2015-11-23 11:01:14 +08:00
|
|
|
// RUN: %clang_cc1 -emit-llvm -O1 -o - -fexceptions -triple=i386-pc-win32 %s | FileCheck %s
|
2014-06-07 06:12:37 +08:00
|
|
|
|
|
|
|
struct S { char a; };
|
2014-06-23 03:05:33 +08:00
|
|
|
struct V { virtual void f(); };
|
2014-06-07 06:12:37 +08:00
|
|
|
struct A : virtual V {};
|
|
|
|
struct B : S, virtual V {};
|
|
|
|
struct T {};
|
|
|
|
|
|
|
|
T* test0() { return dynamic_cast<T*>((B*)0); }
|
2014-06-23 03:05:33 +08:00
|
|
|
// CHECK-LABEL: define noalias %struct.T* @"\01?test0@@YAPAUT@@XZ"()
|
|
|
|
// CHECK: ret %struct.T* null
|
2014-06-07 06:12:37 +08:00
|
|
|
|
|
|
|
T* test1(V* x) { return &dynamic_cast<T&>(*x); }
|
2014-06-23 03:05:33 +08:00
|
|
|
// CHECK-LABEL: define %struct.T* @"\01?test1@@YAPAUT@@PAUV@@@Z"(%struct.V* %x)
|
|
|
|
// CHECK: [[CAST:%.*]] = bitcast %struct.V* %x to i8*
|
2014-07-07 16:09:15 +08:00
|
|
|
// 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)
|
2014-06-23 03:05:33 +08:00
|
|
|
// CHECK-NEXT: [[RET:%.*]] = bitcast i8* [[CALL]] to %struct.T*
|
|
|
|
// CHECK-NEXT: ret %struct.T* [[RET]]
|
2014-06-07 06:12:37 +08:00
|
|
|
|
|
|
|
T* test2(A* x) { return &dynamic_cast<T&>(*x); }
|
2014-06-23 03:05:33 +08:00
|
|
|
// CHECK-LABEL: define %struct.T* @"\01?test2@@YAPAUT@@PAUA@@@Z"(%struct.A* %x)
|
|
|
|
// CHECK: [[CAST:%.*]] = bitcast %struct.A* %x to i8*
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[VBPTRPTR:%.*]] = getelementptr inbounds %struct.A, %struct.A* %x, i32 0, i32 0
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[VBTBL:%.*]] = load i32*, i32** [[VBPTRPTR]], align 4
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[VBOFFP:%.*]] = getelementptr inbounds i32, i32* [[VBTBL]], i32 1
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[VBOFFS:%.*]] = load i32, i32* [[VBOFFP]], align 4
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[ADJ:%.*]] = getelementptr inbounds i8, i8* [[CAST]], i32 [[VBOFFS]]
|
2014-07-07 16:09:15 +08:00
|
|
|
// 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)
|
2014-06-23 03:05:33 +08:00
|
|
|
// CHECK-NEXT: [[RET:%.*]] = bitcast i8* [[CALL]] to %struct.T*
|
|
|
|
// CHECK-NEXT: ret %struct.T* [[RET]]
|
2014-06-07 06:12:37 +08:00
|
|
|
|
|
|
|
T* test3(B* x) { return &dynamic_cast<T&>(*x); }
|
2014-06-23 03:05:33 +08:00
|
|
|
// CHECK-LABEL: define %struct.T* @"\01?test3@@YAPAUT@@PAUB@@@Z"(%struct.B* %x)
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK: [[VOIDP:%.*]] = getelementptr inbounds %struct.B, %struct.B* %x, i32 0, i32 0, i32 0
|
|
|
|
// CHECK-NEXT: [[VBPTR:%.*]] = getelementptr inbounds i8, i8* [[VOIDP]], i32 4
|
2014-10-23 01:26:00 +08:00
|
|
|
// CHECK-NEXT: [[VBPTRPTR:%.*]] = bitcast i8* [[VBPTR:%.*]] to i32**
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[VBTBL:%.*]] = load i32*, i32** [[VBPTRPTR]], align 4
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[VBOFFP:%.*]] = getelementptr inbounds i32, i32* [[VBTBL]], i32 1
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[VBOFFS:%.*]] = load i32, i32* [[VBOFFP]], align 4
|
2014-06-23 03:05:33 +08:00
|
|
|
// CHECK-NEXT: [[DELTA:%.*]] = add nsw i32 [[VBOFFS]], 4
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[ADJ:%.*]] = getelementptr inbounds i8, i8* [[VOIDP]], i32 [[DELTA]]
|
2014-07-07 16:09:15 +08:00
|
|
|
// 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)
|
2014-06-23 03:05:33 +08:00
|
|
|
// CHECK-NEXT: [[RET:%.*]] = bitcast i8* [[CALL]] to %struct.T*
|
|
|
|
// CHECK-NEXT: ret %struct.T* [[RET]]
|
2014-06-07 06:12:37 +08:00
|
|
|
|
|
|
|
T* test4(V* x) { return dynamic_cast<T*>(x); }
|
2014-06-23 03:05:33 +08:00
|
|
|
// CHECK-LABEL: define %struct.T* @"\01?test4@@YAPAUT@@PAUV@@@Z"(%struct.V* %x)
|
|
|
|
// CHECK: [[CAST:%.*]] = bitcast %struct.V* %x to i8*
|
2014-07-07 16:09:15 +08:00
|
|
|
// 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)
|
2014-06-23 03:05:33 +08:00
|
|
|
// CHECK-NEXT: [[RET:%.*]] = bitcast i8* [[CALL]] to %struct.T*
|
|
|
|
// CHECK-NEXT: ret %struct.T* [[RET]]
|
2014-06-07 06:12:37 +08:00
|
|
|
|
|
|
|
T* test5(A* x) { return dynamic_cast<T*>(x); }
|
2014-06-23 03:05:33 +08:00
|
|
|
// CHECK-LABEL: define %struct.T* @"\01?test5@@YAPAUT@@PAUA@@@Z"(%struct.A* %x)
|
|
|
|
// CHECK: [[CHECK:%.*]] = icmp eq %struct.A* %x, null
|
|
|
|
// CHECK-NEXT: br i1 [[CHECK]]
|
|
|
|
// CHECK: [[VOIDP:%.*]] = bitcast %struct.A* %x to i8*
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[VBPTRPTR:%.*]] = getelementptr inbounds %struct.A, %struct.A* %x, i32 0, i32 0
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[VBTBL:%.*]] = load i32*, i32** [[VBPTRPTR]], align 4
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[VBOFFP:%.*]] = getelementptr inbounds i32, i32* [[VBTBL]], i32 1
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[VBOFFS:%.*]] = load i32, i32* [[VBOFFP]], align 4
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[ADJ:%.*]] = getelementptr inbounds i8, i8* [[VOIDP]], i32 [[VBOFFS]]
|
2016-02-11 08:14:04 +08:00
|
|
|
// 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)
|
2014-06-23 03:05:33 +08:00
|
|
|
// CHECK-NEXT: [[RES:%.*]] = bitcast i8* [[CALL]] to %struct.T*
|
|
|
|
// CHECK-NEXT: br label
|
|
|
|
// CHECK: [[RET:%.*]] = phi %struct.T*
|
|
|
|
// CHECK-NEXT: ret %struct.T* [[RET]]
|
2014-06-07 06:12:37 +08:00
|
|
|
|
|
|
|
T* test6(B* x) { return dynamic_cast<T*>(x); }
|
2014-06-23 03:05:33 +08:00
|
|
|
// CHECK-LABEL: define %struct.T* @"\01?test6@@YAPAUT@@PAUB@@@Z"(%struct.B* %x)
|
|
|
|
// CHECK: [[CHECK:%.*]] = icmp eq %struct.B* %x, null
|
|
|
|
// CHECK-NEXT: br i1 [[CHECK]]
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK: [[CAST:%.*]] = getelementptr inbounds %struct.B, %struct.B* %x, i32 0, i32 0, i32 0
|
|
|
|
// CHECK-NEXT: [[VBPTR:%.*]] = getelementptr inbounds i8, i8* [[CAST]], i32 4
|
2014-10-23 01:26:00 +08:00
|
|
|
// CHECK-NEXT: [[VBPTRPTR:%.*]] = bitcast i8* [[VBPTR]] to i32**
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[VBTBL:%.*]] = load i32*, i32** [[VBPTRPTR]], align 4
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[VBOFFP:%.*]] = getelementptr inbounds i32, i32* [[VBTBL]], i32 1
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[VBOFFS:%.*]] = load i32, i32* [[VBOFFP]], align 4
|
2014-06-23 03:05:33 +08:00
|
|
|
// CHECK-NEXT: [[DELTA:%.*]] = add nsw i32 [[VBOFFS]], 4
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[ADJ:%.*]] = getelementptr inbounds i8, i8* [[CAST]], i32 [[DELTA]]
|
2016-02-11 08:14:04 +08:00
|
|
|
// 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)
|
2014-06-23 03:05:33 +08:00
|
|
|
// CHECK-NEXT: [[RES:%.*]] = bitcast i8* [[CALL]] to %struct.T*
|
|
|
|
// CHECK-NEXT: br label
|
|
|
|
// CHECK: [[RET:%.*]] = phi %struct.T*
|
|
|
|
// CHECK-NEXT: ret %struct.T* [[RET]]
|
2014-06-07 06:12:37 +08:00
|
|
|
|
|
|
|
void* test7(V* x) { return dynamic_cast<void*>(x); }
|
2014-06-23 03:05:33 +08:00
|
|
|
// CHECK-LABEL: define i8* @"\01?test7@@YAPAXPAUV@@@Z"(%struct.V* %x)
|
|
|
|
// CHECK: [[CAST:%.*]] = bitcast %struct.V* %x to i8*
|
|
|
|
// CHECK-NEXT: [[RET:%.*]] = tail call i8* @__RTCastToVoid(i8* [[CAST]])
|
|
|
|
// CHECK-NEXT: ret i8* [[RET]]
|
2014-06-07 06:12:37 +08:00
|
|
|
|
|
|
|
void* test8(A* x) { return dynamic_cast<void*>(x); }
|
2014-06-23 03:05:33 +08:00
|
|
|
// CHECK-LABEL: define i8* @"\01?test8@@YAPAXPAUA@@@Z"(%struct.A* %x)
|
|
|
|
// CHECK: [[CHECK:%.*]] = icmp eq %struct.A* %x, null
|
|
|
|
// CHECK-NEXT: br i1 [[CHECK]]
|
|
|
|
// CHECK: [[VOIDP:%.*]] = bitcast %struct.A* %x to i8*
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[VBPTRPTR:%.*]] = getelementptr inbounds %struct.A, %struct.A* %x, i32 0, i32 0
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[VBTBL:%.*]] = load i32*, i32** [[VBPTRPTR]], align 4
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[VBOFFP:%.*]] = getelementptr inbounds i32, i32* [[VBTBL]], i32 1
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[VBOFFS:%.*]] = load i32, i32* [[VBOFFP]], align 4
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[ADJ:%.*]] = getelementptr inbounds i8, i8* [[VOIDP]], i32 [[VBOFFS]]
|
2014-06-23 03:05:33 +08:00
|
|
|
// CHECK-NEXT: [[RES:%.*]] = tail call i8* @__RTCastToVoid(i8* [[ADJ]])
|
|
|
|
// CHECK-NEXT: br label
|
|
|
|
// CHECK: [[RET:%.*]] = phi i8*
|
|
|
|
// CHECK-NEXT: ret i8* [[RET]]
|
2014-06-07 06:12:37 +08:00
|
|
|
|
|
|
|
void* test9(B* x) { return dynamic_cast<void*>(x); }
|
2014-06-23 03:05:33 +08:00
|
|
|
// CHECK-LABEL: define i8* @"\01?test9@@YAPAXPAUB@@@Z"(%struct.B* %x)
|
|
|
|
// CHECK: [[CHECK:%.*]] = icmp eq %struct.B* %x, null
|
|
|
|
// CHECK-NEXT: br i1 [[CHECK]]
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK: [[CAST:%.*]] = getelementptr inbounds %struct.B, %struct.B* %x, i32 0, i32 0, i32 0
|
|
|
|
// CHECK-NEXT: [[VBPTR:%.*]] = getelementptr inbounds i8, i8* [[CAST]], i32 4
|
2014-10-23 01:26:00 +08:00
|
|
|
// CHECK-NEXT: [[VBPTRPTR:%.*]] = bitcast i8* [[VBPTR]] to i32**
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[VBTBL:%.*]] = load i32*, i32** [[VBPTRPTR]], align 4
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[VBOFFP:%.*]] = getelementptr inbounds i32, i32* [[VBTBL]], i32 1
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[VBOFFS:%.*]] = load i32, i32* [[VBOFFP]], align 4
|
2014-06-23 03:05:33 +08:00
|
|
|
// CHECK-NEXT: [[DELTA:%.*]] = add nsw i32 [[VBOFFS]], 4
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[ADJ:%.*]] = getelementptr inbounds i8, i8* [[CAST]], i32 [[DELTA]]
|
2014-06-23 03:05:33 +08:00
|
|
|
// CHECK-NEXT: [[CALL:%.*]] = tail call i8* @__RTCastToVoid(i8* [[ADJ]])
|
|
|
|
// CHECK-NEXT: br label
|
|
|
|
// CHECK: [[RET:%.*]] = phi i8*
|
|
|
|
// CHECK-NEXT: ret i8* [[RET]]
|
|
|
|
|
2015-11-23 11:01:14 +08:00
|
|
|
namespace PR25606 {
|
|
|
|
struct Cleanup {
|
|
|
|
~Cleanup();
|
|
|
|
};
|
|
|
|
struct S1 { virtual ~S1(); };
|
|
|
|
struct S2 : virtual S1 {};
|
|
|
|
struct S3 : S2 {};
|
|
|
|
|
|
|
|
S3 *f(S2 &s) {
|
|
|
|
Cleanup c;
|
|
|
|
return dynamic_cast<S3 *>(&s);
|
|
|
|
}
|
|
|
|
// CHECK-LABEL: define %"struct.PR25606::S3"* @"\01?f@PR25606@@YAPAUS3@1@AAUS2@1@@Z"(
|
|
|
|
// CHECK: [[CALL:%.*]] = invoke i8* @__RTDynamicCast
|
|
|
|
|
|
|
|
// CHECK: [[BC:%.*]] = bitcast i8* [[CALL]] to %"struct.PR25606::S3"*
|
2017-02-14 08:54:11 +08:00
|
|
|
// CHECK: call x86_thiscallcc void @"\01??_DCleanup@PR25606@@QAEXXZ"(
|
2015-11-23 11:01:14 +08:00
|
|
|
// CHECK: ret %"struct.PR25606::S3"* [[BC]]
|
|
|
|
}
|