1 // RUN: %clang_cc1 -emit-llvm %s -o - -triple i686-pc-linux-gnu | FileCheck %s 2 // RUN: %clang_cc1 -cxx-abi microsoft -emit-llvm %s -o - -triple i686-pc-win32 | FileCheck -check-prefix MSVC %s 3 4 struct A { int a; virtual int aa(); }; 5 struct B { int b; virtual int bb(); }; 6 struct C : virtual A, virtual B { int c; virtual int aa(); virtual int bb(); }; 7 struct AA { int a; virtual int aa(); }; 8 struct BB { int b; virtual int bb(); }; 9 struct CC : AA, BB { virtual int aa(); virtual int bb(); virtual int cc(); }; 10 struct D : virtual C, virtual CC { int e; }; 11 12 D* x; 13 14 A* a() { return x; } 15 // CHECK: @_Z1av() [[NUW:#[0-9]+]] 16 // CHECK: [[VBASEOFFSETPTRA:%[a-zA-Z0-9\.]+]] = getelementptr i8* {{.*}}, i64 -16 17 // CHECK: [[CASTVBASEOFFSETPTRA:%[a-zA-Z0-9\.]+]] = bitcast i8* [[VBASEOFFSETPTRA]] to i32* 18 // CHECK: load i32* [[CASTVBASEOFFSETPTRA]] 19 // CHECK: } 20 21 // MSVC: @"\01?a@@YAPAUA@@XZ"() [[NUW:#[0-9]+]] { 22 // MSVC: %[[vbptr_off:.*]] = getelementptr inbounds i8* {{.*}}, i32 0 23 // MSVC: %[[vbptr:.*]] = bitcast i8* %[[vbptr_off]] to i8** 24 // MSVC: %[[vbtable:.*]] = load i8** %[[vbptr]] 25 // MSVC: %[[entry:.*]] = getelementptr inbounds i8* {{.*}}, i32 4 26 // MSVC: %[[entry_i32:.*]] = bitcast i8* %[[entry]] to i32* 27 // MSVC: %[[offset:.*]] = load i32* %[[entry_i32]] 28 // MSVC: add nsw i32 0, %[[offset]] 29 // MSVC: } 30 31 B* b() { return x; } 32 // CHECK: @_Z1bv() [[NUW]] 33 // CHECK: [[VBASEOFFSETPTRA:%[a-zA-Z0-9\.]+]] = getelementptr i8* {{.*}}, i64 -20 34 // CHECK: [[CASTVBASEOFFSETPTRA:%[a-zA-Z0-9\.]+]] = bitcast i8* [[VBASEOFFSETPTRA]] to i32* 35 // CHECK: load i32* [[CASTVBASEOFFSETPTRA]] 36 // CHECK: } 37 38 // Same as 'a' except we use a different vbtable offset. 39 // MSVC: @"\01?b@@YAPAUB@@XZ"() [[NUW:#[0-9]+]] { 40 // MSVC: %[[vbptr_off:.*]] = getelementptr inbounds i8* {{.*}}, i32 0 41 // MSVC: %[[vbptr:.*]] = bitcast i8* %[[vbptr_off]] to i8** 42 // MSVC: %[[vbtable:.*]] = load i8** %[[vbptr]] 43 // MSVC: %[[entry:.*]] = getelementptr inbounds i8* {{.*}}, i32 8 44 // MSVC: %[[entry_i32:.*]] = bitcast i8* %[[entry]] to i32* 45 // MSVC: %[[offset:.*]] = load i32* %[[entry_i32]] 46 // MSVC: add nsw i32 0, %[[offset]] 47 // MSVC: } 48 49 50 BB* c() { return x; } 51 // CHECK: @_Z1cv() [[NUW]] 52 // CHECK: [[VBASEOFFSETPTRC:%[a-zA-Z0-9\.]+]] = getelementptr i8* {{.*}}, i64 -24 53 // CHECK: [[CASTVBASEOFFSETPTRC:%[a-zA-Z0-9\.]+]] = bitcast i8* [[VBASEOFFSETPTRC]] to i32* 54 // CHECK: [[VBASEOFFSETC:%[a-zA-Z0-9\.]+]] = load i32* [[CASTVBASEOFFSETPTRC]] 55 // CHECK: add i32 [[VBASEOFFSETC]], 8 56 // CHECK: } 57 58 // Same as 'a' except we use a different vbtable offset. 59 // MSVC: @"\01?c@@YAPAUBB@@XZ"() [[NUW:#[0-9]+]] { 60 // MSVC: %[[vbptr_off:.*]] = getelementptr inbounds i8* {{.*}}, i32 0 61 // MSVC: %[[vbptr:.*]] = bitcast i8* %[[vbptr_off]] to i8** 62 // MSVC: %[[vbtable:.*]] = load i8** %[[vbptr]] 63 // MSVC: %[[entry:.*]] = getelementptr inbounds i8* {{.*}}, i32 16 64 // MSVC: %[[entry_i32:.*]] = bitcast i8* %[[entry]] to i32* 65 // MSVC: %[[offset:.*]] = load i32* %[[entry_i32]] 66 // MSVC: add nsw i32 0, %[[offset]] 67 // MSVC: } 68 69 // Put the vbptr at a non-zero offset inside a non-virtual base. 70 struct E { int e; }; 71 struct F : E, D { int f; }; 72 73 F* y; 74 75 BB* d() { return y; } 76 77 // Same as 'c' except the vbptr offset is 4, changing the initial GEP and the 78 // final add. 79 // MSVC: @"\01?d@@YAPAUBB@@XZ"() [[NUW:#[0-9]+]] { 80 // MSVC: %[[vbptr_off:.*]] = getelementptr inbounds i8* {{.*}}, i32 4 81 // MSVC: %[[vbptr:.*]] = bitcast i8* %[[vbptr_off]] to i8** 82 // MSVC: %[[vbtable:.*]] = load i8** %[[vbptr]] 83 // MSVC: %[[entry:.*]] = getelementptr inbounds i8* {{.*}}, i32 16 84 // MSVC: %[[entry_i32:.*]] = bitcast i8* %[[entry]] to i32* 85 // MSVC: %[[offset:.*]] = load i32* %[[entry_i32]] 86 // MSVC: add nsw i32 4, %[[offset]] 87 // MSVC: } 88 89 // CHECK: attributes [[NUW]] = { nounwind{{.*}} } 90