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.
4namespace Test1 {
5  // CHECK: %"struct.Test1::A" = type { i8 }
6  struct A { } *a;
7}
8
9namespace 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}
14
15namespace 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}
20
21namespace 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
36namespace Test5 {
37  struct A {
38    virtual void f();
39    char a;
40  };
41
42  // CHECK: %"struct.Test5::B" = type { [9 x i8], 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
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}
80