xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/dynamic_cast-no-rtti.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -emit-llvm %s -verify -fno-rtti -triple %itanium_abi_triple -o - | FileCheck %s
2f4a2713aSLionel Sambuc // expected-no-diagnostics
3f4a2713aSLionel Sambuc 
4f4a2713aSLionel Sambuc struct A {
~AA5f4a2713aSLionel Sambuc   virtual ~A(){};
6f4a2713aSLionel Sambuc };
7f4a2713aSLionel Sambuc 
8f4a2713aSLionel Sambuc struct B : public A {
BB9f4a2713aSLionel Sambuc   B() : A() {}
10f4a2713aSLionel Sambuc };
11f4a2713aSLionel Sambuc 
12f4a2713aSLionel Sambuc // An upcast can be resolved statically and can be used with -fno-rtti, iff it
13f4a2713aSLionel Sambuc // does not use runtime support.
upcast(B * b)14f4a2713aSLionel Sambuc A *upcast(B *b) {
15f4a2713aSLionel Sambuc   return dynamic_cast<A *>(b);
16f4a2713aSLionel Sambuc // CHECK-LABEL: define %struct.A* @_Z6upcastP1B
17f4a2713aSLionel Sambuc // CHECK-NOT: call i8* @__dynamic_cast
18f4a2713aSLionel Sambuc }
19f4a2713aSLionel Sambuc 
20f4a2713aSLionel Sambuc // A NoOp dynamic_cast can be used with -fno-rtti iff it does not use
21f4a2713aSLionel Sambuc // runtime support.
samecast(B * b)22f4a2713aSLionel Sambuc B *samecast(B *b) {
23f4a2713aSLionel Sambuc   return dynamic_cast<B *>(b);
24f4a2713aSLionel Sambuc // CHECK-LABEL: define %struct.B* @_Z8samecastP1B
25f4a2713aSLionel Sambuc // CHECK-NOT: call i8* @__dynamic_cast
26f4a2713aSLionel Sambuc }
27