Bugzilla (bugzilla.redhat.com) will be under maintenance for infrastructure upgrades and will not be unavailable on July 31st between 12:30 AM - 05:30 AM UTC. We appreciate your understanding and patience. You can follow status.redhat.com for details.
Bug 79464 - g++ with -O assigns overlapping temporaries to the same address
Summary: g++ with -O assigns overlapping temporaries to the same address
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: gcc
Version: 7.1
Hardware: i686
OS: Linux
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Brian Brock
Depends On:
TreeView+ depends on / blocked
Reported: 2002-12-11 22:25 UTC by Alan Stern
Modified: 2007-04-18 16:48 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Last Closed: 2002-12-16 02:28:10 UTC

Attachments (Terms of Use)
C++ source file to demonstrate the compiler bug in action (350 bytes, patch)
2002-12-11 22:27 UTC, Alan Stern
no flags Details | Diff

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:

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

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