https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98692
Bug ID: 98692 Summary: Unitialized Values reported only with -Os Product: gcc Version: 10.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: nick.child at ibm dot com Target Milestone: --- Host: powerpcle-*-linux-gnu* Target: powerpcle-*-linux-gnu* Build: powerpcle-*-linux-gnu* Created attachment 49970 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49970&action=edit Preprocesssed File Hello all, This is my first go at something like this so I apologize for any cringes now. Recently, I implemented memory checks into our CI using valgrind. Everything works fine on x86 with the same commands but gives issues when running on POWER. Specifically, only when using the `-Os` size optimizer flag. Things like `O2` and `O3` don't bring about any errors. While the code runs fine, these valgrind errors are a bit alarming. I have run into the issue using the following compiler versions and OS's: gcc version 9.3.1 20200408 (Red Hat 9.3.1-2) gcc version 10.2.1 20200723 (Red Hat 10.2.1-1) gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04) The errors revolve around an conditional jump on unitialized variables. I am thinking it is a stack allocation issue. I have tried to narrow down my issue to as simple a program as possible (attached). I then build using: $ gcc -Os issue.c -o issue Compilation works and binary executes normally but valgrind complains with: $ valgrind ./issue This could very well be a valgrind mistake, with too many things being optimized off of the executable for valgrind to accurately keep track of memory. Here is the output from valgrind: ==3557285== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info ==3557285== Command: leak ==3557285== ==3557285== Conditional jump or move depends on uninitialised value(s) ==3557285== at 0x416E9B8: __vfprintf_internal (vfprintf-internal.c:1332) ==3557285== by 0x415E33B: printf@@GLIBC_2.17 (printf.c:33) ==3557285== by 0x100005D3: main (in /home/jenkins/testPlace/test2/leak) ==3557285== ==3557285== Use of uninitialised value of size 8 ==3557285== at 0x40A14DC: strchrnul (vg_replace_strmem.c:1394) ==3557285== by 0x416E9D3: __find_specmb (printf-parse.h:111) ==3557285== by 0x416E9D3: __vfprintf_internal (vfprintf-internal.c:1365) ==3557285== by 0x415E33B: printf@@GLIBC_2.17 (printf.c:33) ==3557285== by 0x100005D3: main (in /home/jenkins/testPlace/test2/leak) ==3557285== ==3557285== Use of uninitialised value of size 8 ==3557285== at 0x40A14F0: strchrnul (vg_replace_strmem.c:1394) ==3557285== by 0x416E9D3: __find_specmb (printf-parse.h:111) ==3557285== by 0x416E9D3: __vfprintf_internal (vfprintf-internal.c:1365) ==3557285== by 0x415E33B: printf@@GLIBC_2.17 (printf.c:33) ==3557285== by 0x100005D3: main (in /home/jenkins/testPlace/test2/leak) ==3557285== ==3557285== Conditional jump or move depends on uninitialised value(s) ==3557285== at 0x418BABC: _IO_file_xsputn@@GLIBC_2.17 (fileops.c:1204) ==3557285== by 0x416EA33: __vfprintf_internal (vfprintf-internal.c:1373) ==3557285== by 0x415E33B: printf@@GLIBC_2.17 (printf.c:33) ==3557285== by 0x100005D3: main (in /home/jenkins/testPlace/test2/leak) ==3557285== ==3557285== Conditional jump or move depends on uninitialised value(s) ==3557285== at 0x418BC94: _IO_new_file_xsputn (fileops.c:1253) ==3557285== by 0x418BC94: _IO_file_xsputn@@GLIBC_2.17 (fileops.c:1197) ==3557285== by 0x416EA33: __vfprintf_internal (vfprintf-internal.c:1373) ==3557285== by 0x415E33B: printf@@GLIBC_2.17 (printf.c:33) ==3557285== by 0x100005D3: main (in /home/jenkins/testPlace/test2/leak) ==3557285== ... ... ... ==3558101== ==3558101== HEAP SUMMARY: ==3558101== in use at exit: 0 bytes in 0 blocks ==3558101== total heap usage: 1 allocs, 1 frees, 1,024 bytes allocated ==3558101== ==3558101== All heap blocks were freed -- no leaks are possible ==3558101== ==3558101== Use --track-origins=yes to see where uninitialised values come from ==3558101== For lists of detected and suppressed errors, rerun with: -s ==3558101== ERROR SUMMARY: 44 errors from 31 contexts (suppressed: 0 from 0)