On Wed, 2023-08-30 at 14:49 +0200, Mathieu Malaterre wrote: > On Wed, Aug 30, 2023 at 2:32 PM Xi Ruoyao <xry111@xxxxxxxxxxx> wrote: > > > > On Wed, 2023-08-30 at 14:25 +0200, Mathieu Malaterre via Gcc-help wrote: > > > Hi all, > > > > > > Consider the following silly c++ code (*), it compiles nicely using > > > g++ 13.2 no warnings using either: > > > > > > % g++ -c -O2 -Wall -Wextra alt.cxx > > > > > > or > > > > > > % g++ -c -O0 -Wall -Wextra alt.cxx > > > > > > Is it possible to trigger a warning for this code (maybe I missed some > > > gcc options) ? > > > > Analyzer does a better job for such a "complex" pattern: > > > > $ gcc -Wall -Wextra t.cc -fanalyzer -S > > Cool ! Documentation is somewhat unclear to me as `-fanalyzer` seems > to be required (I cannot simply use > -Wanalyzer-use-of-uninitialized-value) (*) > > Could someone confirm that my code cannot trigger one of the > `fsanitize=undefined` logic ? valgrind sees the uninitialised read: -fsanitize=undefined cannot detect any uninitialised use. OTOH - fsanitize=memory is capable: $ clang++ t.cc -fsanitize=memory $ ./a.out ==969846==WARNING: MemorySanitizer: use-of-uninitialized-value #0 0x5603db7b65f7 in cl(d) (/home/xry111/a.out+0xb55f7) #1 0x5603db7b6709 in k() (/home/xry111/a.out+0xb5709) #2 0x5603db7b67d8 in main (/home/xry111/a.out+0xb57d8) #3 0x7ff2d9c27f59 in __libc_start_call_main /home/xry111/sources/lfs/glibc-2.38/csu/../sysdeps/nptl/libc_start_call_main.h:58:16 #4 0x7ff2d9c28024 in __libc_start_main@GLIBC_2.2.5 /home/xry111/sources/lfs/glibc-2.38/csu/../csu/libc-start.c:360:3 #5 0x5603db71f2d0 in _start /home/xry111/sources/lfs/glibc-2.38/csu/../sysdeps/x86_64/start.S:115 SUMMARY: MemorySanitizer: use-of-uninitialized-value (/home/xry111/a.out+0xb55f7) in cl(d) Exiting But unfortunately the memory sanitizer is only supported by Clang, not GCC :(. -- Xi Ruoyao <xry111@xxxxxxxxxxx> School of Aerospace Science and Technology, Xidian University