John McCall | 7916c99 | 2012-08-01 05:04:58 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -emit-llvm %s -o - | FileCheck %s |
Fariborz Jahanian | 93034ca | 2009-10-16 19:20:59 +0000 | [diff] [blame] | 2 | |
| 3 | struct A { |
John McCall | 7916c99 | 2012-08-01 05:04:58 +0000 | [diff] [blame] | 4 | A(const A&); |
| 5 | A(); |
| 6 | ~A(); |
Fariborz Jahanian | 93034ca | 2009-10-16 19:20:59 +0000 | [diff] [blame] | 7 | }; |
| 8 | |
| 9 | struct B : public A { |
John McCall | 7916c99 | 2012-08-01 05:04:58 +0000 | [diff] [blame] | 10 | B(); |
| 11 | B(const B& Other); |
| 12 | ~B(); |
Douglas Gregor | 2f59979 | 2010-04-02 18:24:57 +0000 | [diff] [blame] | 13 | }; |
Fariborz Jahanian | 93034ca | 2009-10-16 19:20:59 +0000 | [diff] [blame] | 14 | |
| 15 | struct C : public B { |
John McCall | 7916c99 | 2012-08-01 05:04:58 +0000 | [diff] [blame] | 16 | C(); |
| 17 | C(const C& Other); |
| 18 | ~C(); |
Fariborz Jahanian | 93034ca | 2009-10-16 19:20:59 +0000 | [diff] [blame] | 19 | }; |
| 20 | |
| 21 | struct X { |
John McCall | 7916c99 | 2012-08-01 05:04:58 +0000 | [diff] [blame] | 22 | operator B&(); |
| 23 | operator C&(); |
| 24 | X(const X&); |
| 25 | X(); |
| 26 | ~X(); |
| 27 | B b; |
| 28 | C c; |
Fariborz Jahanian | 93034ca | 2009-10-16 19:20:59 +0000 | [diff] [blame] | 29 | }; |
| 30 | |
John McCall | 7916c99 | 2012-08-01 05:04:58 +0000 | [diff] [blame] | 31 | void test0_helper(A); |
| 32 | void test0(X x) { |
| 33 | test0_helper(x); |
| 34 | // CHECK: define void @_Z5test01X( |
| 35 | // CHECK: [[TMP:%.*]] = alloca [[A:%.*]], align |
| 36 | // CHECK-NEXT: [[T0:%.*]] = call [[B:%.*]]* @_ZN1XcvR1BEv( |
| 37 | // CHECK-NEXT: [[T1:%.*]] = bitcast [[B]]* [[T0]] to [[A]]* |
| 38 | // CHECK-NEXT: call void @_ZN1AC1ERKS_([[A]]* [[TMP]], [[A]]* [[T1]]) |
| 39 | // CHECK-NEXT: call void @_Z12test0_helper1A([[A]]* [[TMP]]) |
| 40 | // CHECK-NEXT: call void @_ZN1AD1Ev([[A]]* [[TMP]]) |
| 41 | // CHECK-NEXT: ret void |
Fariborz Jahanian | 93034ca | 2009-10-16 19:20:59 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Fariborz Jahanian | 3759a03 | 2009-10-19 19:18:20 +0000 | [diff] [blame] | 44 | struct Base; |
| 45 | |
| 46 | struct Root { |
John McCall | 7916c99 | 2012-08-01 05:04:58 +0000 | [diff] [blame] | 47 | operator Base&(); |
Fariborz Jahanian | 3759a03 | 2009-10-19 19:18:20 +0000 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | struct Derived; |
| 51 | |
| 52 | struct Base : Root { |
John McCall | 7916c99 | 2012-08-01 05:04:58 +0000 | [diff] [blame] | 53 | Base(const Base &); |
| 54 | Base(); |
| 55 | operator Derived &(); |
Fariborz Jahanian | 3759a03 | 2009-10-19 19:18:20 +0000 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | struct Derived : Base { |
| 59 | }; |
| 60 | |
John McCall | 7916c99 | 2012-08-01 05:04:58 +0000 | [diff] [blame] | 61 | void test1_helper(Base); |
| 62 | void test1(Derived bb) { |
| 63 | // CHECK: define void @_Z5test17Derived( |
| 64 | // CHECK-NOT: call {{.*}} @_ZN4BasecvR7DerivedEv( |
| 65 | // CHECK: call void @_ZN4BaseC1ERKS_( |
| 66 | // CHECK-NOT: call {{.*}} @_ZN4BasecvR7DerivedEv( |
| 67 | // CHECK: call void @_Z12test1_helper4Base( |
| 68 | test1_helper(bb); |
Fariborz Jahanian | 3759a03 | 2009-10-19 19:18:20 +0000 | [diff] [blame] | 69 | } |
Fariborz Jahanian | 93034ca | 2009-10-16 19:20:59 +0000 | [diff] [blame] | 70 | |
John McCall | 7916c99 | 2012-08-01 05:04:58 +0000 | [diff] [blame] | 71 | // Don't crash after devirtualizing a derived-to-base conversion |
| 72 | // to an empty base allocated at offset zero. |
| 73 | // rdar://problem/11993704 |
| 74 | class Test2a {}; |
| 75 | class Test2b final : public virtual Test2a {}; |
| 76 | void test2(Test2b &x) { |
| 77 | Test2a &y = x; |
| 78 | // CHECK: define void @_Z5test2R6Test2b( |
| 79 | // CHECK: [[X:%.*]] = alloca [[B:%.*]]*, align 8 |
| 80 | // CHECK-NEXT: [[Y:%.*]] = alloca [[A:%.*]]*, align 8 |
| 81 | // CHECK-NEXT: store [[B]]* {{%.*}}, [[B]]** [[X]], align 8 |
| 82 | // CHECK-NEXT: [[T0:%.*]] = load [[B]]** [[X]], align 8 |
| 83 | // CHECK-NEXT: [[T1:%.*]] = bitcast [[B]]* [[T0]] to [[A]]* |
| 84 | // CHECK-NEXT: store [[A]]* [[T1]], [[A]]** [[Y]], align 8 |
| 85 | // CHECK-NEXT: ret void |
| 86 | } |