David Majnemer | 1162d25 | 2014-06-22 19:05:33 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -emit-llvm -O1 -o - -triple=i386-pc-win32 %s | FileCheck %s |
Warren Hunt | b57b4b0 | 2014-06-06 22:12:37 +0000 | [diff] [blame] | 2 | |
| 3 | struct S { char a; }; |
David Majnemer | 1162d25 | 2014-06-22 19:05:33 +0000 | [diff] [blame] | 4 | struct V { virtual void f(); }; |
Warren Hunt | b57b4b0 | 2014-06-06 22:12:37 +0000 | [diff] [blame] | 5 | struct A : virtual V {}; |
| 6 | struct B : S, virtual V {}; |
| 7 | struct T {}; |
| 8 | |
| 9 | T* test0() { return dynamic_cast<T*>((B*)0); } |
David Majnemer | 1162d25 | 2014-06-22 19:05:33 +0000 | [diff] [blame] | 10 | // CHECK-LABEL: define noalias %struct.T* @"\01?test0@@YAPAUT@@XZ"() |
| 11 | // CHECK: ret %struct.T* null |
Warren Hunt | b57b4b0 | 2014-06-06 22:12:37 +0000 | [diff] [blame] | 12 | |
| 13 | T* test1(V* x) { return &dynamic_cast<T&>(*x); } |
David Majnemer | 1162d25 | 2014-06-22 19:05:33 +0000 | [diff] [blame] | 14 | // CHECK-LABEL: define %struct.T* @"\01?test1@@YAPAUT@@PAUV@@@Z"(%struct.V* %x) |
| 15 | // CHECK: [[CAST:%.*]] = bitcast %struct.V* %x to i8* |
David Majnemer | 611cdb9 | 2014-07-07 08:09:15 +0000 | [diff] [blame] | 16 | // CHECK-NEXT: [[CALL:%.*]] = tail call i8* @__RTDynamicCast(i8* [[CAST]], i32 0, i8* bitcast (%rtti.TypeDescriptor7* @"\01??_R0?AUV@@@8" to i8*), i8* bitcast (%rtti.TypeDescriptor7* @"\01??_R0?AUT@@@8" to i8*), i32 1) |
David Majnemer | 1162d25 | 2014-06-22 19:05:33 +0000 | [diff] [blame] | 17 | // CHECK-NEXT: [[RET:%.*]] = bitcast i8* [[CALL]] to %struct.T* |
| 18 | // CHECK-NEXT: ret %struct.T* [[RET]] |
Warren Hunt | b57b4b0 | 2014-06-06 22:12:37 +0000 | [diff] [blame] | 19 | |
| 20 | T* test2(A* x) { return &dynamic_cast<T&>(*x); } |
David Majnemer | 1162d25 | 2014-06-22 19:05:33 +0000 | [diff] [blame] | 21 | // CHECK-LABEL: define %struct.T* @"\01?test2@@YAPAUT@@PAUA@@@Z"(%struct.A* %x) |
| 22 | // CHECK: [[CAST:%.*]] = bitcast %struct.A* %x to i8* |
Reid Kleckner | 0ba8ba4 | 2014-10-22 17:26:00 +0000 | [diff] [blame^] | 23 | // CHECK-NEXT: [[VBPTRPTR:%.*]] = getelementptr inbounds %struct.A* %x, i32 0, i32 0 |
| 24 | // CHECK-NEXT: [[VBTBL:%.*]] = load i32** [[VBPTRPTR]], align 4 |
| 25 | // CHECK-NEXT: [[VBOFFP:%.*]] = getelementptr inbounds i32* [[VBTBL]], i32 1 |
| 26 | // CHECK-NEXT: [[VBOFFS:%.*]] = load i32* [[VBOFFP]], align 4 |
David Majnemer | 1162d25 | 2014-06-22 19:05:33 +0000 | [diff] [blame] | 27 | // CHECK-NEXT: [[ADJ:%.*]] = getelementptr inbounds i8* [[CAST]], i32 [[VBOFFS]] |
David Majnemer | 611cdb9 | 2014-07-07 08:09:15 +0000 | [diff] [blame] | 28 | // CHECK-NEXT: [[CALL:%.*]] = tail call i8* @__RTDynamicCast(i8* [[ADJ]], i32 [[VBOFFS]], i8* bitcast (%rtti.TypeDescriptor7* @"\01??_R0?AUA@@@8" to i8*), i8* bitcast (%rtti.TypeDescriptor7* @"\01??_R0?AUT@@@8" to i8*), i32 1) |
David Majnemer | 1162d25 | 2014-06-22 19:05:33 +0000 | [diff] [blame] | 29 | // CHECK-NEXT: [[RET:%.*]] = bitcast i8* [[CALL]] to %struct.T* |
| 30 | // CHECK-NEXT: ret %struct.T* [[RET]] |
Warren Hunt | b57b4b0 | 2014-06-06 22:12:37 +0000 | [diff] [blame] | 31 | |
| 32 | T* test3(B* x) { return &dynamic_cast<T&>(*x); } |
David Majnemer | 1162d25 | 2014-06-22 19:05:33 +0000 | [diff] [blame] | 33 | // CHECK-LABEL: define %struct.T* @"\01?test3@@YAPAUT@@PAUB@@@Z"(%struct.B* %x) |
| 34 | // CHECK: [[VOIDP:%.*]] = getelementptr inbounds %struct.B* %x, i32 0, i32 0, i32 0 |
| 35 | // CHECK-NEXT: [[VBPTR:%.*]] = getelementptr inbounds i8* [[VOIDP]], i32 4 |
Reid Kleckner | 0ba8ba4 | 2014-10-22 17:26:00 +0000 | [diff] [blame^] | 36 | // CHECK-NEXT: [[VBPTRPTR:%.*]] = bitcast i8* [[VBPTR:%.*]] to i32** |
| 37 | // CHECK-NEXT: [[VBTBL:%.*]] = load i32** [[VBPTRPTR]], align 4 |
| 38 | // CHECK-NEXT: [[VBOFFP:%.*]] = getelementptr inbounds i32* [[VBTBL]], i32 1 |
| 39 | // CHECK-NEXT: [[VBOFFS:%.*]] = load i32* [[VBOFFP]], align 4 |
David Majnemer | 1162d25 | 2014-06-22 19:05:33 +0000 | [diff] [blame] | 40 | // CHECK-NEXT: [[DELTA:%.*]] = add nsw i32 [[VBOFFS]], 4 |
| 41 | // CHECK-NEXT: [[ADJ:%.*]] = getelementptr inbounds i8* [[VOIDP]], i32 [[DELTA]] |
David Majnemer | 611cdb9 | 2014-07-07 08:09:15 +0000 | [diff] [blame] | 42 | // CHECK-NEXT: [[CALL:%.*]] = tail call i8* @__RTDynamicCast(i8* [[ADJ]], i32 [[DELTA]], i8* bitcast (%rtti.TypeDescriptor7* @"\01??_R0?AUB@@@8" to i8*), i8* bitcast (%rtti.TypeDescriptor7* @"\01??_R0?AUT@@@8" to i8*), i32 1) |
David Majnemer | 1162d25 | 2014-06-22 19:05:33 +0000 | [diff] [blame] | 43 | // CHECK-NEXT: [[RET:%.*]] = bitcast i8* [[CALL]] to %struct.T* |
| 44 | // CHECK-NEXT: ret %struct.T* [[RET]] |
Warren Hunt | b57b4b0 | 2014-06-06 22:12:37 +0000 | [diff] [blame] | 45 | |
| 46 | T* test4(V* x) { return dynamic_cast<T*>(x); } |
David Majnemer | 1162d25 | 2014-06-22 19:05:33 +0000 | [diff] [blame] | 47 | // CHECK-LABEL: define %struct.T* @"\01?test4@@YAPAUT@@PAUV@@@Z"(%struct.V* %x) |
| 48 | // CHECK: [[CAST:%.*]] = bitcast %struct.V* %x to i8* |
David Majnemer | 611cdb9 | 2014-07-07 08:09:15 +0000 | [diff] [blame] | 49 | // CHECK-NEXT: [[CALL:%.*]] = tail call i8* @__RTDynamicCast(i8* [[CAST]], i32 0, i8* bitcast (%rtti.TypeDescriptor7* @"\01??_R0?AUV@@@8" to i8*), i8* bitcast (%rtti.TypeDescriptor7* @"\01??_R0?AUT@@@8" to i8*), i32 0) |
David Majnemer | 1162d25 | 2014-06-22 19:05:33 +0000 | [diff] [blame] | 50 | // CHECK-NEXT: [[RET:%.*]] = bitcast i8* [[CALL]] to %struct.T* |
| 51 | // CHECK-NEXT: ret %struct.T* [[RET]] |
Warren Hunt | b57b4b0 | 2014-06-06 22:12:37 +0000 | [diff] [blame] | 52 | |
| 53 | T* test5(A* x) { return dynamic_cast<T*>(x); } |
David Majnemer | 1162d25 | 2014-06-22 19:05:33 +0000 | [diff] [blame] | 54 | // CHECK-LABEL: define %struct.T* @"\01?test5@@YAPAUT@@PAUA@@@Z"(%struct.A* %x) |
| 55 | // CHECK: [[CHECK:%.*]] = icmp eq %struct.A* %x, null |
| 56 | // CHECK-NEXT: br i1 [[CHECK]] |
| 57 | // CHECK: [[VOIDP:%.*]] = bitcast %struct.A* %x to i8* |
Reid Kleckner | 0ba8ba4 | 2014-10-22 17:26:00 +0000 | [diff] [blame^] | 58 | // CHECK-NEXT: [[VBPTRPTR:%.*]] = getelementptr inbounds %struct.A* %x, i32 0, i32 0 |
| 59 | // CHECK-NEXT: [[VBTBL:%.*]] = load i32** [[VBPTRPTR]], align 4 |
| 60 | // CHECK-NEXT: [[VBOFFP:%.*]] = getelementptr inbounds i32* [[VBTBL]], i32 1 |
| 61 | // CHECK-NEXT: [[VBOFFS:%.*]] = load i32* [[VBOFFP]], align 4 |
David Majnemer | 1162d25 | 2014-06-22 19:05:33 +0000 | [diff] [blame] | 62 | // CHECK-NEXT: [[ADJ:%.*]] = getelementptr inbounds i8* [[VOIDP]], i32 [[VBOFFS]] |
David Majnemer | 611cdb9 | 2014-07-07 08:09:15 +0000 | [diff] [blame] | 63 | // CHECK-NEXT: [[CALL:%.*]] = tail call i8* @__RTDynamicCast(i8* [[ADJ]], i32 [[VBOFFS]], i8* bitcast (%rtti.TypeDescriptor7* @"\01??_R0?AUA@@@8" to i8*), i8* bitcast (%rtti.TypeDescriptor7* @"\01??_R0?AUT@@@8" to i8*), i32 0) |
David Majnemer | 1162d25 | 2014-06-22 19:05:33 +0000 | [diff] [blame] | 64 | // CHECK-NEXT: [[RES:%.*]] = bitcast i8* [[CALL]] to %struct.T* |
| 65 | // CHECK-NEXT: br label |
| 66 | // CHECK: [[RET:%.*]] = phi %struct.T* |
| 67 | // CHECK-NEXT: ret %struct.T* [[RET]] |
Warren Hunt | b57b4b0 | 2014-06-06 22:12:37 +0000 | [diff] [blame] | 68 | |
| 69 | T* test6(B* x) { return dynamic_cast<T*>(x); } |
David Majnemer | 1162d25 | 2014-06-22 19:05:33 +0000 | [diff] [blame] | 70 | // CHECK-LABEL: define %struct.T* @"\01?test6@@YAPAUT@@PAUB@@@Z"(%struct.B* %x) |
| 71 | // CHECK: [[CHECK:%.*]] = icmp eq %struct.B* %x, null |
| 72 | // CHECK-NEXT: br i1 [[CHECK]] |
| 73 | // CHECK: [[CAST:%.*]] = getelementptr inbounds %struct.B* %x, i32 0, i32 0, i32 0 |
| 74 | // CHECK-NEXT: [[VBPTR:%.*]] = getelementptr inbounds i8* [[CAST]], i32 4 |
Reid Kleckner | 0ba8ba4 | 2014-10-22 17:26:00 +0000 | [diff] [blame^] | 75 | // CHECK-NEXT: [[VBPTRPTR:%.*]] = bitcast i8* [[VBPTR]] to i32** |
| 76 | // CHECK-NEXT: [[VBTBL:%.*]] = load i32** [[VBPTRPTR]], align 4 |
| 77 | // CHECK-NEXT: [[VBOFFP:%.*]] = getelementptr inbounds i32* [[VBTBL]], i32 1 |
| 78 | // CHECK-NEXT: [[VBOFFS:%.*]] = load i32* [[VBOFFP]], align 4 |
David Majnemer | 1162d25 | 2014-06-22 19:05:33 +0000 | [diff] [blame] | 79 | // CHECK-NEXT: [[DELTA:%.*]] = add nsw i32 [[VBOFFS]], 4 |
| 80 | // CHECK-NEXT: [[ADJ:%.*]] = getelementptr inbounds i8* [[CAST]], i32 [[DELTA]] |
David Majnemer | 611cdb9 | 2014-07-07 08:09:15 +0000 | [diff] [blame] | 81 | // CHECK-NEXT: [[CALL:%.*]] = tail call i8* @__RTDynamicCast(i8* [[ADJ]], i32 [[DELTA]], i8* bitcast (%rtti.TypeDescriptor7* @"\01??_R0?AUB@@@8" to i8*), i8* bitcast (%rtti.TypeDescriptor7* @"\01??_R0?AUT@@@8" to i8*), i32 0) |
David Majnemer | 1162d25 | 2014-06-22 19:05:33 +0000 | [diff] [blame] | 82 | // CHECK-NEXT: [[RES:%.*]] = bitcast i8* [[CALL]] to %struct.T* |
| 83 | // CHECK-NEXT: br label |
| 84 | // CHECK: [[RET:%.*]] = phi %struct.T* |
| 85 | // CHECK-NEXT: ret %struct.T* [[RET]] |
Warren Hunt | b57b4b0 | 2014-06-06 22:12:37 +0000 | [diff] [blame] | 86 | |
| 87 | void* test7(V* x) { return dynamic_cast<void*>(x); } |
David Majnemer | 1162d25 | 2014-06-22 19:05:33 +0000 | [diff] [blame] | 88 | // CHECK-LABEL: define i8* @"\01?test7@@YAPAXPAUV@@@Z"(%struct.V* %x) |
| 89 | // CHECK: [[CAST:%.*]] = bitcast %struct.V* %x to i8* |
| 90 | // CHECK-NEXT: [[RET:%.*]] = tail call i8* @__RTCastToVoid(i8* [[CAST]]) |
| 91 | // CHECK-NEXT: ret i8* [[RET]] |
Warren Hunt | b57b4b0 | 2014-06-06 22:12:37 +0000 | [diff] [blame] | 92 | |
| 93 | void* test8(A* x) { return dynamic_cast<void*>(x); } |
David Majnemer | 1162d25 | 2014-06-22 19:05:33 +0000 | [diff] [blame] | 94 | // CHECK-LABEL: define i8* @"\01?test8@@YAPAXPAUA@@@Z"(%struct.A* %x) |
| 95 | // CHECK: [[CHECK:%.*]] = icmp eq %struct.A* %x, null |
| 96 | // CHECK-NEXT: br i1 [[CHECK]] |
| 97 | // CHECK: [[VOIDP:%.*]] = bitcast %struct.A* %x to i8* |
Reid Kleckner | 0ba8ba4 | 2014-10-22 17:26:00 +0000 | [diff] [blame^] | 98 | // CHECK-NEXT: [[VBPTRPTR:%.*]] = getelementptr inbounds %struct.A* %x, i32 0, i32 0 |
| 99 | // CHECK-NEXT: [[VBTBL:%.*]] = load i32** [[VBPTRPTR]], align 4 |
| 100 | // CHECK-NEXT: [[VBOFFP:%.*]] = getelementptr inbounds i32* [[VBTBL]], i32 1 |
| 101 | // CHECK-NEXT: [[VBOFFS:%.*]] = load i32* [[VBOFFP]], align 4 |
David Majnemer | 1162d25 | 2014-06-22 19:05:33 +0000 | [diff] [blame] | 102 | // CHECK-NEXT: [[ADJ:%.*]] = getelementptr inbounds i8* [[VOIDP]], i32 [[VBOFFS]] |
| 103 | // CHECK-NEXT: [[RES:%.*]] = tail call i8* @__RTCastToVoid(i8* [[ADJ]]) |
| 104 | // CHECK-NEXT: br label |
| 105 | // CHECK: [[RET:%.*]] = phi i8* |
| 106 | // CHECK-NEXT: ret i8* [[RET]] |
Warren Hunt | b57b4b0 | 2014-06-06 22:12:37 +0000 | [diff] [blame] | 107 | |
| 108 | void* test9(B* x) { return dynamic_cast<void*>(x); } |
David Majnemer | 1162d25 | 2014-06-22 19:05:33 +0000 | [diff] [blame] | 109 | // CHECK-LABEL: define i8* @"\01?test9@@YAPAXPAUB@@@Z"(%struct.B* %x) |
| 110 | // CHECK: [[CHECK:%.*]] = icmp eq %struct.B* %x, null |
| 111 | // CHECK-NEXT: br i1 [[CHECK]] |
| 112 | // CHECK: [[CAST:%.*]] = getelementptr inbounds %struct.B* %x, i32 0, i32 0, i32 0 |
| 113 | // CHECK-NEXT: [[VBPTR:%.*]] = getelementptr inbounds i8* [[CAST]], i32 4 |
Reid Kleckner | 0ba8ba4 | 2014-10-22 17:26:00 +0000 | [diff] [blame^] | 114 | // CHECK-NEXT: [[VBPTRPTR:%.*]] = bitcast i8* [[VBPTR]] to i32** |
| 115 | // CHECK-NEXT: [[VBTBL:%.*]] = load i32** [[VBPTRPTR]], align 4 |
| 116 | // CHECK-NEXT: [[VBOFFP:%.*]] = getelementptr inbounds i32* [[VBTBL]], i32 1 |
| 117 | // CHECK-NEXT: [[VBOFFS:%.*]] = load i32* [[VBOFFP]], align 4 |
David Majnemer | 1162d25 | 2014-06-22 19:05:33 +0000 | [diff] [blame] | 118 | // CHECK-NEXT: [[DELTA:%.*]] = add nsw i32 [[VBOFFS]], 4 |
| 119 | // CHECK-NEXT: [[ADJ:%.*]] = getelementptr inbounds i8* [[CAST]], i32 [[DELTA]] |
| 120 | // CHECK-NEXT: [[CALL:%.*]] = tail call i8* @__RTCastToVoid(i8* [[ADJ]]) |
| 121 | // CHECK-NEXT: br label |
| 122 | // CHECK: [[RET:%.*]] = phi i8* |
| 123 | // CHECK-NEXT: ret i8* [[RET]] |
| 124 | |