conditional-gnu-ext.cpp
3.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s
// rdar: // 8353567
// pr7726
extern "C" int printf(...);
void test0() {
// CHECK: call i32 (...) @printf({{.*}}, i8* inttoptr (i64 3735928559 to i8*))
printf("%p\n", (void *)0xdeadbeef ? : (void *)0xaaaaaa);
}
// rdar://8446940
namespace radar8446940 {
extern "C" void abort();
int main () {
char x[1];
char *y = x ? : 0;
if (x != y)
abort();
}
}
namespace radar8453812 {
extern "C" void abort();
_Complex int getComplex(_Complex int val) {
static int count;
if (count++)
abort();
return val;
}
_Complex int cmplx() {
_Complex int cond;
_Complex int rhs;
return getComplex(1+2i) ? : rhs;
}
// lvalue test
void foo (int& lv) {
++lv;
}
int global = 1;
int &cond() {
static int count;
if (count++)
abort();
return global;
}
int main() {
cmplx();
int rhs = 10;
foo (cond()? : rhs);
return global-2;
}
}
namespace test3 {
struct A {
A();
A(const A&);
~A();
};
struct B {
B();
B(const B&);
~B();
operator bool();
operator A();
};
B test0(B &x) {
// CHECK-LABEL: define void @_ZN5test35test0ERNS_1BE(
// CHECK: [[X:%.*]] = alloca [[B:%.*]]*,
// CHECK: store [[B]]* {{%.*}}, [[B]]** [[X]]
// CHECK-NEXT: [[T0:%.*]] = load [[B]]*, [[B]]** [[X]]
// CHECK-NEXT: [[BOOL:%.*]] = call zeroext i1 @_ZN5test31BcvbEv([[B]]* [[T0]])
// CHECK-NEXT: br i1 [[BOOL]]
// CHECK: call void @_ZN5test31BC1ERKS0_([[B]]* [[RESULT:%.*]], [[B]]* dereferenceable({{[0-9]+}}) [[T0]])
// CHECK-NEXT: br label
// CHECK: call void @_ZN5test31BC1Ev([[B]]* [[RESULT]])
// CHECK-NEXT: br label
// CHECK: ret void
return x ?: B();
}
B test1() {
// CHECK-LABEL: define void @_ZN5test35test1Ev(
// CHECK: [[TEMP:%.*]] = alloca [[B]],
// CHECK: call void @_ZN5test312test1_helperEv([[B]]* sret [[TEMP]])
// CHECK-NEXT: [[BOOL:%.*]] = call zeroext i1 @_ZN5test31BcvbEv([[B]]* [[TEMP]])
// CHECK-NEXT: br i1 [[BOOL]]
// CHECK: call void @_ZN5test31BC1ERKS0_([[B]]* [[RESULT:%.*]], [[B]]* dereferenceable({{[0-9]+}}) [[TEMP]])
// CHECK-NEXT: br label
// CHECK: call void @_ZN5test31BC1Ev([[B]]* [[RESULT]])
// CHECK-NEXT: br label
// CHECK: call void @_ZN5test31BD1Ev([[B]]* [[TEMP]])
// CHECK-NEXT: ret void
extern B test1_helper();
return test1_helper() ?: B();
}
A test2(B &x) {
// CHECK-LABEL: define void @_ZN5test35test2ERNS_1BE(
// CHECK: [[X:%.*]] = alloca [[B]]*,
// CHECK: store [[B]]* {{%.*}}, [[B]]** [[X]]
// CHECK-NEXT: [[T0:%.*]] = load [[B]]*, [[B]]** [[X]]
// CHECK-NEXT: [[BOOL:%.*]] = call zeroext i1 @_ZN5test31BcvbEv([[B]]* [[T0]])
// CHECK-NEXT: br i1 [[BOOL]]
// CHECK: call void @_ZN5test31BcvNS_1AEEv([[A:%.*]]* sret [[RESULT:%.*]], [[B]]* [[T0]])
// CHECK-NEXT: br label
// CHECK: call void @_ZN5test31AC1Ev([[A]]* [[RESULT]])
// CHECK-NEXT: br label
// CHECK: ret void
return x ?: A();
}
A test3() {
// CHECK-LABEL: define void @_ZN5test35test3Ev(
// CHECK: [[TEMP:%.*]] = alloca [[B]],
// CHECK: call void @_ZN5test312test3_helperEv([[B]]* sret [[TEMP]])
// CHECK-NEXT: [[BOOL:%.*]] = call zeroext i1 @_ZN5test31BcvbEv([[B]]* [[TEMP]])
// CHECK-NEXT: br i1 [[BOOL]]
// CHECK: call void @_ZN5test31BcvNS_1AEEv([[A]]* sret [[RESULT:%.*]], [[B]]* [[TEMP]])
// CHECK-NEXT: br label
// CHECK: call void @_ZN5test31AC1Ev([[A]]* [[RESULT]])
// CHECK-NEXT: br label
// CHECK: call void @_ZN5test31BD1Ev([[B]]* [[TEMP]])
// CHECK-NEXT: ret void
extern B test3_helper();
return test3_helper() ?: A();
}
}
namespace test4 {
// Make sure this doesn't crash.
void f() {
const int a = 10, b = 20;
const int *c = &(a ?: b);
}
}