2009-12-16 04:14:24 +08:00
|
|
|
// RUN: %clang_cc1 -emit-llvm %s -o - -triple i686-pc-linux-gnu | FileCheck %s
|
2014-01-15 03:35:09 +08:00
|
|
|
// RUN: %clang_cc1 -emit-llvm %s -o - -triple i686-pc-win32 | FileCheck -check-prefix MSVC %s
|
2009-10-07 06:43:30 +08:00
|
|
|
|
2009-11-28 11:31:34 +08:00
|
|
|
struct A { int a; virtual int aa(); };
|
|
|
|
struct B { int b; virtual int bb(); };
|
|
|
|
struct C : virtual A, virtual B { int c; virtual int aa(); virtual int bb(); };
|
|
|
|
struct AA { int a; virtual int aa(); };
|
|
|
|
struct BB { int b; virtual int bb(); };
|
|
|
|
struct CC : AA, BB { virtual int aa(); virtual int bb(); virtual int cc(); };
|
|
|
|
struct D : virtual C, virtual CC { int e; };
|
2009-10-07 06:43:30 +08:00
|
|
|
|
2009-11-28 11:31:34 +08:00
|
|
|
D* x;
|
|
|
|
|
|
|
|
A* a() { return x; }
|
2013-02-27 08:06:04 +08:00
|
|
|
// CHECK: @_Z1av() [[NUW:#[0-9]+]]
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK: [[VBASEOFFSETPTRA:%[a-zA-Z0-9\.]+]] = getelementptr i8, i8* {{.*}}, i64 -16
|
2009-11-28 11:31:34 +08:00
|
|
|
// CHECK: [[CASTVBASEOFFSETPTRA:%[a-zA-Z0-9\.]+]] = bitcast i8* [[VBASEOFFSETPTRA]] to i32*
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: load i32, i32* [[CASTVBASEOFFSETPTRA]]
|
2009-11-28 11:31:34 +08:00
|
|
|
// CHECK: }
|
|
|
|
|
2018-03-17 04:36:49 +08:00
|
|
|
// MSVC: @"?a@@YAPAUA@@XZ"() [[NUW:#[0-9]+]] {
|
2015-02-28 03:18:17 +08:00
|
|
|
// MSVC: %[[vbptr_off:.*]] = getelementptr inbounds i8, i8* {{.*}}, i32 0
|
2014-10-23 01:26:00 +08:00
|
|
|
// MSVC: %[[vbptr:.*]] = bitcast i8* %[[vbptr_off]] to i32**
|
2015-02-28 05:19:58 +08:00
|
|
|
// MSVC: %[[vbtable:.*]] = load i32*, i32** %[[vbptr]]
|
2015-02-28 03:18:17 +08:00
|
|
|
// MSVC: %[[entry:.*]] = getelementptr inbounds i32, i32* {{.*}}, i32 1
|
2015-02-28 05:19:58 +08:00
|
|
|
// MSVC: %[[offset:.*]] = load i32, i32* %[[entry]]
|
2013-05-30 02:02:47 +08:00
|
|
|
// MSVC: add nsw i32 0, %[[offset]]
|
|
|
|
// MSVC: }
|
|
|
|
|
2009-11-28 11:31:34 +08:00
|
|
|
B* b() { return x; }
|
2013-02-27 08:06:04 +08:00
|
|
|
// CHECK: @_Z1bv() [[NUW]]
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK: [[VBASEOFFSETPTRA:%[a-zA-Z0-9\.]+]] = getelementptr i8, i8* {{.*}}, i64 -20
|
2009-11-28 11:31:34 +08:00
|
|
|
// CHECK: [[CASTVBASEOFFSETPTRA:%[a-zA-Z0-9\.]+]] = bitcast i8* [[VBASEOFFSETPTRA]] to i32*
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: load i32, i32* [[CASTVBASEOFFSETPTRA]]
|
2009-11-28 11:31:34 +08:00
|
|
|
// CHECK: }
|
|
|
|
|
2013-05-30 02:02:47 +08:00
|
|
|
// Same as 'a' except we use a different vbtable offset.
|
2018-03-17 04:36:49 +08:00
|
|
|
// MSVC: @"?b@@YAPAUB@@XZ"() [[NUW:#[0-9]+]] {
|
2015-02-28 03:18:17 +08:00
|
|
|
// MSVC: %[[vbptr_off:.*]] = getelementptr inbounds i8, i8* {{.*}}, i32 0
|
2014-10-23 01:26:00 +08:00
|
|
|
// MSVC: %[[vbptr:.*]] = bitcast i8* %[[vbptr_off]] to i32**
|
2015-02-28 05:19:58 +08:00
|
|
|
// MSVC: %[[vbtable:.*]] = load i32*, i32** %[[vbptr]]
|
2015-02-28 03:18:17 +08:00
|
|
|
// MSVC: %[[entry:.*]] = getelementptr inbounds i32, i32* {{.*}}, i32 2
|
2015-02-28 05:19:58 +08:00
|
|
|
// MSVC: %[[offset:.*]] = load i32, i32* %[[entry]]
|
2013-05-30 02:02:47 +08:00
|
|
|
// MSVC: add nsw i32 0, %[[offset]]
|
|
|
|
// MSVC: }
|
|
|
|
|
|
|
|
|
2009-11-28 11:31:34 +08:00
|
|
|
BB* c() { return x; }
|
2013-02-27 08:06:04 +08:00
|
|
|
// CHECK: @_Z1cv() [[NUW]]
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK: [[VBASEOFFSETPTRC:%[a-zA-Z0-9\.]+]] = getelementptr i8, i8* {{.*}}, i64 -24
|
2009-11-28 11:31:34 +08:00
|
|
|
// CHECK: [[CASTVBASEOFFSETPTRC:%[a-zA-Z0-9\.]+]] = bitcast i8* [[VBASEOFFSETPTRC]] to i32*
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[VBASEOFFSETC:%[a-zA-Z0-9\.]+]] = load i32, i32* [[CASTVBASEOFFSETPTRC]]
|
2009-11-28 11:31:34 +08:00
|
|
|
// CHECK: add i32 [[VBASEOFFSETC]], 8
|
|
|
|
// CHECK: }
|
2013-02-20 15:22:19 +08:00
|
|
|
|
2013-05-30 02:02:47 +08:00
|
|
|
// Same as 'a' except we use a different vbtable offset.
|
2018-03-17 04:36:49 +08:00
|
|
|
// MSVC: @"?c@@YAPAUBB@@XZ"() [[NUW:#[0-9]+]] {
|
2015-02-28 03:18:17 +08:00
|
|
|
// MSVC: %[[vbptr_off:.*]] = getelementptr inbounds i8, i8* {{.*}}, i32 0
|
2014-10-23 01:26:00 +08:00
|
|
|
// MSVC: %[[vbptr:.*]] = bitcast i8* %[[vbptr_off]] to i32**
|
2015-02-28 05:19:58 +08:00
|
|
|
// MSVC: %[[vbtable:.*]] = load i32*, i32** %[[vbptr]]
|
2015-02-28 03:18:17 +08:00
|
|
|
// MSVC: %[[entry:.*]] = getelementptr inbounds i32, i32* {{.*}}, i32 4
|
2015-02-28 05:19:58 +08:00
|
|
|
// MSVC: %[[offset:.*]] = load i32, i32* %[[entry]]
|
2013-05-30 02:02:47 +08:00
|
|
|
// MSVC: add nsw i32 0, %[[offset]]
|
|
|
|
// MSVC: }
|
|
|
|
|
|
|
|
// Put the vbptr at a non-zero offset inside a non-virtual base.
|
|
|
|
struct E { int e; };
|
|
|
|
struct F : E, D { int f; };
|
|
|
|
|
|
|
|
F* y;
|
|
|
|
|
|
|
|
BB* d() { return y; }
|
|
|
|
|
|
|
|
// Same as 'c' except the vbptr offset is 4, changing the initial GEP and the
|
|
|
|
// final add.
|
2018-03-17 04:36:49 +08:00
|
|
|
// MSVC: @"?d@@YAPAUBB@@XZ"() [[NUW:#[0-9]+]] {
|
2015-02-28 03:18:17 +08:00
|
|
|
// MSVC: %[[vbptr_off:.*]] = getelementptr inbounds i8, i8* {{.*}}, i32 4
|
2014-10-23 01:26:00 +08:00
|
|
|
// MSVC: %[[vbptr:.*]] = bitcast i8* %[[vbptr_off]] to i32**
|
2015-02-28 05:19:58 +08:00
|
|
|
// MSVC: %[[vbtable:.*]] = load i32*, i32** %[[vbptr]]
|
2015-02-28 03:18:17 +08:00
|
|
|
// MSVC: %[[entry:.*]] = getelementptr inbounds i32, i32* {{.*}}, i32 4
|
2015-02-28 05:19:58 +08:00
|
|
|
// MSVC: %[[offset:.*]] = load i32, i32* %[[entry]]
|
2014-01-14 08:31:30 +08:00
|
|
|
// MSVC: add nsw i32 4, %[[offset]]
|
2013-05-30 02:02:47 +08:00
|
|
|
// MSVC: }
|
|
|
|
|
2021-07-09 23:58:48 +08:00
|
|
|
// CHECK: attributes [[NUW]] = { mustprogress noinline nounwind{{.*}} }
|