1 // RUN: %clang_cc1 -fno-rtti %s -emit-llvm -o %t -triple=i386-pc-win32 -fdump-vtable-layouts 2>&1 | FileCheck --check-prefix=VFTABLES %s 2 // RUN: FileCheck --check-prefix=GLOBALS %s < %t 3 // RUN: FileCheck --check-prefix=CODEGEN %s < %t 4 5 namespace test1 { 6 7 // Some covariant types. 8 struct A { int a; }; 9 struct B { int b; }; 10 struct C : A, B { int c; }; 11 struct D : C { int d; }; 12 struct E : D { int e; }; 13 14 // One base class and two overrides, all with covariant return types. 15 struct H { virtual B *foo(); }; 16 struct I : H { virtual C *foo(); }; 17 struct J : I { virtual D *foo(); J(); }; 18 struct K : J { virtual E *foo(); K(); }; 19 20 J::J() {} 21 22 // VFTABLES-LABEL: VFTable for 'test1::H' in 'test1::I' in 'test1::J' (3 entries). 23 // VFTABLES-NEXT: 0 | test1::D *test1::J::foo() 24 // VFTABLES-NEXT: [return adjustment (to type 'struct test1::B *'): 4 non-virtual] 25 // VFTABLES-NEXT: 1 | test1::D *test1::J::foo() 26 // VFTABLES-NEXT: [return adjustment (to type 'struct test1::C *'): 0 non-virtual] 27 // VFTABLES-NEXT: 2 | test1::D *test1::J::foo() 28 29 // GLOBALS-LABEL: @"\01??_7J@test1@@6B@" = linkonce_odr unnamed_addr constant [3 x i8*] 30 // GLOBALS: @"\01?foo@J@test1@@QAEPAUB@2@XZ" 31 // GLOBALS: @"\01?foo@J@test1@@QAEPAUC@2@XZ" 32 // GLOBALS: @"\01?foo@J@test1@@UAEPAUD@2@XZ" 33 34 K::K() {} 35 36 // VFTABLES-LABEL: VFTable for 'test1::H' in 'test1::I' in 'test1::J' in 'test1::K' (4 entries). 37 // VFTABLES-NEXT: 0 | test1::E *test1::K::foo() 38 // VFTABLES-NEXT: [return adjustment (to type 'struct test1::B *'): 4 non-virtual] 39 // VFTABLES-NEXT: 1 | test1::E *test1::K::foo() 40 // VFTABLES-NEXT: [return adjustment (to type 'struct test1::C *'): 0 non-virtual] 41 // VFTABLES-NEXT: 2 | test1::E *test1::K::foo() 42 // VFTABLES-NEXT: [return adjustment (to type 'struct test1::D *'): 0 non-virtual] 43 // VFTABLES-NEXT: 3 | test1::E *test1::K::foo() 44 45 // Only B to C requires adjustment, but we get 3 thunks in K's vftable, two of 46 // which are trivial. 47 // GLOBALS-LABEL: @"\01??_7K@test1@@6B@" = linkonce_odr unnamed_addr constant [4 x i8*] 48 // GLOBALS: @"\01?foo@K@test1@@QAEPAUB@2@XZ" 49 // GLOBALS: @"\01?foo@K@test1@@QAEPAUC@2@XZ" 50 // GLOBALS: @"\01?foo@K@test1@@QAEPAUD@2@XZ" 51 // GLOBALS: @"\01?foo@K@test1@@UAEPAUE@2@XZ" 52 53 // This thunk has a return adjustment. 54 // CODEGEN-LABEL: define {{.*}} @"\01?foo@K@test1@@QAEPAUB@2@XZ" 55 // CODEGEN: call {{.*}} @"\01?foo@K@test1@@UAEPAUE@2@XZ" 56 // CODEGEN: icmp {{.*}}, null 57 // CODEGEN: getelementptr 58 // CODEGEN: ret 59 60 // These two don't. 61 // CODEGEN-LABEL: define {{.*}} @"\01?foo@K@test1@@QAEPAUC@2@XZ" 62 // CODEGEN: call {{.*}} @"\01?foo@K@test1@@UAEPAUE@2@XZ" 63 // CODEGEN-NEXT: ret 64 65 // CODEGEN-LABEL: define {{.*}} @"\01?foo@K@test1@@QAEPAUD@2@XZ" 66 // CODEGEN: call {{.*}} @"\01?foo@K@test1@@UAEPAUE@2@XZ" 67 // CODEGEN-NEXT: ret 68 69 } 70 71 namespace test2 { 72 73 // Covariant types. D* is not trivially convertible to C*. 74 struct A { int a; }; 75 struct B { int b; }; 76 struct C : B { int c; }; 77 struct D : A, C { int d; }; 78 struct E : D { int e; }; 79 80 // J's foo will require an adjusting thunk, and K will require a trivial thunk. 81 struct H { virtual B *foo(); }; 82 struct I : H { virtual C *foo(); }; 83 struct J : I { virtual D *foo(); J(); }; 84 struct K : J { virtual E *foo(); K(); }; 85 86 J::J() {} 87 88 // VFTABLES-LABEL: VFTable for 'test2::H' in 'test2::I' in 'test2::J' (2 entries). 89 // VFTABLES-NEXT: 0 | test2::D *test2::J::foo() 90 // VFTABLES-NEXT: [return adjustment (to type 'struct test2::B *'): 4 non-virtual] 91 // VFTABLES-NEXT: 1 | test2::D *test2::J::foo() 92 93 // GLOBALS-LABEL: @"\01??_7J@test2@@6B@" = linkonce_odr unnamed_addr constant [2 x i8*] 94 95 K::K() {} 96 97 // VFTABLES-LABEL: VFTable for 'test2::H' in 'test2::I' in 'test2::J' in 'test2::K' (3 entries). 98 // VFTABLES-NEXT: 0 | test2::E *test2::K::foo() 99 // VFTABLES-NEXT: [return adjustment (to type 'struct test2::B *'): 4 non-virtual] 100 // VFTABLES-NEXT: 1 | test2::E *test2::K::foo() 101 // VFTABLES-NEXT: [return adjustment (to type 'struct test2::D *'): 0 non-virtual] 102 // VFTABLES-NEXT: 2 | test2::E *test2::K::foo() 103 104 // GLOBALS-LABEL: @"\01??_7K@test2@@6B@" = linkonce_odr unnamed_addr constant [3 x i8*] 105 106 } 107