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