Bugzilla will be upgraded to version 5.0 on a still to be determined date in the near future. The original upgrade date has been delayed.
Bug 79464 - g++ with -O assigns overlapping temporaries to the same address
g++ with -O assigns overlapping temporaries to the same address
Product: Red Hat Linux
Classification: Retired
Component: gcc (Show other bugs)
i686 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Brian Brock
Depends On:
  Show dependency treegraph
Reported: 2002-12-11 17:25 EST by Alan Stern
Modified: 2007-04-18 12:48 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2002-12-15 21:28:10 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

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

  None (edit)
Description Alan Stern 2002-12-11 17:25:52 EST
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 17:27:41 EST
Created attachment 88486 [details]
C++ source file to demonstrate the compiler bug in action
Comment 2 Alan Cox 2002-12-15 21:28:10 EST
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.