| 1 |
// RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s |
| 2 |
|
| 3 |
// An extra byte should be allocated for an empty class. |
| 4 |
namespace Test1 { |
| 5 |
// CHECK: %"struct.Test1::A" = type { i8 } |
| 6 |
struct A { } a; |
| 7 |
} |
| 8 |
|
| 9 |
namespace Test2 { |
| 10 |
// No need to add tail padding here. |
| 11 |
// CHECK: %"struct.Test2::A" = type { ptr, i32 } |
| 12 |
struct A { void *a; int b; } a; |
| 13 |
} |
| 14 |
|
| 15 |
namespace Test3 { |
| 16 |
// C should have a vtable pointer. |
| 17 |
// CHECK: %"struct.Test3::A" = type <{ ptr, i32, [4 x i8] }> |
| 18 |
struct A { virtual void f(); int a; } a; |
| 19 |
} |
| 20 |
|
| 21 |
namespace Test4 { |
| 22 |
// Test from PR5589. |
| 23 |
// CHECK: %"struct.Test4::B" = type { %"struct.Test4::A", i16, double } |
| 24 |
// CHECK: %"struct.Test4::A" = type { i32, i8, float } |
| 25 |
struct A { |
| 26 |
int a; |
| 27 |
char c; |
| 28 |
float b; |
| 29 |
}; |
| 30 |
struct B : public A { |
| 31 |
short d; |
| 32 |
double e; |
| 33 |
} b; |
| 34 |
} |
| 35 |
|
| 36 |
namespace Test5 { |
| 37 |
struct A { |
| 38 |
virtual void f(); |
| 39 |
char a; |
| 40 |
}; |
| 41 |
|
| 42 |
// CHECK: %"struct.Test5::B" = type { %"struct.Test5::A.base", i8, i8, [5 x i8] } |
| 43 |
struct B : A { |
| 44 |
char b : 1; |
| 45 |
char c; |
| 46 |
} b; |
| 47 |
} |
| 48 |
|
| 49 |
// PR10912: don't crash |
| 50 |
namespace Test6 { |
| 51 |
template <typename T> class A { |
| 52 |
// If T is complete, IR-gen will want to translate it recursively |
| 53 |
// when translating T*. |
| 54 |
T *foo; |
| 55 |
}; |
| 56 |
|
| 57 |
class B; |
| 58 |
|
| 59 |
// This causes IR-gen to have an incomplete translation of A<B> |
| 60 |
// sitting around. |
| 61 |
A<B> *a; |
| 62 |
|
| 63 |
class C {}; |
| 64 |
class B : public C { |
| 65 |
// This forces Sema to instantiate A<B>, which triggers a callback |
| 66 |
// to IR-gen. Because of the previous, incomplete translation, |
| 67 |
// IR-gen actually cares, and it immediately tries to complete |
| 68 |
// A<B>'s IR type. That, in turn, causes the translation of B*. |
| 69 |
// B isn't complete yet, but it has a definition, and if we try to |
| 70 |
// compute a record layout for that definition then we'll really |
| 71 |
// regret it later. |
| 72 |
A<B> a; |
| 73 |
}; |
| 74 |
|
| 75 |
// The derived class E and empty base class C are required to |
| 76 |
// provoke the original assertion. |
| 77 |
class E : public B {}; |
| 78 |
E *e; |
| 79 |
} |
| 80 |
|
| 81 |
// Make sure this doesn't crash. (It's okay if we start rejecting it at some |
| 82 |
// point.) |
| 83 |
namespace Test7 { |
| 84 |
#pragma pack (1) |
| 85 |
class A {}; |
| 86 |
// CHECK: %"class.Test7::B" = type <{ ptr, i8 }> |
| 87 |
class B { |
| 88 |
virtual ~B(); |
| 89 |
A a; |
| 90 |
}; |
| 91 |
B test(B b) { return b; } |
| 92 |
#pragma pack () |
| 93 |
} |
| 94 |
|
| 95 |
// Shouldn't crash. |
| 96 |
namespace Test8 { |
| 97 |
struct A {}; |
| 98 |
struct D { int a; }; |
| 99 |
struct B : virtual D, A { }; |
| 100 |
struct C : B, A { void f() {} }; |
| 101 |
C c; |
| 102 |
} |