Bug 985895 - G++ miscompiles callable construct
G++ miscompiles callable construct
Status: CLOSED WONTFIX
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: gcc (Show other bugs)
6.4
x86_64 Linux
unspecified Severity high
: rc
: ---
Assigned To: Jakub Jelinek
qe-baseos-tools
:
Depends On:
Blocks: 994246 1056252
  Show dependency treegraph
 
Reported: 2013-07-18 09:02 EDT by Gregor Jasny
Modified: 2014-05-06 07:01 EDT (History)
7 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2014-05-06 07:01:32 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)
Test case (39.38 KB, application/x-gzip)
2013-07-18 09:02 EDT, Gregor Jasny
no flags Details
Minimized test case (398 bytes, text/plain)
2014-04-24 14:59 EDT, Petr Machata
no flags Details

  None (edit)
Description Gregor Jasny 2013-07-18 09:02:22 EDT
Created attachment 775307 [details]
Test case

Description of problem:
Attached you'll find a testcase (.ii file included) that is miscompiled by GCC with O2 optimization level. Clang 3.3 and GCC 4.8 (on Debian) produces a proper binary.

If I add printf logging to all ctors and dtors of all classes that are involved, the program works too.

The binary is valgrind clean.

Version-Release number of selected component (if applicable):
RHEL 6.4 x86_64
boost-devel-1.41.0-17.el6_4.x86_64
gcc-c++-4.4.7-3.el6.x86_64

How reproducible:
always

Steps to Reproduce:
1. make
2. ./testcase

Actual results:
"pure virtual method called"

(gdb) bt
#0  0x00000035ad2328a5 in raise () from /lib64/libc.so.6
#1  0x00000035ad234085 in abort () from /lib64/libc.so.6
#2  0x0000003f77ebea5d in __gnu_cxx::__verbose_terminate_handler() () from /usr/lib64/libstdc++.so.6
#3  0x0000003f77ebcbe6 in ?? () from /usr/lib64/libstdc++.so.6
#4  0x0000003f77ebcc13 in std::terminate() () from /usr/lib64/libstdc++.so.6
#5  0x0000003f77ebd53f in __cxa_pure_virtual () from /usr/lib64/libstdc++.so.6
#6  0x00000000004009a9 in PeriodicTimer::startInternal(int, PeriodicTimer::ITimerCallback&) ()
#7  0x0000000000400a3c in PeriodicTimerTests::shouldBeAbleToRestartTimer() ()
#8  0x0000000000400aa5 in main ()

Expected results:
Should work without problems.

Thanks,
Gregor
Comment 10 Petr Machata 2014-04-24 14:59:05 EDT
Created attachment 889408 [details]
Minimized test case

# g++ -O2 /meh.cc && ./a.out
pure virtual method called
terminate called without an active exception
Aborted
# g++ --version
g++ (GCC) 4.4.7 20120313 (Red Hat 4.4.7-4)
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

- vs. -

$ g++ /var/lib/mock/epel-6-x86_64/root/meh.cc && ./a.out
$ g++ --version
g++ (GCC) 4.6.3 20120306 (Red Hat 4.6.3-2)
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Comment 11 Petr Machata 2014-04-24 15:01:00 EDT
Oops, forgot about -O2 in the latter run.  It still passes even with that.
Comment 17 Matt Newsome 2014-04-29 10:28:18 EDT
In reviewing this case for Red Hat platform engineering, our conclusion is that this is an issue in the gcc-4.4 shipped in RHEL 6, but fixing it via a backported patch would risk reducing overall toolchain stability.

Fortunately we're proposing two potential workarounds:

 - Red Hat Developer Toolset v2.1 provides gcc-4.8 for RHEL 6 and in our testing does not exhibit this issue
 - Use of -fno-tree-sink during compilation is expected to resolve the issue you are seeing

We recommend using either of these workarounds. Please let us know if these resolve your issue and we'll close out this bug. Thanks.

Note You need to log in before you can comment on or make changes to this bug.