| 1 | // RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -emit-llvm -O3 -o - | FileCheck %s |
| 2 | |
| 3 | // CHECK: %"struct.rdar20621065::B" = type { float, float } |
| 4 | |
| 5 | struct Empty { }; |
| 6 | |
| 7 | struct A { |
| 8 | explicit A(unsigned a = 0xffffffff) : a(a) { } |
| 9 | |
| 10 | unsigned a; |
| 11 | }; |
| 12 | |
| 13 | struct B : A, Empty { |
| 14 | B() : A(), Empty() { } |
| 15 | }; |
| 16 | |
| 17 | struct C : A, Empty { |
| 18 | C() : A(), Empty() { } |
| 19 | C(const C& other) : A(0x12345678), Empty(other) { } |
| 20 | }; |
| 21 | |
| 22 | struct D : A, Empty { |
| 23 | D& operator=(const D& other) { |
| 24 | a = 0x87654321; |
| 25 | Empty::operator=(other); |
| 26 | |
| 27 | return *this; |
| 28 | } |
| 29 | }; |
| 30 | |
| 31 | #define CHECK(x) if (!(x)) return __LINE__ |
| 32 | |
| 33 | // PR7012 |
| 34 | // CHECK-LABEL: define i32 @_Z1fv() |
| 35 | int f() { |
| 36 | B b1; |
| 37 | |
| 38 | // Check that A::a is not overwritten by the Empty default constructor. |
| 39 | CHECK(b1.a == 0xffffffff); |
| 40 | |
| 41 | C c1; |
| 42 | C c2(c1); |
| 43 | |
| 44 | // Check that A::a has the value set in the C::C copy constructor. |
| 45 | CHECK(c2.a == 0x12345678); |
| 46 | |
| 47 | D d1, d2; |
| 48 | d2 = d1; |
| 49 | |
| 50 | // Check that A::as has the value set in the D copy assignment operator. |
| 51 | CHECK(d2.a == 0x87654321); |
| 52 | |
| 53 | // Success! |
| 54 | // CHECK: ret i32 0 |
| 55 | return 0; |
| 56 | } |
| 57 | |
| 58 | namespace PR8796 { |
| 59 | struct FreeCell { |
| 60 | }; |
| 61 | union ThingOrCell { |
| 62 | FreeCell t; |
| 63 | FreeCell cell; |
| 64 | }; |
| 65 | struct Things { |
| 66 | ThingOrCell things; |
| 67 | }; |
| 68 | Things x; |
| 69 | } |
| 70 | |
| 71 | #ifdef HARNESS |
| 72 | extern "C" void printf(const char *, ...); |
| 73 | |
| 74 | int main() { |
| 75 | int result = f(); |
| 76 | |
| 77 | if (result == 0) |
| 78 | printf("success!\n"); |
| 79 | else |
| 80 | printf("test on line %d failed!\n", result); |
| 81 | |
| 82 | return result; |
| 83 | } |
| 84 | #endif |
| 85 | |
| 86 | namespace rdar20621065 { |
| 87 | struct A { |
| 88 | float array[0]; |
| 89 | }; |
| 90 | |
| 91 | struct B : A { |
| 92 | float left; |
| 93 | float right; |
| 94 | }; |
| 95 | |
| 96 | // Type checked at the top of the file. |
| 97 | B b; |
| 98 | }; |
| 99 | |
| 100 | // This test used to crash when CGRecordLayout::getNonVirtualBaseLLVMFieldNo was called. |
| 101 | namespace record_layout { |
| 102 | struct X0 { |
| 103 | int x[0]; |
| 104 | }; |
| 105 | |
| 106 | template<typename> |
| 107 | struct X2 : X0 { |
| 108 | }; |
| 109 | |
| 110 | template<typename> |
| 111 | struct X3 : X2<int> { |
| 112 | X3() : X2<int>() {} |
| 113 | }; |
| 114 | |
| 115 | |
| 116 | void test0() { |
| 117 | X3<int>(); |
| 118 | } |
| 119 | } |
| 120 | |