Bug 79464

Summary: g++ with -O assigns overlapping temporaries to the same address
Product: [Retired] Red Hat Linux Reporter: Alan Stern <stern>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED CURRENTRELEASE QA Contact: Brian Brock <bbrock>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.1   
Target Milestone: ---   
Target Release: ---   
Hardware: i686   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2002-12-16 02:28:10 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
C++ source file to demonstrate the compiler bug in action none

Description Alan Stern 2002-12-11 22:25:52 UTC
From Bugzilla Helper:
User-Agent: Mozilla/4.77 [en] (X11; U; Linux 2.2.22-6.2.3a i686)

Description of problem:
The C++ compiler from package gcc-c++-2.96-112.7.1 incorrectly assigns addresses
for temporaries when compiling with -O and using inline functions.  The attached
program (a.cc) prints the address of each object as it is constructed and as it
is destroyed.  You can see that two of the temporaries are assigned to the same
location in memory and both are simultaneously alive (that is, both are
constructed, then both are destroyed).

This bug does not occur if the program is compiled without -O or if the function
"func" is not declared as inline.

Version-Release number of selected component (if applicable):


How reproducible:
Always

Steps to Reproduce:
1. Compile the attached program: g++ -O a.cc
2. Run the executable: ./a.out
3. Check the output, and see that two constructors are called for the same
address, then two destructors are called for that address.
	

Actual Results:  [stern@ida x]$ g++ -O a.cc
[stern@ida x]$ ./a.out
Cons-1 at 0xbffffaf0
Cons-1 at 0xbffffae0
Cons-2 at 0xbffffb00
Cons-1 at 0xbffffaf0
Cons-2 at 0xbffffb10
Dest at 0xbffffb00
Dest at 0xbffffaf0
Dest at 0xbffffaf0
Dest at 0xbffffae0
Dest at 0xbffffb10


Expected Results:  The second line of output saying "Cons-1 at 0xbffffaf0"
should refer to a different address, and similarly the second line saying "Dest
at 0xbffffaf0" should refer to that different address.

Alternatively, the address could be reused if the first destructor was called
before the second constructor.

Additional info:

Comment 1 Alan Stern 2002-12-11 22:27:41 UTC
Created attachment 88486 [details]
C++ source file to demonstrate the compiler bug in action

Comment 2 Alan Cox 2002-12-16 02:28:10 UTC
g++ 3.2 in 8.0 gets this right