First Last Prev Next    No search results available
Details
: [c++] C++ Frontend lays out superclasses like anonymous b...
Bug#: 104
: tools
: llvm-g++
Status: RESOLVED
Resolution: FIXED
: All
: All
: 1.0
: P2
: critical
: 1.1

:
: miscompilation
:
:
  Show dependency tree - Show dependency graph
People
Reporter: Chris Lattner <sabre@nondot.org>
Assigned To: Chris Lattner <sabre@nondot.org>

Attachments


Note

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

Related actions


Description:   Opened: 2003-11-09 01:07
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
------- Comment #1 From Chris Lattner 2003-11-09 10:57:00 -------
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

First Last Prev Next    No search results available