1f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -emit-llvm -o %t 2f4a2713aSLionel Sambuc // RUN: FileCheck --check-prefix=CHECK-TEST1 %s < %t 3f4a2713aSLionel Sambuc // RUN: FileCheck --check-prefix=CHECK-TEST2 %s < %t 4f4a2713aSLionel Sambuc // RUN: FileCheck --check-prefix=CHECK-TEST5 %s < %t 5f4a2713aSLionel Sambuc 6f4a2713aSLionel Sambuc #include <typeinfo> 7f4a2713aSLionel Sambuc 8f4a2713aSLionel Sambuc // CHECK-TEST1: @_ZTVN5Test11AE = external unnamed_addr constant 9f4a2713aSLionel Sambuc namespace Test1 { 10f4a2713aSLionel Sambuc 11f4a2713aSLionel Sambuc struct A { 12f4a2713aSLionel Sambuc A(); 13f4a2713aSLionel Sambuc virtual void f(); ~ATest1::A14f4a2713aSLionel Sambuc virtual ~A() { } 15f4a2713aSLionel Sambuc }; 16f4a2713aSLionel Sambuc A()17f4a2713aSLionel SambucA::A() { } 18f4a2713aSLionel Sambuc f(A * a)19f4a2713aSLionel Sambucvoid f(A* a) { 20f4a2713aSLionel Sambuc a->f(); 21f4a2713aSLionel Sambuc }; 22f4a2713aSLionel Sambuc 23f4a2713aSLionel Sambuc // CHECK-LABEL: define void @_ZN5Test11gEv 24f4a2713aSLionel Sambuc // CHECK: call void @_ZN5Test11A1fEv g()25f4a2713aSLionel Sambucvoid g() { 26f4a2713aSLionel Sambuc A a; 27f4a2713aSLionel Sambuc f(&a); 28f4a2713aSLionel Sambuc } 29f4a2713aSLionel Sambuc 30f4a2713aSLionel Sambuc } 31f4a2713aSLionel Sambuc 32f4a2713aSLionel Sambuc // Test2::A's key function (f) is defined in this translation unit, but when 33f4a2713aSLionel Sambuc // we're doing codegen for the typeid(A) call, we don't know that yet. 34f4a2713aSLionel Sambuc // This tests mainly that the typeinfo and typename constants have their linkage 35f4a2713aSLionel Sambuc // updated correctly. 36f4a2713aSLionel Sambuc 37f4a2713aSLionel Sambuc // CHECK-TEST2: @_ZTSN5Test21AE = constant 38*0a6a1f1dSLionel Sambuc // CHECK-TEST2: @_ZTIN5Test21AE = constant 39f4a2713aSLionel Sambuc // CHECK-TEST2: @_ZTVN5Test21AE = unnamed_addr constant 40f4a2713aSLionel Sambuc namespace Test2 { 41f4a2713aSLionel Sambuc struct A { 42f4a2713aSLionel Sambuc virtual void f(); 43f4a2713aSLionel Sambuc }; 44f4a2713aSLionel Sambuc g()45f4a2713aSLionel Sambuc const std::type_info &g() { 46f4a2713aSLionel Sambuc return typeid(A); 47f4a2713aSLionel Sambuc }; 48f4a2713aSLionel Sambuc f()49f4a2713aSLionel Sambuc void A::f() { } 50f4a2713aSLionel Sambuc } 51f4a2713aSLionel Sambuc 52f4a2713aSLionel Sambuc // Test that we don't assert on this test. 53f4a2713aSLionel Sambuc namespace Test3 { 54f4a2713aSLionel Sambuc 55f4a2713aSLionel Sambuc struct A { 56f4a2713aSLionel Sambuc virtual void f(); ~ATest3::A57f4a2713aSLionel Sambuc virtual ~A() { } 58f4a2713aSLionel Sambuc }; 59f4a2713aSLionel Sambuc 60f4a2713aSLionel Sambuc struct B : A { 61f4a2713aSLionel Sambuc B(); 62f4a2713aSLionel Sambuc virtual void f(); 63f4a2713aSLionel Sambuc }; 64f4a2713aSLionel Sambuc B()65f4a2713aSLionel SambucB::B() { } 66f4a2713aSLionel Sambuc g(A * a)67f4a2713aSLionel Sambucvoid g(A* a) { 68f4a2713aSLionel Sambuc a->f(); 69f4a2713aSLionel Sambuc }; 70f4a2713aSLionel Sambuc 71f4a2713aSLionel Sambuc } 72f4a2713aSLionel Sambuc 73f4a2713aSLionel Sambuc // PR9114, test that we don't try to instantiate RefPtr<Node>. 74f4a2713aSLionel Sambuc namespace Test4 { 75f4a2713aSLionel Sambuc 76f4a2713aSLionel Sambuc template <class T> struct RefPtr { 77f4a2713aSLionel Sambuc T* p; ~RefPtrTest4::RefPtr78f4a2713aSLionel Sambuc ~RefPtr() { 79f4a2713aSLionel Sambuc p->deref(); 80f4a2713aSLionel Sambuc } 81f4a2713aSLionel Sambuc }; 82f4a2713aSLionel Sambuc 83f4a2713aSLionel Sambuc struct A { 84f4a2713aSLionel Sambuc virtual ~A(); 85f4a2713aSLionel Sambuc }; 86f4a2713aSLionel Sambuc 87f4a2713aSLionel Sambuc struct Node; 88f4a2713aSLionel Sambuc 89f4a2713aSLionel Sambuc struct B : A { 90f4a2713aSLionel Sambuc virtual void deref(); 91f4a2713aSLionel Sambuc RefPtr<Node> m; 92f4a2713aSLionel Sambuc }; 93f4a2713aSLionel Sambuc f()94f4a2713aSLionel Sambucvoid f() { 95f4a2713aSLionel Sambuc RefPtr<B> b; 96f4a2713aSLionel Sambuc } 97f4a2713aSLionel Sambuc 98f4a2713aSLionel Sambuc } 99f4a2713aSLionel Sambuc 100f4a2713aSLionel Sambuc // PR9130, test that we emit a definition of A::f. 101f4a2713aSLionel Sambuc // CHECK-TEST5-LABEL: define linkonce_odr void @_ZN5Test51A1fEv 102f4a2713aSLionel Sambuc namespace Test5 { 103f4a2713aSLionel Sambuc 104f4a2713aSLionel Sambuc struct A { fTest5::A105f4a2713aSLionel Sambuc virtual void f() { } 106f4a2713aSLionel Sambuc }; 107f4a2713aSLionel Sambuc 108f4a2713aSLionel Sambuc struct B : A { 109f4a2713aSLionel Sambuc virtual ~B(); 110f4a2713aSLionel Sambuc }; 111f4a2713aSLionel Sambuc ~B()112f4a2713aSLionel SambucB::~B() { } 113f4a2713aSLionel Sambuc 114f4a2713aSLionel Sambuc } 115f4a2713aSLionel Sambuc 116f4a2713aSLionel Sambuc // Check that we don't assert on this test. 117f4a2713aSLionel Sambuc namespace Test6 { 118f4a2713aSLionel Sambuc 119f4a2713aSLionel Sambuc struct A { 120f4a2713aSLionel Sambuc virtual ~A(); 121f4a2713aSLionel Sambuc int a; 122f4a2713aSLionel Sambuc }; 123f4a2713aSLionel Sambuc 124f4a2713aSLionel Sambuc struct B { 125f4a2713aSLionel Sambuc virtual ~B(); 126f4a2713aSLionel Sambuc int b; 127f4a2713aSLionel Sambuc }; 128f4a2713aSLionel Sambuc 129f4a2713aSLionel Sambuc struct C : A, B { 130f4a2713aSLionel Sambuc C(); 131f4a2713aSLionel Sambuc }; 132f4a2713aSLionel Sambuc 133f4a2713aSLionel Sambuc struct D : C { 134f4a2713aSLionel Sambuc virtual void f(); 135f4a2713aSLionel Sambuc D(); 136f4a2713aSLionel Sambuc }; 137f4a2713aSLionel Sambuc D()138f4a2713aSLionel SambucD::D() { } 139f4a2713aSLionel Sambuc 140f4a2713aSLionel Sambuc } 141f4a2713aSLionel Sambuc 142f4a2713aSLionel Sambuc namespace Test7 { 143f4a2713aSLionel Sambuc 144f4a2713aSLionel Sambuc struct c1 {}; 145f4a2713aSLionel Sambuc struct c10 : c1{ 146f4a2713aSLionel Sambuc virtual void foo (); 147f4a2713aSLionel Sambuc }; 148f4a2713aSLionel Sambuc struct c11 : c10, c1{ 149f4a2713aSLionel Sambuc virtual void f6 (); 150f4a2713aSLionel Sambuc }; 151f4a2713aSLionel Sambuc struct c28 : virtual c11{ 152f4a2713aSLionel Sambuc void f6 (); 153f4a2713aSLionel Sambuc }; 154f4a2713aSLionel Sambuc } 155