Fariborz Jahanian | af9b968 | 2010-09-17 15:51:28 +0000 | [diff] [blame] | 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 | |
John McCall | 56ca35d | 2011-02-17 10:25:35 +0000 | [diff] [blame] | 7 | void test0() { |
| 8 | // CHECK: call i32 (...)* @printf({{.*}}, i8* inttoptr (i64 3735928559 to i8*)) |
Fariborz Jahanian | af9b968 | 2010-09-17 15:51:28 +0000 | [diff] [blame] | 9 | printf("%p\n", (void *)0xdeadbeef ? : (void *)0xaaaaaa); |
Fariborz Jahanian | af9b968 | 2010-09-17 15:51:28 +0000 | [diff] [blame] | 10 | } |
Fariborz Jahanian | 1fb019b | 2010-09-18 19:38:38 +0000 | [diff] [blame] | 11 | |
| 12 | // rdar://8446940 |
| 13 | namespace radar8446940 { |
| 14 | extern "C" void abort(); |
| 15 | |
| 16 | int main () { |
| 17 | char x[1]; |
| 18 | char *y = x ? : 0; |
| 19 | |
| 20 | if (x != y) |
| 21 | abort(); |
| 22 | } |
| 23 | } |
Fariborz Jahanian | aa3b57e | 2010-09-20 23:50:22 +0000 | [diff] [blame] | 24 | |
| 25 | namespace radar8453812 { |
| 26 | extern "C" void abort(); |
| 27 | _Complex int getComplex(_Complex int val) { |
| 28 | static int count; |
| 29 | if (count++) |
| 30 | abort(); |
| 31 | return val; |
| 32 | } |
| 33 | |
| 34 | _Complex int cmplx() { |
| 35 | _Complex int cond; |
| 36 | _Complex int rhs; |
| 37 | |
| 38 | return getComplex(1+2i) ? : rhs; |
| 39 | } |
| 40 | |
Fariborz Jahanian | 0b78710 | 2010-09-21 18:32:21 +0000 | [diff] [blame] | 41 | // lvalue test |
| 42 | void foo (int& lv) { |
| 43 | ++lv; |
| 44 | } |
| 45 | |
| 46 | int global = 1; |
| 47 | |
| 48 | int &cond() { |
| 49 | static int count; |
| 50 | if (count++) |
| 51 | abort(); |
| 52 | return global; |
| 53 | } |
| 54 | |
| 55 | |
Fariborz Jahanian | aa3b57e | 2010-09-20 23:50:22 +0000 | [diff] [blame] | 56 | int main() { |
| 57 | cmplx(); |
Fariborz Jahanian | 0b78710 | 2010-09-21 18:32:21 +0000 | [diff] [blame] | 58 | int rhs = 10; |
| 59 | foo (cond()? : rhs); |
| 60 | return global-2; |
Fariborz Jahanian | aa3b57e | 2010-09-20 23:50:22 +0000 | [diff] [blame] | 61 | } |
| 62 | } |
John McCall | 7cc25fe | 2011-02-21 05:25:38 +0000 | [diff] [blame] | 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 | |
| 79 | B test0(B &x) { |
| 80 | // CHECK: define void @_ZN5test35test0ERNS_1BE( |
| 81 | // CHECK: [[X:%.*]] = alloca [[B:%.*]]*, |
| 82 | // CHECK-NEXT: store [[B]]* {{%.*}}, [[B]]** [[X]] |
| 83 | // CHECK-NEXT: [[T0:%.*]] = load [[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]]* [[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 | |
| 94 | B test1() { |
| 95 | // CHECK: define void @_ZN5test35test1Ev( |
| 96 | // CHECK: [[TEMP:%.*]] = alloca [[B]], |
| 97 | // CHECK-NEXT: call void @_ZN5test312test1_helperEv([[B]]* sret [[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]]* [[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 | |
| 111 | A test2(B &x) { |
| 112 | // CHECK: define void @_ZN5test35test2ERNS_1BE( |
| 113 | // CHECK: [[X:%.*]] = alloca [[B]]*, |
| 114 | // CHECK-NEXT: store [[B]]* {{%.*}}, [[B]]** [[X]] |
| 115 | // CHECK-NEXT: [[T0:%.*]] = load [[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 [[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 | |
| 126 | A test3() { |
| 127 | // CHECK: define void @_ZN5test35test3Ev( |
| 128 | // CHECK: [[TEMP:%.*]] = alloca [[B]], |
| 129 | // CHECK-NEXT: call void @_ZN5test312test3_helperEv([[B]]* sret [[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 [[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 | } |
Eli Friedman | 2c0c745 | 2012-01-25 05:04:17 +0000 | [diff] [blame] | 143 | |
| 144 | namespace test4 { |
| 145 | // Make sure this doesn't crash. |
| 146 | void f() { |
| 147 | const int a = 10, b = 20; |
| 148 | const int *c = &(a ?: b); |
| 149 | } |
| 150 | } |