David Blaikie | 1b76fbc | 2012-09-10 23:06:08 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -triple armv7-none-eabi -emit-llvm -o - | FileCheck %s |
Anders Carlsson | 8e7670d | 2009-10-12 19:41:04 +0000 | [diff] [blame] | 2 | |
| 3 | struct A { |
| 4 | virtual void f(); |
Anders Carlsson | cd0b32e | 2011-04-10 18:20:53 +0000 | [diff] [blame] | 5 | virtual void f_const() const; |
| 6 | |
Anders Carlsson | cf5deec | 2009-10-12 19:51:33 +0000 | [diff] [blame] | 7 | A h(); |
Anders Carlsson | 8e7670d | 2009-10-12 19:41:04 +0000 | [diff] [blame] | 8 | }; |
| 9 | |
Anders Carlsson | cf5deec | 2009-10-12 19:51:33 +0000 | [diff] [blame] | 10 | A g(); |
| 11 | |
Anders Carlsson | 8e7670d | 2009-10-12 19:41:04 +0000 | [diff] [blame] | 12 | void f(A a, A *ap, A& ar) { |
| 13 | // This should not be a virtual function call. |
| 14 | |
| 15 | // CHECK: call void @_ZN1A1fEv(%struct.A* %a) |
| 16 | a.f(); |
| 17 | |
| 18 | // CHECK: call void % |
| 19 | ap->f(); |
| 20 | |
| 21 | // CHECK: call void % |
| 22 | ar.f(); |
Anders Carlsson | 7636648 | 2009-10-12 19:45:47 +0000 | [diff] [blame] | 23 | |
| 24 | // CHECK: call void @_ZN1A1fEv |
| 25 | A().f(); |
Anders Carlsson | cf5deec | 2009-10-12 19:51:33 +0000 | [diff] [blame] | 26 | |
| 27 | // CHECK: call void @_ZN1A1fEv |
| 28 | g().f(); |
| 29 | |
| 30 | // CHECK: call void @_ZN1A1fEv |
| 31 | a.h().f(); |
Anders Carlsson | cd0b32e | 2011-04-10 18:20:53 +0000 | [diff] [blame] | 32 | |
| 33 | // CHECK: call void @_ZNK1A7f_constEv |
| 34 | a.f_const(); |
| 35 | |
| 36 | // CHECK: call void @_ZN1A1fEv |
| 37 | (a).f(); |
Anders Carlsson | 8e7670d | 2009-10-12 19:41:04 +0000 | [diff] [blame] | 38 | } |
Anders Carlsson | 4a0d832 | 2009-10-12 19:59:15 +0000 | [diff] [blame] | 39 | |
| 40 | struct B { |
| 41 | virtual void f(); |
| 42 | ~B(); |
| 43 | |
| 44 | B h(); |
| 45 | }; |
| 46 | |
| 47 | |
| 48 | void f() { |
| 49 | // CHECK: call void @_ZN1B1fEv |
| 50 | B().f(); |
| 51 | |
| 52 | // CHECK: call void @_ZN1B1fEv |
| 53 | B().h().f(); |
| 54 | } |
Anders Carlsson | cd0b32e | 2011-04-10 18:20:53 +0000 | [diff] [blame] | 55 | |
Rafael Espindola | 12582bd | 2012-06-26 19:18:25 +0000 | [diff] [blame] | 56 | namespace test2 { |
| 57 | struct foo { |
| 58 | virtual void f(); |
| 59 | virtual ~foo(); |
| 60 | }; |
| 61 | |
| 62 | struct bar : public foo { |
| 63 | virtual void f(); |
| 64 | virtual ~bar(); |
| 65 | }; |
| 66 | |
| 67 | void f(bar *b) { |
| 68 | // CHECK: call void @_ZN5test23foo1fEv |
David Blaikie | 1b76fbc | 2012-09-10 23:06:08 +0000 | [diff] [blame] | 69 | // CHECK: call %"struct.test2::foo"* @_ZN5test23fooD1Ev |
Rafael Espindola | 12582bd | 2012-06-26 19:18:25 +0000 | [diff] [blame] | 70 | b->foo::f(); |
| 71 | b->foo::~foo(); |
| 72 | } |
| 73 | } |
Rafael Espindola | 0713d99 | 2012-06-27 17:44:39 +0000 | [diff] [blame] | 74 | |
| 75 | namespace test3 { |
| 76 | // Test that we don't crash in this case. |
| 77 | struct B { |
| 78 | }; |
| 79 | struct D : public B { |
| 80 | }; |
| 81 | void f(D d) { |
| 82 | // CHECK: define void @_ZN5test31fENS_1DE |
| 83 | d.B::~B(); |
| 84 | } |
| 85 | } |
Richard Smith | ac45293 | 2012-08-15 22:59:28 +0000 | [diff] [blame] | 86 | |
| 87 | namespace test4 { |
| 88 | struct Animal { |
| 89 | virtual void eat(); |
| 90 | }; |
| 91 | struct Fish : Animal { |
| 92 | virtual void eat(); |
| 93 | }; |
| 94 | struct Wrapper { |
| 95 | Fish fish; |
| 96 | }; |
| 97 | extern Wrapper *p; |
| 98 | void test() { |
| 99 | // CHECK: call void @_ZN5test44Fish3eatEv |
| 100 | p->fish.eat(); |
| 101 | } |
| 102 | } |