Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGenCXX / virtual-base-cast.cpp
blob57388431e90076677bbd2bb62e61d08ed31af4f3
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
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; };
12 D* x;
14 A* a() { return x; }
15 // CHECK: @_Z1av() [[NUW:#[0-9]+]]
16 // CHECK: [[VBASEOFFSETPTRA:%[a-zA-Z0-9\.]+]] = getelementptr i8, ptr {{.*}}, i64 -16
17 // CHECK: load i32, ptr [[VBASEOFFSETPTRA]]
18 // CHECK: }
20 // MSVC: @"?a@@YAPAUA@@XZ"() [[NUW:#[0-9]+]] {
21 // MSVC: %[[vbptr_off:.*]] = getelementptr inbounds i8, ptr {{.*}}, i32 0
22 // MSVC: %[[vbtable:.*]] = load ptr, ptr %[[vbptr_off]]
23 // MSVC: %[[entry:.*]] = getelementptr inbounds i32, ptr {{.*}}, i32 1
24 // MSVC: %[[offset:.*]] = load i32, ptr %[[entry]]
25 // MSVC: add nsw i32 0, %[[offset]]
26 // MSVC: }
28 B* b() { return x; }
29 // CHECK: @_Z1bv() [[NUW]]
30 // CHECK: [[VBASEOFFSETPTRA:%[a-zA-Z0-9\.]+]] = getelementptr i8, ptr {{.*}}, i64 -20
31 // CHECK: load i32, ptr [[VBASEOFFSETPTRA]]
32 // CHECK: }
34 // Same as 'a' except we use a different vbtable offset.
35 // MSVC: @"?b@@YAPAUB@@XZ"() [[NUW:#[0-9]+]] {
36 // MSVC: %[[vbptr_off:.*]] = getelementptr inbounds i8, ptr {{.*}}, i32 0
37 // MSVC: %[[vbtable:.*]] = load ptr, ptr %[[vbptr_off]]
38 // MSVC: %[[entry:.*]] = getelementptr inbounds i32, ptr {{.*}}, i32 2
39 // MSVC: %[[offset:.*]] = load i32, ptr %[[entry]]
40 // MSVC: add nsw i32 0, %[[offset]]
41 // MSVC: }
44 BB* c() { return x; }
45 // CHECK: @_Z1cv() [[NUW]]
46 // CHECK: [[VBASEOFFSETPTRC:%[a-zA-Z0-9\.]+]] = getelementptr i8, ptr {{.*}}, i64 -24
47 // CHECK: [[VBASEOFFSETC:%[a-zA-Z0-9\.]+]] = load i32, ptr [[VBASEOFFSETPTRC]]
48 // CHECK: add i32 [[VBASEOFFSETC]], 8
49 // CHECK: }
51 // Same as 'a' except we use a different vbtable offset.
52 // MSVC: @"?c@@YAPAUBB@@XZ"() [[NUW:#[0-9]+]] {
53 // MSVC: %[[vbptr_off:.*]] = getelementptr inbounds i8, ptr {{.*}}, i32 0
54 // MSVC: %[[vbtable:.*]] = load ptr, ptr %[[vbptr_off]]
55 // MSVC: %[[entry:.*]] = getelementptr inbounds i32, ptr {{.*}}, i32 4
56 // MSVC: %[[offset:.*]] = load i32, ptr %[[entry]]
57 // MSVC: add nsw i32 0, %[[offset]]
58 // MSVC: }
60 // Put the vbptr at a non-zero offset inside a non-virtual base.
61 struct E { int e; };
62 struct F : E, D { int f; };
64 F* y;
66 BB* d() { return y; }
68 // Same as 'c' except the vbptr offset is 4, changing the initial GEP and the
69 // final add.
70 // MSVC: @"?d@@YAPAUBB@@XZ"() [[NUW:#[0-9]+]] {
71 // MSVC: %[[vbptr_off:.*]] = getelementptr inbounds i8, ptr {{.*}}, i32 4
72 // MSVC: %[[vbtable:.*]] = load ptr, ptr %[[vbptr_off]]
73 // MSVC: %[[entry:.*]] = getelementptr inbounds i32, ptr {{.*}}, i32 4
74 // MSVC: %[[offset:.*]] = load i32, ptr %[[entry]]
75 // MSVC: add nsw i32 4, %[[offset]]
76 // MSVC: }
78 // CHECK: attributes [[NUW]] = { mustprogress noinline nounwind{{.*}} }