This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/16568] New: 3.5: wrong code for conditional in initializer
- From: "gcc-bugzilla at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 15 Jul 2004 16:12:01 -0000
- Subject: [Bug c++/16568] New: 3.5: wrong code for conditional in initializer
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
In the example below, the C constructor is miscompiled.
I compile like this:
$ g++ -S x.cc
Here is the generated code for the constructor (eliding labels used for EH):
_ZN1CC2EP4ystr:
pushl %ebp
movl %esp, %ebp
subl $24, %esp
cmpl $0, 12(%ebp)
jne .L2
movl 8(%ebp), %eax
movl %eax, -4(%ebp)
movl $0, 4(%esp)
movl -4(%ebp), %eax
movl %eax, (%esp)
call _ZN4ystrC1Ei ; ystr::ystr[in-charge](int)
jmp .L1
.L2:
movl 12(%ebp), %eax
movl %eax, 4(%esp)
movl -4(%ebp), %eax ; !!! read of uninitialized memory
movl %eax, (%esp)
call _ZN4ystrC1ERKS_ ; ystr::ystr[in-charge](ystr const&)
.L1:
leave
ret
In the case that the jne to .L2 is taken, we reference the value
at -4(%ebp). However, this location is only initialized in the
other branch of the conditional. Thus, we end up passing an invalid
pointer as the this argument of the constructor.
This problem is seen already in the -original tree dump:
;; Function C::C(ystr*) (_ZN1CC2EP4ystr)
;; enabled by -tree-original
{
struct ystr * this.0;
if (value == 0B)
{
this.0 = (struct ystr *)this;
__comp_ctor (this.0, 0);
}
else
{
__comp_ctor (this.0, value);
}
}
Environment:
System: Linux karma 2.6.7 #18 Wed Jul 14 03:27:01 EDT 2004 i686 i686 i386 GNU/Linux
Architecture: i686
<machine, os, target, libraries (multiple lines)>
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: /home/sss/gcc/gcc/configure --prefix=/usr/local/gcc --enable-threads=posix --enable-long-long --enable-languages=c,c++,f95
How-To-Repeat:
-------------------------------------
struct ystr {
ystr (int);
ystr (const ystr&);
};
struct C
{
C(ystr* value);
ystr _object;
};
C::C(ystr* value)
: _object(value == 0 ? 0 : *value)
{
}
-------------------------------------
------- Additional Comments From snyder at fnal dot gov 2004-07-15 16:11 -------
Fix:
<how to correct or work around the problem, if known (multiple lines)>
--
Summary: 3.5: wrong code for conditional in initializer
Product: gcc
Version: 3.5.0
Status: UNCONFIRMED
Severity: critical
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: snyder at fnal dot gov
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16568