Using -Wall and -Woverloaded-virtual together changes the behaviour of the code

Vadim Zeitlin vz-gcc@zeitlins.org
Fri Mar 23 18:16:00 GMT 2018


On Fri, 23 Mar 2018 17:58:37 +0000 Jonathan Wakely <jwakely.gcc@gmail.com> wrote:

JW> On 23 March 2018 at 17:47, Vadim Zeitlin wrote:
JW> >  Hello,
JW> >
JW> >  I'm running into a rather crazy problem that I can't minimize enough to
JW> > create a bug report for, so I'd like to ask here if anybody might have any
JW> > ideas about it by chance. The problem is that the behaviour of some piece
JW> > of C++ code changes, when compiling using MinGW g++ 7.2 (20180123 version
JW> > from Debian Buster) and "-O2", depending on whether both of -Wall and
JW> > -Woverloaded-virtual command line options are specified or not. I.e. the
JW> > code behaves in the same way (and the generated assembly is identical) when
JW> > compiling with just "-O2", or with "-O2 -Wall", or with "-O2
JW> > -Woverloaded-virtual", but when all of "-O2 -Wall -Woverloaded-virtual" are
JW> > used, the code behaviour changes (it's a unit test and it starts failing)
JW> > and the assembly for the functions in which the test fails looks very
JW> > different.
JW> >
JW> >  Unfortunately I can't reduce the program to anything reasonably small as
JW> > just about any changes to the source file, including to the clearly
JW> > unrelated stuff, make the bug disappear. I've tried using delta tool
JW> > recommended by gcc wiki, but it didn't produce anything useful after
JW> > running for many hours (it reduced the test case from 85801 initial lines
JW> > of preprocessed code to ~67000, which is not really very useful...).
JW> >
JW> >  Does anyone know what else could I try doing? Or maybe someone already
JW> > knows how does the combination of these 2 warning switches affect the code
JW> > generation (which is something I'd naïvely expect to be impossible)?
JW> 
JW> Have you already tried -fsanitize=undefined and the other suggestions
JW> at https://gcc.gnu.org/bugs/ ?

 Hello and thank you for your reply!

 Unfortunately the problem only occurs when using i686-w64-mingw32
cross-compiler and it doesn't support UBSAN AFAIK. The project itself is
cross-platform and I do check the test suite using both UBSAN and ASAN
under Linux and there are almost no conditional compilation preprocessor
directives in the code in question, so I'm reasonably sure that it doesn't
invoke undefined behaviour but, of course, I could be wrong.

 As for the other suggestions, I forgot to check whether compiling with
"-fno-strict-aliasing -fwrapv -fno-aggressive-loop-optimizations" changes
anything, thanks for the reminder. After having done so now, it doesn't
seem to make any difference however, i.e. if I add these flags to the
command line containing "-Wall -Woverloaded-virtual", the test still fails.
And if I keep these flags, but remove one or both of the warning options,
the test passes.

 Just to be clear, this is what bothers me the most: how can these warnings
options affect the optimizer output? Shouldn't this be "impossible"?

 Thanks again,
VZ
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20180323/f482f1ce/attachment.sig>


More information about the Gcc-help mailing list