Debian Codegraph @

clang/test/AST/ByteCode/codegen.cpp

raw
1 // RUN: %clang_cc1 -triple x86_64-linux -emit-llvm -o - %s -fcxx-exceptions | FileCheck %s
2 // RUN: %clang_cc1 -triple x86_64-linux -emit-llvm -o - %s -fcxx-exceptions -fexperimental-new-constant-interpreter | FileCheck %s
3
4 #ifdef __SIZEOF_INT128__
5 // CHECK: @PR11705 = global i128 0
6 __int128_t PR11705 = (__int128_t)&PR11705;
7 #endif
8
9 int arr[2];
10 // CHECK: @pastEnd = constant ptr getelementptr (i8, ptr @arr, i64 8)
11 int &pastEnd = arr[2];
12
13 // CHECK: @F = constant ptr @arr, align 8
14 int &F = arr[0];
15
16 // CHECK: @_ZL1q = internal global [4294967294 x i8] zeroinitializer, align 16
17 static char q[-2U];
18 void useQ() { char *p = q + 1; }
19
20 struct S {
21 int a;
22 float c[3];
23 };
24
25 // CHECK: @s = global %struct.S zeroinitializer, align 4
26 S s;
27 // CHECK: @sp = constant ptr getelementptr (i8, ptr @s, i64 16), align 8
28 float &sp = s.c[3];
29
30 namespace NearlyZeroInit {
31 // CHECK: @_ZN14NearlyZeroInit1bE ={{.*}} global{{.*}} { i32, <{ i32, [2147483647 x i32] }> } { i32 1, <{ i32, [2147483647 x i32] }> <{ i32 2, [2147483647 x i32] zeroinitializer }> }{{.*}}
32 struct B { int n; int arr[1024 * 1024 * 1024 * 2u]; } b = {1, {2}};
33 }
34
35 namespace BaseClassOffsets {
36 struct A { int a; };
37 struct B { int b; };
38 struct C : A, B { int c; };
39
40 extern C c;
41 // CHECK: @_ZN16BaseClassOffsets1aE = global ptr @_ZN16BaseClassOffsets1cE, align 8
42 A* a = &c;
43 // CHECK: @_ZN16BaseClassOffsets1bE = global ptr getelementptr (i8, ptr @_ZN16BaseClassOffsets1cE, i64 4), align 8
44 B* b = &c;
45 }
46
47 namespace ExprBase {
48 struct A { int n; };
49 struct B { int n; };
50 struct C : A, B {};
51
52 extern const int &&t = ((B&&)C{}).n;
53 // CHECK: @_ZGRN8ExprBase1tE_ = internal global {{.*}} zeroinitializer,
54 // CHECK: @_ZN8ExprBase1tE = constant ptr {{.*}} @_ZGRN8ExprBase1tE_, {{.*}} 8
55 }
56
57 namespace reinterpretcast {
58 const unsigned int n = 1234;
59 extern const int &s = reinterpret_cast<const int&>(n);
60 // CHECK: @_ZN15reinterpretcastL1nE = internal constant i32 1234, align 4
61 // CHECK: @_ZN15reinterpretcast1sE = constant ptr @_ZN15reinterpretcastL1nE, align 8
62
63 void *f1(unsigned long l) {
64 return reinterpret_cast<void *>(l);
65 }
66 // CHECK: define {{.*}} ptr @_ZN15reinterpretcast2f1Em
67 // CHECK: inttoptr
68 }
69
70 namespace Bitfield {
71 struct S { int a : 5; ~S(); };
72 // CHECK: alloca
73 // CHECK: call {{.*}}memset
74 // CHECK: store i32 {{.*}}, ptr @_ZGRN8Bitfield1rE_
75 // CHECK: call void @_ZN8Bitfield1SD1
76 // CHECK: store ptr @_ZGRN8Bitfield1rE_, ptr @_ZN8Bitfield1rE, align 8
77 int &&r = S().a;
78 }
79
80 namespace Null {
81 decltype(nullptr) null();
82 // CHECK: call {{.*}} @_ZN4Null4nullEv(
83 int *p = null();
84 struct S {};
85 // CHECK: call {{.*}} @_ZN4Null4nullEv(
86 int S::*q = null();
87 }
88
89 struct A {
90 A();
91 ~A();
92 enum E { Foo };
93 };
94
95 A *g();
96
97 void f(A *a) {
98 A::E e1 = a->Foo;
99
100 // CHECK: call noundef ptr @_Z1gv()
101 A::E e2 = g()->Foo;
102 // CHECK: call void @_ZN1AC1Ev(
103 // CHECK: call void @_ZN1AD1Ev(
104 A::E e3 = A().Foo;
105 }
106
107 int notdead() {
108 auto l = [c=0]() mutable {
109 return c++ < 5 ? 10 : 12;
110 };
111 return l();
112 }
113 // CHECK: _ZZ7notdeadvEN3$_0clEv
114 // CHECK: ret i32 %cond
115
116 /// The conmparison of those two parameters should NOT work.
117 bool paramcmp(const int& lhs, const int& rhs) {
118 if (&lhs == &rhs)
119 return true;
120 return false;
121 }
122 // CHECK: _Z8paramcmpRKiS0_
123 // CHECK: if.then
124 // CHECK: if.end
125
126 /// &x == &OuterX should work and return 0.
127 class X {
128 public:
129 X();
130 X(const X&);
131 X(const volatile X &);
132 ~X();
133 };
134
135 extern X OuterX;
136
137 X test24() {
138 X x;
139 if (&x == &OuterX)
140 throw 0;
141 return x;
142 }
143 // CHECK: _Z6test24v
144 // CHECK-NOT: eh.resume
145 // CHECK-NOT: unreachable