User account creation filtered due to spam.

Bug 47011 - ICE when using attribute optimize
Summary: ICE when using attribute optimize
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.4.5
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Keywords: ice-on-valid-code
Depends on:
Reported: 2010-12-19 10:16 UTC by Lorenzo Castelli
Modified: 2012-02-01 03:18 UTC (History)
0 users

See Also:
Target: x86_64-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:

Code to reproduce the error (113 bytes, text/x-c++src)
2010-12-19 10:18 UTC, Lorenzo Castelli
bug showing ICE with -O, incorrect code without optimization (649 bytes, text/plain)
2011-09-20 12:31 UTC, Mat Hostetter

Note You need to log in before you can comment on or make changes to this bug.
Description Lorenzo Castelli 2010-12-19 10:16:59 UTC
When compiling the attached file with:
 g++ -O3 -c gcc-crash.cpp

the following error is emitted:
 gcc-crash.cpp: In member function ‘virtual A B::m()’:
 gcc-crash.cpp:7: internal compiler error: in tree_nrv, at tree-nrv.c:143

This happens with gcc 4.4.5 and the current branch on SVN. It doesn't seem to happen on gcc 4.5.
Comment 1 Lorenzo Castelli 2010-12-19 10:18:34 UTC
Created attachment 22819 [details]
Code to reproduce the error
Comment 2 Mat Hostetter 2011-09-20 12:31:56 UTC
Created attachment 25327 [details]
bug showing ICE with -O, incorrect code without optimization
Comment 3 Mat Hostetter 2011-09-20 12:32:47 UTC
I am seeing the same crash with gcc 4.4.[3456], on x86_64. It works on 4.6.1.

I encountered this crash when simply upgrading to the latest boost (1.47.0), which uses attribute optimize, so this is likely to affect other people.

But the bug is more surprising and subtle than just the crash. It can silently generate incorrect code, which took me longer to track down.

If you compile my attached code optimized you get the internal compiler error. If you compile it unoptimized, g++ silently changes the calling convention for vector::begin from by-value to by-reference -- but only if a completely unrelated empty function is marked with attribute optimize! 

In the full example this meant g++ miscompiled std::vector::begin to use the wrong calling convention, which when linked into other objects expecting the proper calling convention would cause a crash.