[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#894302: g++-7: Compiler generates wrong code with warning options



Package: g++-7
Version: 7.3.0-12
Severity: important

This is an apparently impossible bug which nevertheless can be reliably
observed when using Debian versions of g++-7 and also i686-w64-mingw32-g++.
It consists in compiler generating different, and broken, code when
compiling the same input with only warning options -- which are, of course,
not supposed to affect the code generation at all -- added.

The upstream bug at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85091
contains several test cases. Using the one from
https://gcc.gnu.org/bugzilla/attachment.cgi?id=43774 it can be seen that
running

        g++-7 -S -std=c++17 -O2 gcc-7.3-x86_64-linux.cpp -o nowarn.s

and

        g++-7 -S -std=c++17 -O2 gcc-7.3-x86_64-linux.cpp -Wnonnull -Woverloaded-virtual -o warn.s

commands produces different assembly. Subsequently, Martin Liška has
created a further reduced test case which allows to reproduce the problem
using just "-O1 -Woverloaded-virtual", please see
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85091#c31

The bug is really mysterious but quite worrisome, as it results in broken
code being silently generated in practice and, worse, the generated code
oscillates between correct and broken versions when any, even apparently
completely unrelated, changes are made. Another interesting detail is that
using -fchecking=2 makes the bug disappear (but -fchecking does not).

Finally, please note that the bug doesn't seem to happen with the upstream
versions nor with g++ 7.2 from Fedora, so it's highly likely that it's due
to one of the Debian-specific patches, even if I really can't see anything
that could explain it in any of them.

Thanks in advance for any help with this!

-- System Information:
Debian Release: buster/sid
  APT prefers unstable
  APT policy: (990, 'unstable'), (500, 'unstable-debug'), (100, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 4.6.0-0.bpo.1-amd64 (SMP w/8 CPU cores)
Locale: LANG=C.UTF-8, LC_CTYPE=C.UTF-8 (charmap=UTF-8) (ignored: LC_ALL set to C.UTF-8), LANGUAGE=C.UTF-8 (charmap=UTF-8) (ignored: LC_ALL set to C.UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: unable to detect

Versions of packages g++-7 depends on:
ii  gcc-7            7.3.0-12
ii  gcc-7-base       7.3.0-12
ii  libc6            2.27-2
ii  libgmp10         2:6.1.2+dfsg-3
ii  libisl19         0.19-1
ii  libmpc3          1.1.0-1
ii  libmpfr6         4.0.1-1
ii  libstdc++-7-dev  7.3.0-12
ii  zlib1g           1:1.2.8.dfsg-5

g++-7 recommends no packages.

Versions of packages g++-7 suggests:
pn  g++-7-multilib    <none>
pn  gcc-7-doc         <none>
pn  libstdc++6-7-dbg  <none>

-- no debconf information

Attachment: pgpw1_NTc1rCk.pgp
Description: PGP signature


Reply to: