blob: 40e68f672232d99746c22ed38ddea5a1b18a3748 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -emit-llvm %s -o - -triple i686-pc-linux-gnu | FileCheck %s
Reid Klecknerb0f533e2013-05-29 18:02:47 +00002// RUN: %clang_cc1 -cxx-abi microsoft -emit-llvm %s -o - -triple i686-pc-win32 | FileCheck -check-prefix MSVC %s
Anders Carlsson2f1986b2009-10-06 22:43:30 +00003
Eli Friedman8432f252009-11-28 03:31:34 +00004struct A { int a; virtual int aa(); };
5struct B { int b; virtual int bb(); };
6struct C : virtual A, virtual B { int c; virtual int aa(); virtual int bb(); };
7struct AA { int a; virtual int aa(); };
8struct BB { int b; virtual int bb(); };
9struct CC : AA, BB { virtual int aa(); virtual int bb(); virtual int cc(); };
10struct D : virtual C, virtual CC { int e; };
Anders Carlsson2f1986b2009-10-06 22:43:30 +000011
Eli Friedman8432f252009-11-28 03:31:34 +000012D* x;
13
14A* a() { return x; }
Bill Wendling89924572013-02-27 00:06:04 +000015// CHECK: @_Z1av() [[NUW:#[0-9]+]]
Eli Friedman8432f252009-11-28 03:31:34 +000016// 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 Klecknerb0f533e2013-05-29 18:02:47 +000021// 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 Friedman8432f252009-11-28 03:31:34 +000031B* b() { return x; }
Bill Wendling89924572013-02-27 00:06:04 +000032// CHECK: @_Z1bv() [[NUW]]
Eli Friedman8432f252009-11-28 03:31:34 +000033// 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 Klecknerb0f533e2013-05-29 18:02:47 +000038// 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 Friedman8432f252009-11-28 03:31:34 +000050BB* c() { return x; }
Bill Wendling89924572013-02-27 00:06:04 +000051// CHECK: @_Z1cv() [[NUW]]
Eli Friedman8432f252009-11-28 03:31:34 +000052// 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 Wendlingf7a9da02013-02-20 07:22:19 +000057
Reid Klecknerb0f533e2013-05-29 18:02:47 +000058// 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.
70struct E { int e; };
71struct F : E, D { int f; };
72
73F* y;
74
75BB* 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 Wendling89924572013-02-27 00:06:04 +000089// CHECK: attributes [[NUW]] = { nounwind{{.*}} }