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