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