2010-12-05 08:08:52 +08:00
|
|
|
// RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
|
2009-07-28 01:10:54 +08:00
|
|
|
|
2010-05-05 13:47:36 +08:00
|
|
|
// An extra byte should be allocated for an empty class.
|
2010-12-05 08:08:52 +08:00
|
|
|
namespace Test1 {
|
|
|
|
// CHECK: %"struct.Test1::A" = type { i8 }
|
|
|
|
struct A { } *a;
|
|
|
|
}
|
2009-12-08 09:24:23 +08:00
|
|
|
|
2010-12-05 08:08:52 +08:00
|
|
|
namespace Test2 {
|
|
|
|
// No need to add tail padding here.
|
|
|
|
// CHECK: %"struct.Test2::A" = type { i8*, i32 }
|
|
|
|
struct A { void *a; int b; } *a;
|
|
|
|
}
|
2009-12-17 01:27:20 +08:00
|
|
|
|
2010-12-05 08:08:52 +08:00
|
|
|
namespace Test3 {
|
|
|
|
// C should have a vtable pointer.
|
2014-09-28 14:39:30 +08:00
|
|
|
// CHECK: %"struct.Test3::A" = type <{ i32 (...)**, i32, [4 x i8] }>
|
2010-12-05 08:08:52 +08:00
|
|
|
struct A { virtual void f(); int a; } *a;
|
|
|
|
}
|
2011-04-18 05:56:13 +08:00
|
|
|
|
|
|
|
namespace Test4 {
|
|
|
|
// Test from PR5589.
|
|
|
|
// CHECK: %"struct.Test4::B" = type { %"struct.Test4::A", i16, double }
|
2011-07-10 01:41:47 +08:00
|
|
|
// CHECK: %"struct.Test4::A" = type { i32, i8, float }
|
2011-04-18 05:56:13 +08:00
|
|
|
struct A {
|
|
|
|
int a;
|
|
|
|
char c;
|
|
|
|
float b;
|
|
|
|
};
|
|
|
|
struct B : public A {
|
|
|
|
short d;
|
|
|
|
double e;
|
|
|
|
} *b;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace Test5 {
|
|
|
|
struct A {
|
|
|
|
virtual void f();
|
|
|
|
char a;
|
|
|
|
};
|
|
|
|
|
Complete Rewrite of CGRecordLayoutBuilder
CGRecordLayoutBuilder was aging, complex, multi-pass, and shows signs of
existing before ASTRecordLayoutBuilder. It redundantly performed many
layout operations that are now performed by ASTRecordLayoutBuilder and
asserted that the results were the same. With the addition of support
for the MS-ABI, such as placement of vbptrs, vtordisps, different
bitfield layout and a variety of other features, CGRecordLayoutBuilder
was growing unwieldy in its redundancy.
This patch re-architects CGRecordLayoutBuilder to not perform any
redundant layout but rather, as directly as possible, lower an
ASTRecordLayout to an llvm::type. The new architecture is significantly
smaller and simpler than the CGRecordLayoutBuilder and contains fewer
ABI-specific code paths. It's also one pass.
The architecture of the new system is described in the comments. For the
most part, the new system simply takes all of the fields and bases from
an ASTRecordLayout, sorts them, inserts padding and dumps a record.
Bitfields, unions and primary virtual bases make this process a bit more
complicated. See the inline comments.
In addition, this patch updates a few lit tests due to the fact that the
new system computes more accurate llvm types than CGRecordLayoutBuilder.
Each change is commented individually in the review.
Differential Revision: http://llvm-reviews.chandlerc.com/D2795
llvm-svn: 201907
2014-02-22 07:49:50 +08:00
|
|
|
// CHECK: %"struct.Test5::B" = type { %"struct.Test5::A.base", i8, i8, [5 x i8] }
|
2011-04-18 05:56:13 +08:00
|
|
|
struct B : A {
|
|
|
|
char b : 1;
|
|
|
|
char c;
|
|
|
|
} *b;
|
|
|
|
}
|
2011-10-07 10:39:22 +08:00
|
|
|
|
|
|
|
// PR10912: don't crash
|
|
|
|
namespace Test6 {
|
|
|
|
template <typename T> class A {
|
|
|
|
// If T is complete, IR-gen will want to translate it recursively
|
|
|
|
// when translating T*.
|
|
|
|
T *foo;
|
|
|
|
};
|
|
|
|
|
|
|
|
class B;
|
|
|
|
|
|
|
|
// This causes IR-gen to have an incomplete translation of A<B>
|
|
|
|
// sitting around.
|
|
|
|
A<B> *a;
|
|
|
|
|
|
|
|
class C {};
|
|
|
|
class B : public C {
|
|
|
|
// This forces Sema to instantiate A<B>, which triggers a callback
|
|
|
|
// to IR-gen. Because of the previous, incomplete translation,
|
|
|
|
// IR-gen actually cares, and it immediately tries to complete
|
|
|
|
// A<B>'s IR type. That, in turn, causes the translation of B*.
|
|
|
|
// B isn't complete yet, but it has a definition, and if we try to
|
|
|
|
// compute a record layout for that definition then we'll really
|
|
|
|
// regret it later.
|
|
|
|
A<B> a;
|
|
|
|
};
|
|
|
|
|
|
|
|
// The derived class E and empty base class C are required to
|
|
|
|
// provoke the original assertion.
|
|
|
|
class E : public B {};
|
|
|
|
E *e;
|
|
|
|
}
|
2012-04-27 10:34:46 +08:00
|
|
|
|
|
|
|
// <rdar://problem/11324125>: Make sure this doesn't crash. (It's okay
|
|
|
|
// if we start rejecting it at some point.)
|
|
|
|
namespace Test7 {
|
|
|
|
#pragma pack (1)
|
|
|
|
class A {};
|
|
|
|
// CHECK: %"class.Test7::B" = type <{ i32 (...)**, %"class.Test7::A" }>
|
|
|
|
class B {
|
|
|
|
virtual ~B();
|
|
|
|
A a;
|
|
|
|
};
|
|
|
|
B* b;
|
|
|
|
#pragma pack ()
|
|
|
|
}
|
2014-04-26 05:56:30 +08:00
|
|
|
|
|
|
|
// Shouldn't crash.
|
|
|
|
namespace Test8 {
|
2014-06-07 04:31:48 +08:00
|
|
|
struct A {};
|
|
|
|
struct D { int a; };
|
|
|
|
struct B : virtual D, A { };
|
|
|
|
struct C : B, A { void f() {} };
|
|
|
|
C c;
|
2014-04-26 05:56:30 +08:00
|
|
|
}
|