blob: 21e1a2b40f04c902b55f8e8d37b40737cfbe5aaf [file] [log] [blame]
Anders Carlsson560bf122010-12-05 00:08:52 +00001// RUN: %clang_cc1 %s -triple x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
Anders Carlsson696798f2009-07-27 17:10:54 +00002
Anders Carlsson68e30132010-05-05 05:47:36 +00003// An extra byte should be allocated for an empty class.
Anders Carlsson560bf122010-12-05 00:08:52 +00004namespace Test1 {
5 // CHECK: %"struct.Test1::A" = type { i8 }
6 struct A { } *a;
7}
Anders Carlssonc2456822009-12-08 01:24:23 +00008
Anders Carlsson560bf122010-12-05 00:08:52 +00009namespace Test2 {
10 // No need to add tail padding here.
11 // CHECK: %"struct.Test2::A" = type { i8*, i32 }
12 struct A { void *a; int b; } *a;
13}
Anders Carlsson4b3e5be2009-12-16 17:27:20 +000014
Anders Carlsson560bf122010-12-05 00:08:52 +000015namespace Test3 {
16 // C should have a vtable pointer.
17 // CHECK: %"struct.Test3::A" = type { i32 (...)**, i32 }
18 struct A { virtual void f(); int a; } *a;
19}
Anders Carlssoneb9d81d2011-04-17 21:56:13 +000020
21namespace Test4 {
22 // Test from PR5589.
Anders Carlssoneb9d81d2011-04-17 21:56:13 +000023 // CHECK: %"struct.Test4::B" = type { %"struct.Test4::A", i16, double }
Chris Lattner9cbe4f02011-07-09 17:41:47 +000024 // CHECK: %"struct.Test4::A" = type { i32, i8, float }
Anders Carlssoneb9d81d2011-04-17 21:56:13 +000025 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
36namespace Test5 {
37 struct A {
38 virtual void f();
39 char a;
40 };
41
Anders Carlssonf54d81f2011-04-17 21:57:29 +000042 // CHECK: %"struct.Test5::B" = type { [9 x i8], i8, i8, [5 x i8] }
Anders Carlssoneb9d81d2011-04-17 21:56:13 +000043 struct B : A {
44 char b : 1;
45 char c;
46 } *b;
47}
John McCall65959352011-10-07 02:39:22 +000048
49// PR10912: don't crash
50namespace 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}
Eli Friedmanc8f11e92012-04-27 02:34:46 +000080
81// <rdar://problem/11324125>: Make sure this doesn't crash. (It's okay
82// if we start rejecting it at some point.)
83namespace Test7 {
84 #pragma pack (1)
85 class A {};
86 // CHECK: %"class.Test7::B" = type <{ i32 (...)**, %"class.Test7::A" }>
87 class B {
88 virtual ~B();
89 A a;
90 };
91 B* b;
92 #pragma pack ()
93}