https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92364
Bug ID: 92364 Summary: strict-overflow warning only when using "--coverage" flag and -O2 or above, and inlining Product: gcc Version: 6.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: gmc at synopsys dot com Target Milestone: --- Created attachment 47170 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47170&action=edit Source file to be compiled with g++ to demonstrate the bug This is an issue which is hard to characterize, as it seems that a whole lots of different things have to line up for it to occur. When compiling the sample code with g++, a warning will be issued for 'strict-overflow' ONLY when building with -O2, ONLY when building with --coverage, and only when using inlining. Furthermore, if I make any unrelated changes to the code, the issue goes away. This issue exists in GCC 6.2, 7.3, and 7.4, but GCC 8.1 and newer (I tested 8.2, 8.3, 9.1, 9.2) do NOT have the issue The g++ compiler is configured as follows (GCC 6.2 shown, 7.3 etc. configured with the same options): Target: x86_64-redhat-linux Configured with: ../src/gcc-6.2.0/configure --prefix=/depot/gcc-6.2.0 --enable-bootstrap --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-languages=c,c++,fortran --disable-libgcj --with-cpu=generic --build=x86_64-redhat-linux Thread model: posix gcc version 6.2.0 (GCC) Compile the testcase as: g++ -c foo.cc -o /tmp/foo.o -O3 -Wall -Werror -Wno-uninitialized --coverage With this reduced testcase, I can flip the compilation / pass / fail status with a whole range of unlikely changes – e.g. - If I compile without the "-Wno-uninitialized" flag, then I get THREE warnings: + 1 warning about strict overflow + 2 warnings about uninitialized vars thingy.GridMap::Num_Y and hingy.GridMap::Num_X then if I initialize those vars in the constructor via GridMap() { Num_X=0; Num_Y=0; } then not only do the uninit warnings go away, but so does the strict overflow one - Similarly, commenting out unrelated code, makes the warning disappear: if (my_y > Num_Y) { my_y = Num_Y; /* trim = true; */ } even though the value of trim has no effect on the following line where the strict-overflow warning is triggered - Disabling inlining also makes the issue go away (-fno-inline or set attribute on funcs)