Skip to content

Instantly share code, notes, and snippets.

@jyasskin
Created October 22, 2013 07:40
Show Gist options
  • Save jyasskin/7096618 to your computer and use it in GitHub Desktop.
Save jyasskin/7096618 to your computer and use it in GitHub Desktop.
$ clang++ -O1 -g test.cc -fno-omit-frame-pointer -o test && ~/src/chromium/src/third_party/valgrind/linux_x64/bin/valgrind ./test
==10069== Memcheck, a memory error detector
==10069== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==10069== Using Valgrind-3.9.0.SVN and LibVEX; rerun with -h for copyright info
==10069== Command: ./test
==10069==
==10069== Conditional jump or move depends on uninitialised value(s)
==10069== at 0x400597: main (test.cc:15)
==10069==
Yep.
==10069==
==10069== HEAP SUMMARY:
==10069== in use at exit: 0 bytes in 0 blocks
==10069== total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==10069==
==10069== All heap blocks were freed -- no leaks are possible
==10069==
==10069== For counts of detected and suppressed errors, rerun with: -v
==10069== Use --track-origins=yes to see where uninitialised values come from
==10069== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 2 from 2)
#include <stdio.h>
__attribute__((noinline)) bool InitializeIf(volatile bool cond, int* var) {
if (!cond)
return false;
*var = 3;
return true;
}
int main() {
int var;
bool initted = InitializeIf(false, &var);
if (!initted || var == 2)
printf("Yep.\n");
}
.file "test.cc"
.text
.globl _Z12InitializeIfbPi
.align 16, 0x90
.type _Z12InitializeIfbPi,@function
_Z12InitializeIfbPi: # @_Z12InitializeIfbPi
.cfi_startproc
# BB#0: # %entry
movb %dil, -1(%rsp)
testb $1, -1(%rsp)
je .LBB0_1
# BB#2: # %if.end
movl $3, (%rsi)
movb $1, %al
# kill: AL<def> AL<kill> EAX<kill>
ret
.LBB0_1:
xorl %eax, %eax
# kill: AL<def> AL<kill> EAX<kill>
ret
.Ltmp0:
.size _Z12InitializeIfbPi, .Ltmp0-_Z12InitializeIfbPi
.cfi_endproc
.globl main
.align 16, 0x90
.type main,@function
main: # @main
.cfi_startproc
# BB#0: # %entry
pushq %rbp
.Ltmp3:
.cfi_def_cfa_offset 16
.Ltmp4:
.cfi_offset %rbp, -16
movq %rsp, %rbp
.Ltmp5:
.cfi_def_cfa_register %rbp
subq $16, %rsp
leaq -4(%rbp), %rsi
xorl %edi, %edi
callq _Z12InitializeIfbPi
cmpl $2, -4(%rbp)
je .LBB1_2
# BB#1: # %entry
xorb $1, %al
je .LBB1_3
.LBB1_2: # %if.then
movl $.Lstr, %edi
callq puts
.LBB1_3: # %if.end
xorl %eax, %eax
addq $16, %rsp
popq %rbp
ret
.Ltmp6:
.size main, .Ltmp6-main
.cfi_endproc
.type .L.str,@object # @.str
.section .rodata.str1.1,"aMS",@progbits,1
.L.str:
.asciz "Yep.\n"
.size .L.str, 6
.type .Lstr,@object # @str
.Lstr:
.asciz "Yep."
.size .Lstr, 5
.section ".note.GNU-stack","",@progbits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment