diff options
Diffstat (limited to 'clang/test/CIR/CodeGen/dynamic-cast-exact.cpp')
-rw-r--r-- | clang/test/CIR/CodeGen/dynamic-cast-exact.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/clang/test/CIR/CodeGen/dynamic-cast-exact.cpp b/clang/test/CIR/CodeGen/dynamic-cast-exact.cpp index e3b8533..9ddb68f 100644 --- a/clang/test/CIR/CodeGen/dynamic-cast-exact.cpp +++ b/clang/test/CIR/CodeGen/dynamic-cast-exact.cpp @@ -172,3 +172,37 @@ B *offset_cast(A *a) { // OGCG-NEXT: br label %[[LABEL_END]] // OGCG: [[LABEL_END]]: // OGCG-NEXT: phi ptr [ %[[RESULT]], %[[LABEL_NOTNULL]] ], [ null, %[[LABEL_NULL]] ] + +Derived *ptr_cast_always_fail(Base2 *ptr) { + return dynamic_cast<Derived *>(ptr); + } + +// CIR: cir.func {{.*}} @_Z20ptr_cast_always_failP5Base2 +// CIR: %{{.+}} = cir.load{{.*}} %{{.+}} : !cir.ptr<!cir.ptr<!rec_Base2>>, !cir.ptr<!rec_Base2> +// CIR-NEXT: %[[RESULT:.*]] = cir.const #cir.ptr<null> : !cir.ptr<!rec_Derived> +// CIR-NEXT: cir.store %[[RESULT]], %{{.*}} : !cir.ptr<!rec_Derived>, !cir.ptr<!cir.ptr<!rec_Derived>> + +// LLVM: define {{.*}} ptr @_Z20ptr_cast_always_failP5Base2 +// LLVM-NEXT: ret ptr null + +// OGCG: define {{.*}} ptr @_Z20ptr_cast_always_failP5Base2 +// OGCG-NEXT: entry: +// OGCG-NEXT: ret ptr null + +Derived &ref_cast_always_fail(Base2 &ref) { + return dynamic_cast<Derived &>(ref); +} + +// CIR: cir.func {{.*}} @_Z20ref_cast_always_failR5Base2 +// CIR: %{{.+}} = cir.load{{.*}} %{{.+}} : !cir.ptr<!cir.ptr<!rec_Base2>>, !cir.ptr<!rec_Base2> +// CIR-NEXT: cir.call @__cxa_bad_cast() : () -> () +// CIR-NEXT: cir.unreachable + +// LLVM: define {{.*}} ptr @_Z20ref_cast_always_failR5Base2 +// LLVM-NEXT: tail call void @__cxa_bad_cast() +// LLVM-NEXT: unreachable + +// OGCG: define {{.*}} ptr @_Z20ref_cast_always_failR5Base2 +// OGCG-NEXT: entry: +// OGCG-NEXT: tail call void @__cxa_bad_cast() +// OGCG-NEXT: unreachable |