brintos

brintos / llvm-project-archived public Read only

0
0
Text · 6.2 KiB · a5d0d5a Raw
122 lines · cpp
1// RUN: %clang_cc1 -emit-llvm -O1 -o - -fexceptions -triple=i386-pc-win32 %s | FileCheck %s2 3struct S { char a; };4struct V { virtual void f(); };5struct A : virtual V {};6struct B : S, virtual V {};7struct T {};8 9T* test0() { return dynamic_cast<T*>((B*)0); }10// CHECK-LABEL: define dso_local noalias noundef ptr @"?test0@@YAPAUT@@XZ"()11// CHECK:   ret ptr null12 13T* test1(V* x) { return &dynamic_cast<T&>(*x); }14// CHECK-LABEL: define dso_local noundef ptr @"?test1@@YAPAUT@@PAUV@@@Z"(ptr noundef %x)15// CHECK:   [[CALL:%.*]] = tail call ptr @__RTDynamicCast(ptr %x, i32 0, ptr nonnull @"??_R0?AUV@@@8", ptr nonnull @"??_R0?AUT@@@8", i32 1)16// CHECK-NEXT:   ret ptr [[CALL]]17 18T* test2(A* x) { return &dynamic_cast<T&>(*x); }19// CHECK-LABEL: define dso_local noundef ptr @"?test2@@YAPAUT@@PAUA@@@Z"(ptr noundef %x)20// CHECK:        [[VBTBL:%.*]] = load ptr, ptr %x, align 421// CHECK-NEXT:   [[VBOFFP:%.*]] = getelementptr inbounds nuw i8, ptr [[VBTBL]], i32 422// CHECK-NEXT:   [[VBOFFS:%.*]] = load i32, ptr [[VBOFFP]], align 423// CHECK-NEXT:   [[ADJ:%.*]] = getelementptr inbounds i8, ptr %x, i32 [[VBOFFS]]24// CHECK-NEXT:   [[CALL:%.*]] = tail call ptr @__RTDynamicCast(ptr nonnull [[ADJ]], i32 [[VBOFFS]], ptr nonnull @"??_R0?AUA@@@8", ptr nonnull @"??_R0?AUT@@@8", i32 1)25// CHECK-NEXT:   ret ptr [[CALL]]26 27T* test3(B* x) { return &dynamic_cast<T&>(*x); }28// CHECK-LABEL: define dso_local noundef ptr @"?test3@@YAPAUT@@PAUB@@@Z"(ptr noundef %x)29// CHECK:        [[VBPTR:%.*]] = getelementptr inbounds nuw i8, ptr %x, i32 430// CHECK-NEXT:   [[VBTBL:%.*]] = load ptr, ptr [[VBPTR:%.*]], align 431// CHECK-NEXT:   [[VBOFFP:%.*]] = getelementptr inbounds nuw i8, ptr [[VBTBL]], i32 432// CHECK-NEXT:   [[VBOFFS:%.*]] = load i32, ptr [[VBOFFP]], align 433// CHECK-NEXT:   [[DELTA:%.*]] = add nsw i32 [[VBOFFS]], 434// CHECK-NEXT:   [[ADJ:%.*]] = getelementptr inbounds i8, ptr %x, i32 [[DELTA]]35// CHECK-NEXT:   [[CALL:%.*]] = tail call ptr @__RTDynamicCast(ptr [[ADJ]], i32 [[DELTA]], ptr nonnull @"??_R0?AUB@@@8", ptr nonnull @"??_R0?AUT@@@8", i32 1)36// CHECK-NEXT:   ret ptr [[CALL]]37 38T* test4(V* x) { return dynamic_cast<T*>(x); }39// CHECK-LABEL: define dso_local noundef ptr @"?test4@@YAPAUT@@PAUV@@@Z"(ptr noundef %x)40// CHECK:   [[CALL:%.*]] = tail call ptr @__RTDynamicCast(ptr %x, i32 0, ptr nonnull @"??_R0?AUV@@@8", ptr nonnull @"??_R0?AUT@@@8", i32 0)41// CHECK-NEXT:   ret ptr [[CALL]]42 43T* test5(A* x) { return dynamic_cast<T*>(x); }44// CHECK-LABEL: define dso_local noundef ptr @"?test5@@YAPAUT@@PAUA@@@Z"(ptr noundef %x)45// CHECK:        [[CHECK:%.*]] = icmp eq ptr %x, null46// CHECK-NEXT:   br i1 [[CHECK]]47// CHECK:        [[VBTBL:%.*]] = load ptr, ptr %x, align 448// CHECK-NEXT:   [[VBOFFP:%.*]] = getelementptr inbounds nuw i8, ptr [[VBTBL]], i32 449// CHECK-NEXT:   [[VBOFFS:%.*]] = load i32, ptr [[VBOFFP]], align 450// CHECK-NEXT:   [[ADJ:%.*]] = getelementptr inbounds i8, ptr %x, i32 [[VBOFFS]]51// CHECK-NEXT:   [[CALL:%.*]] = tail call ptr @__RTDynamicCast(ptr nonnull [[ADJ]], i32 [[VBOFFS]], ptr {{.*}}@"??_R0?AUA@@@8", ptr {{.*}}@"??_R0?AUT@@@8", i32 0)52// CHECK-NEXT:   br label53// CHECK:        [[RET:%.*]] = phi ptr54// CHECK-NEXT:   ret ptr [[RET]]55 56T* test6(B* x) { return dynamic_cast<T*>(x); }57// CHECK-LABEL: define dso_local noundef ptr @"?test6@@YAPAUT@@PAUB@@@Z"(ptr noundef %x)58// CHECK:        [[CHECK:%.*]] = icmp eq ptr %x, null59// CHECK-NEXT:   br i1 [[CHECK]]60// CHECK:        [[VBPTR:%.*]] = getelementptr inbounds nuw i8, ptr %x, i32 461// CHECK-NEXT:   [[VBTBL:%.*]] = load ptr, ptr [[VBPTR]], align 462// CHECK-NEXT:   [[VBOFFP:%.*]] = getelementptr inbounds nuw i8, ptr [[VBTBL]], i32 463// CHECK-NEXT:   [[VBOFFS:%.*]] = load i32, ptr [[VBOFFP]], align 464// CHECK-NEXT:   [[DELTA:%.*]] = add nsw i32 [[VBOFFS]], 465// CHECK-NEXT:   [[ADJ:%.*]] = getelementptr inbounds i8, ptr %x, i32 [[DELTA]]66// CHECK-NEXT:   [[CALL:%.*]] = tail call ptr @__RTDynamicCast(ptr nonnull [[ADJ]], i32 [[DELTA]], ptr {{.*}}@"??_R0?AUB@@@8", ptr {{.*}}@"??_R0?AUT@@@8", i32 0)67// CHECK-NEXT:   br label68// CHECK:        [[RET:%.*]] = phi ptr69// CHECK-NEXT:   ret ptr [[RET]]70 71void* test7(V* x) { return dynamic_cast<void*>(x); }72// CHECK-LABEL: define dso_local noundef ptr @"?test7@@YAPAXPAUV@@@Z"(ptr noundef %x)73// CHECK:   [[RET:%.*]] = tail call ptr @__RTCastToVoid(ptr %x)74// CHECK-NEXT:   ret ptr [[RET]]75 76void* test8(A* x) { return dynamic_cast<void*>(x); }77// CHECK-LABEL: define dso_local noundef ptr @"?test8@@YAPAXPAUA@@@Z"(ptr noundef %x)78// CHECK:        [[CHECK:%.*]] = icmp eq ptr %x, null79// CHECK-NEXT:   br i1 [[CHECK]]80// CHECK:        [[VBTBL:%.*]] = load ptr, ptr %x, align 481// CHECK-NEXT:   [[VBOFFP:%.*]] = getelementptr inbounds nuw i8, ptr [[VBTBL]], i32 482// CHECK-NEXT:   [[VBOFFS:%.*]] = load i32, ptr [[VBOFFP]], align 483// CHECK-NEXT:   [[ADJ:%.*]] = getelementptr inbounds i8, ptr %x, i32 [[VBOFFS]]84// CHECK-NEXT:   [[RES:%.*]] = tail call ptr @__RTCastToVoid(ptr nonnull [[ADJ]])85// CHECK-NEXT:   br label86// CHECK:        [[RET:%.*]] = phi ptr87// CHECK-NEXT:   ret ptr [[RET]]88 89void* test9(B* x) { return dynamic_cast<void*>(x); }90// CHECK-LABEL: define dso_local noundef ptr @"?test9@@YAPAXPAUB@@@Z"(ptr noundef %x)91// CHECK:        [[CHECK:%.*]] = icmp eq ptr %x, null92// CHECK-NEXT:   br i1 [[CHECK]]93// CHECK:        [[VBPTR:%.*]] = getelementptr inbounds nuw i8, ptr %x, i32 494// CHECK-NEXT:   [[VBTBL:%.*]] = load ptr, ptr [[VBPTR]], align 495// CHECK-NEXT:   [[VBOFFP:%.*]] = getelementptr inbounds nuw i8, ptr [[VBTBL]], i32 496// CHECK-NEXT:   [[VBOFFS:%.*]] = load i32, ptr [[VBOFFP]], align 497// CHECK-NEXT:   [[BASE:%.*]] = getelementptr i8, ptr %x, i32 [[VBOFFS]]98// CHECK-NEXT:   [[ADJ:%.*]] = getelementptr i8, ptr [[BASE]], i32 499// CHECK-NEXT:   [[CALL:%.*]] = tail call ptr @__RTCastToVoid(ptr [[ADJ]])100// CHECK-NEXT:   br label101// CHECK:        [[RET:%.*]] = phi ptr102// CHECK-NEXT:   ret ptr [[RET]]103 104namespace PR25606 {105struct Cleanup {106  ~Cleanup();107};108struct S1 { virtual ~S1(); };109struct S2 : virtual S1 {};110struct S3 : S2 {};111 112S3 *f(S2 &s) {113  Cleanup c;114  return dynamic_cast<S3 *>(&s);115}116// CHECK-LABEL: define dso_local noundef ptr @"?f@PR25606@@YAPAUS3@1@AAUS2@1@@Z"(117// CHECK:    [[CALL:%.*]] = invoke ptr @__RTDynamicCast118 119// CHECK:    call x86_thiscallcc void @"??1Cleanup@PR25606@@QAE@XZ"(120// CHECK:    ret ptr [[CALL]]121}122