This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
c++/9704: miscompiles openoffice (deals with bitfield members)
- From: matz at suse dot de
- To: gcc-gnats at gcc dot gnu dot org
- Cc: mark at codesourcery dot com
- Date: 14 Feb 2003 12:59:49 -0000
- Subject: c++/9704: miscompiles openoffice (deals with bitfield members)
- Reply-to: matz at suse dot de
>Number: 9704
>Category: c++
>Synopsis: miscompiles openoffice (deals with bitfield members)
>Confidential: no
>Severity: critical
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Fri Feb 14 13:06:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator: matz@suse.de
>Release: 3.3 20030123 CVS and HEAD
>Organization:
>Environment:
i686-linux
>Description:
The below testcase is miscompiled, and this affects openoffice.
This is the case since september last year (i.e. in 3.3 and HEAD).
---------------- snip -----------------
struct BOOL {
int nVal:1, bSet:1;
BOOL (int i) : nVal(i!=0), bSet(1) {}
};
struct Fill {
void *d;
Fill() : d(0) {}
Fill( const Fill& ) {}
};
struct SvMetaSlot {
Fill aGroupId;
#ifdef OUTLINE_CCTOR
BOOL a1; BOOL a2; BOOL a3; BOOL a4; BOOL a5; BOOL a6; BOOL a7;
#endif
BOOL a8;
SvMetaSlot() :
#ifdef OUTLINE_CCTOR
a1(0), a2(0), a3(0), a4(0), a5(0), a6(0), a7(0),
#endif
a8(1) {}
SvMetaSlot* MakeClone() const;
};
SvMetaSlot* SvMetaSlot::MakeClone() const { return new SvMetaSlot( *this ); }
extern "C" void abort(void);
int main()
{
SvMetaSlot s; SvMetaSlot s2(s);
if (s.a8.bSet != s2.a8.bSet)
abort ();
return 0;
}
-------------- snap -------------
Compile it with -O1 (or -O2), and see it abort. When
-DOUTLINE_CCTOR is given, the implicit cctor of SvMetaSlot
is created in an out-of-line copy, so it can be analyzed easier.
If it's not given, the cctor in inlined into the MakeClone()
method, but the outcome is the same. Note how the BOOL class
uses just bitfield members.
What happens is, that all the BOOL members of SvMetaSlot are
not copied in the synthetic copy ctor. There is no RTL
generated for copying those members, for instance the
assembler output for the out-of-line copy on i686 is:
SvMetaSlot::SvMetaSlot[in-charge](SvMetaSlot const&):
pushl %ebp
movl %esp, %ebp
popl %ebp
ret
The miscompile happens with cvs -D"2002-09-30 19:00", but not
with -D"2002-09-30 18:21", and the only patch during that period
is Marks:
+2002-09-30 Mark Mitchell <mark@codesourcery.com>
+
+ * class.c (walk_subobject_offsets): Correct the calculation of
+ offsets for virtual bases. Correct the counting of array
+ elements.
+ (layout_nonempty_base_or_field): Simplify. Correct the
+ calculation of offsets to be propagated through the binfo
+ hierarchy.
+ (build_base_field): Avoid creating a FIELD_DECL for empty bases.
+ ....
>How-To-Repeat:
Compile the above testcase with g++ (no matter what -O option),
on i686-linux (x86-64 breaks too), run it. It will abort.
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: