Thanks. Obviously, I should have tried that before posting my question, although I would not have known how to obtain the answer without seeing your answer below.
Not being familiar with the x86 asm language, I modified the foo.cpp program (explicitly assign y=0) and then g++ again, so I could compare the two asm lang outputs. After that, it was fairly clear that the compiler is not initializing y. Ben -----Original Message----- From: John Reiser <jrei...@bitwagon.com> Sent: Monday, March 2, 2020 7:20 PM To: valgrind-users@lists.sourceforge.net Subject: Re: [Valgrind-users] detecting uninitialized values in debug builds On 3/2/20 22:02 UTC, Ben White wrote: > I've also been told that the g++ compiler will initialize all stack > objects to zero when compiling for debug (the -g option). Obviously you didn't try it. g++ 9.2.1 does not do that. $ cat foo.cpp int g(int x, int y); int f(int x) { int y; return g(x, y); // uninit use of y } $ g++ -g -S foo.cpp $ cat foo.s .file "foo.cpp" .text .Ltext0: .globl _Z1fi .type _Z1fi, @function _Z1fi: .LFB0: .file 1 "foo.cpp" .loc 1 4 1 .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rsp, %rbp .cfi_def_cfa_register 6 subq $32, %rsp movl %edi, -20(%rbp) .loc 1 6 17 movl -4(%rbp), %edx // -4(%rbp) is never initialized movl -20(%rbp), %eax movl %edx, %esi // 2nd parameter to g movl %eax, %edi call _Z1gii .loc 1 7 1 leave .cfi_def_cfa 7, 8 ret .cfi_endproc .LFE0: .size _Z1fi, .-_Z1fi [[snip]] .section .debug_str,"MS",@progbits,1 .LASF1: .string "foo.cpp" .LASF0: .string "GNU C++14 9.2.1 20190827 (Red Hat 9.2.1-1) -mtune=generic -march=x86-64 -g" .LASF3: .string "_Z1fi" .LASF2: .string "/home/user" .ident "GCC: (GNU) 9.2.1 20190827 (Red Hat 9.2.1-1)" .section .note.GNU-stack,"",@progbits $ _______________________________________________ Valgrind-users mailing list Valgrind-users@lists.sourceforge.net https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.sourceforge.net%2Flists%2Flistinfo%2Fvalgrind-users&data=02%7C01%7Cben.white%40cohu.com%7C4af3d19203134610feef08d7bf220529%7Ceacc2a35149847488d1f03fb953672f8%7C0%7C0%7C637188025165390441&sdata=CkROtsN2ADGpGORSPKlYSEqmibqd3VLSA0LfO8U2giU%3D&reserved=0 _______________________________________________ Valgrind-users mailing list Valgrind-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/valgrind-users