Bugzilla – Bug 104
[c++] C++ Frontend lays out superclasses like anonymous bitfields!
Last modified: 2003-11-09 10:57:00
You need to log in before you can comment on or make changes to this bug.
In this test (test/Regression/C++Frontend/2003-11-09-ConstructorTypeSafety.cpp.tr): --- struct contained { unsigned X; contained(); }; struct base { unsigned A, B; }; struct derived : public base { contained _M_value_field; }; int test() { derived X; } --- There are lots of type safety problems. For example, the types are compiled to: %struct.base = type { uint, uint } %struct.contained = type { uint } %struct.derived = type { ubyte, ubyte, ubyte, ubyte, ubyte, ubyte, ubyte, ubyte, %struct.contained } instead of: %struct.derived = type { %struct.base, %struct.contained } Ugh. Of course, this is nuking all of my attempts at working on data-structure based programs. :( -Chris
Whoa, this is scary. The C++ front-end would always lay out base classes as anonymous bitfield references, causing no end of trouble. I would not be suprised if this fixes some of the problems we are having with C++ codes: this could cause miscompilations. $ diff -u llvm-types.c~ llvm-types.c --- llvm-types.c~ 2003-11-04 13:25:46.000000000 -0600 +++ llvm-types.c 2003-11-09 10:37:09.000000000 -0600 @@ -633,7 +633,8 @@ ElementAlignments[*Idx] = ByteAlignment; *Size = StartOffset/8 + llvm_type_get_size(Ty); ++*Idx; - } else if (DECL_NAME(field) == 0) { /* Is this an anonymous bitfield? */ + } else if (DECL_NAME(field) == 0 && /* Is this an anonymous bitfield? */ + DECL_BIT_FIELD(field)) { unsigned NumPads; /* Is it attempting to align the current offset to some value? */ if (GetDeclSize(field) == 0) { --- With this patch, we now get: %struct.derived = type { %struct.base, %struct.contained } As expected. -Chris