Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -emit-llvm %s -o - -triple i686-pc-linux-gnu | FileCheck %s |
Reid Kleckner | b0f533e | 2013-05-29 18:02:47 +0000 | [diff] [blame^] | 2 | // RUN: %clang_cc1 -cxx-abi microsoft -emit-llvm %s -o - -triple i686-pc-win32 | FileCheck -check-prefix MSVC %s |
Anders Carlsson | 2f1986b | 2009-10-06 22:43:30 +0000 | [diff] [blame] | 3 | |
Eli Friedman | 8432f25 | 2009-11-28 03:31:34 +0000 | [diff] [blame] | 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; }; |
Anders Carlsson | 2f1986b | 2009-10-06 22:43:30 +0000 | [diff] [blame] | 11 | |
Eli Friedman | 8432f25 | 2009-11-28 03:31:34 +0000 | [diff] [blame] | 12 | D* x; |
| 13 | |
| 14 | A* a() { return x; } |
Bill Wendling | 8992457 | 2013-02-27 00:06:04 +0000 | [diff] [blame] | 15 | // CHECK: @_Z1av() [[NUW:#[0-9]+]] |
Eli Friedman | 8432f25 | 2009-11-28 03:31:34 +0000 | [diff] [blame] | 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 | |
Reid Kleckner | b0f533e | 2013-05-29 18:02:47 +0000 | [diff] [blame^] | 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 | |
Eli Friedman | 8432f25 | 2009-11-28 03:31:34 +0000 | [diff] [blame] | 31 | B* b() { return x; } |
Bill Wendling | 8992457 | 2013-02-27 00:06:04 +0000 | [diff] [blame] | 32 | // CHECK: @_Z1bv() [[NUW]] |
Eli Friedman | 8432f25 | 2009-11-28 03:31:34 +0000 | [diff] [blame] | 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 | |
Reid Kleckner | b0f533e | 2013-05-29 18:02:47 +0000 | [diff] [blame^] | 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 | |
Eli Friedman | 8432f25 | 2009-11-28 03:31:34 +0000 | [diff] [blame] | 50 | BB* c() { return x; } |
Bill Wendling | 8992457 | 2013-02-27 00:06:04 +0000 | [diff] [blame] | 51 | // CHECK: @_Z1cv() [[NUW]] |
Eli Friedman | 8432f25 | 2009-11-28 03:31:34 +0000 | [diff] [blame] | 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: } |
Bill Wendling | f7a9da0 | 2013-02-20 07:22:19 +0000 | [diff] [blame] | 57 | |
Reid Kleckner | b0f533e | 2013-05-29 18:02:47 +0000 | [diff] [blame^] | 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 | |
Bill Wendling | 8992457 | 2013-02-27 00:06:04 +0000 | [diff] [blame] | 89 | // CHECK: attributes [[NUW]] = { nounwind{{.*}} } |