2010-09-17 23:51:28 +08:00
|
|
|
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s
|
|
|
|
// rdar: // 8353567
|
|
|
|
// pr7726
|
|
|
|
|
|
|
|
extern "C" int printf(...);
|
|
|
|
|
2011-02-17 18:25:35 +08:00
|
|
|
void test0() {
|
2015-04-17 07:25:00 +08:00
|
|
|
// CHECK: call i32 (...) @printf({{.*}}, i8* inttoptr (i64 3735928559 to i8*))
|
2010-09-17 23:51:28 +08:00
|
|
|
printf("%p\n", (void *)0xdeadbeef ? : (void *)0xaaaaaa);
|
|
|
|
}
|
2010-09-19 03:38:38 +08:00
|
|
|
|
|
|
|
// rdar://8446940
|
|
|
|
namespace radar8446940 {
|
|
|
|
extern "C" void abort();
|
|
|
|
|
|
|
|
int main () {
|
|
|
|
char x[1];
|
|
|
|
char *y = x ? : 0;
|
|
|
|
|
|
|
|
if (x != y)
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
}
|
2010-09-21 07:50:22 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-09-22 02:32:21 +08:00
|
|
|
// lvalue test
|
|
|
|
void foo (int& lv) {
|
|
|
|
++lv;
|
|
|
|
}
|
|
|
|
|
|
|
|
int global = 1;
|
|
|
|
|
|
|
|
int &cond() {
|
|
|
|
static int count;
|
|
|
|
if (count++)
|
|
|
|
abort();
|
|
|
|
return global;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-21 07:50:22 +08:00
|
|
|
int main() {
|
|
|
|
cmplx();
|
2010-09-22 02:32:21 +08:00
|
|
|
int rhs = 10;
|
|
|
|
foo (cond()? : rhs);
|
|
|
|
return global-2;
|
2010-09-21 07:50:22 +08:00
|
|
|
}
|
|
|
|
}
|
2011-02-21 13:25:38 +08:00
|
|
|
|
|
|
|
namespace test3 {
|
|
|
|
struct A {
|
|
|
|
A();
|
|
|
|
A(const A&);
|
|
|
|
~A();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct B {
|
|
|
|
B();
|
|
|
|
B(const B&);
|
|
|
|
~B();
|
|
|
|
operator bool();
|
|
|
|
operator A();
|
|
|
|
};
|
|
|
|
|
|
|
|
B test0(B &x) {
|
2020-02-04 02:09:39 +08:00
|
|
|
// CHECK-LABEL: define void @_ZN5test35test0ERNS_1BE(
|
2011-02-21 13:25:38 +08:00
|
|
|
// CHECK: [[X:%.*]] = alloca [[B:%.*]]*,
|
2019-06-21 01:15:21 +08:00
|
|
|
// CHECK: store [[B]]* {{%.*}}, [[B]]** [[X]]
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[T0:%.*]] = load [[B]]*, [[B]]** [[X]]
|
2020-11-17 07:04:55 +08:00
|
|
|
// CHECK-NEXT: [[BOOL:%.*]] = call zeroext i1 @_ZN5test31BcvbEv([[B]]* {{[^,]*}} [[T0]])
|
2011-02-21 13:25:38 +08:00
|
|
|
// CHECK-NEXT: br i1 [[BOOL]]
|
2020-11-17 07:04:55 +08:00
|
|
|
// CHECK: call void @_ZN5test31BC1ERKS0_([[B]]* {{[^,]*}} [[RESULT:%.*]], [[B]]* nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) [[T0]])
|
2011-02-21 13:25:38 +08:00
|
|
|
// CHECK-NEXT: br label
|
2020-11-17 07:04:55 +08:00
|
|
|
// CHECK: call void @_ZN5test31BC1Ev([[B]]* {{[^,]*}} [[RESULT]])
|
2011-02-21 13:25:38 +08:00
|
|
|
// CHECK-NEXT: br label
|
|
|
|
// CHECK: ret void
|
|
|
|
return x ?: B();
|
|
|
|
}
|
|
|
|
|
|
|
|
B test1() {
|
2020-02-04 02:09:39 +08:00
|
|
|
// CHECK-LABEL: define void @_ZN5test35test1Ev(
|
2011-02-21 13:25:38 +08:00
|
|
|
// CHECK: [[TEMP:%.*]] = alloca [[B]],
|
2020-09-29 21:33:55 +08:00
|
|
|
// CHECK: call void @_ZN5test312test1_helperEv([[B]]* sret([[B]]) align 1 [[TEMP]])
|
2020-11-17 07:04:55 +08:00
|
|
|
// CHECK-NEXT: [[BOOL:%.*]] = call zeroext i1 @_ZN5test31BcvbEv([[B]]* {{[^,]*}} [[TEMP]])
|
2011-02-21 13:25:38 +08:00
|
|
|
// CHECK-NEXT: br i1 [[BOOL]]
|
2020-11-17 07:04:55 +08:00
|
|
|
// CHECK: call void @_ZN5test31BC1ERKS0_([[B]]* {{[^,]*}} [[RESULT:%.*]], [[B]]* nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) [[TEMP]])
|
2011-02-21 13:25:38 +08:00
|
|
|
// CHECK-NEXT: br label
|
2020-11-17 07:04:55 +08:00
|
|
|
// CHECK: call void @_ZN5test31BC1Ev([[B]]* {{[^,]*}} [[RESULT]])
|
2011-02-21 13:25:38 +08:00
|
|
|
// CHECK-NEXT: br label
|
2020-11-17 07:04:55 +08:00
|
|
|
// CHECK: call void @_ZN5test31BD1Ev([[B]]* {{[^,]*}} [[TEMP]])
|
2011-02-21 13:25:38 +08:00
|
|
|
// CHECK-NEXT: ret void
|
|
|
|
extern B test1_helper();
|
|
|
|
return test1_helper() ?: B();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
A test2(B &x) {
|
2020-02-04 02:09:39 +08:00
|
|
|
// CHECK-LABEL: define void @_ZN5test35test2ERNS_1BE(
|
2011-02-21 13:25:38 +08:00
|
|
|
// CHECK: [[X:%.*]] = alloca [[B]]*,
|
2019-06-21 01:15:21 +08:00
|
|
|
// CHECK: store [[B]]* {{%.*}}, [[B]]** [[X]]
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[T0:%.*]] = load [[B]]*, [[B]]** [[X]]
|
2020-11-17 07:04:55 +08:00
|
|
|
// CHECK-NEXT: [[BOOL:%.*]] = call zeroext i1 @_ZN5test31BcvbEv([[B]]* {{[^,]*}} [[T0]])
|
2011-02-21 13:25:38 +08:00
|
|
|
// CHECK-NEXT: br i1 [[BOOL]]
|
2020-11-17 07:04:55 +08:00
|
|
|
// CHECK: call void @_ZN5test31BcvNS_1AEEv([[A:%.*]]* sret([[A]]) align 1 [[RESULT:%.*]], [[B]]* {{[^,]*}} [[T0]])
|
2011-02-21 13:25:38 +08:00
|
|
|
// CHECK-NEXT: br label
|
2020-11-17 07:04:55 +08:00
|
|
|
// CHECK: call void @_ZN5test31AC1Ev([[A]]* {{[^,]*}} [[RESULT]])
|
2011-02-21 13:25:38 +08:00
|
|
|
// CHECK-NEXT: br label
|
|
|
|
// CHECK: ret void
|
|
|
|
return x ?: A();
|
|
|
|
}
|
|
|
|
|
|
|
|
A test3() {
|
2020-02-04 02:09:39 +08:00
|
|
|
// CHECK-LABEL: define void @_ZN5test35test3Ev(
|
2011-02-21 13:25:38 +08:00
|
|
|
// CHECK: [[TEMP:%.*]] = alloca [[B]],
|
2020-09-29 21:33:55 +08:00
|
|
|
// CHECK: call void @_ZN5test312test3_helperEv([[B]]* sret([[B]]) align 1 [[TEMP]])
|
2020-11-17 07:04:55 +08:00
|
|
|
// CHECK-NEXT: [[BOOL:%.*]] = call zeroext i1 @_ZN5test31BcvbEv([[B]]* {{[^,]*}} [[TEMP]])
|
2011-02-21 13:25:38 +08:00
|
|
|
// CHECK-NEXT: br i1 [[BOOL]]
|
2020-11-17 07:04:55 +08:00
|
|
|
// CHECK: call void @_ZN5test31BcvNS_1AEEv([[A]]* sret([[A]]) align 1 [[RESULT:%.*]], [[B]]* {{[^,]*}} [[TEMP]])
|
2011-02-21 13:25:38 +08:00
|
|
|
// CHECK-NEXT: br label
|
2020-11-17 07:04:55 +08:00
|
|
|
// CHECK: call void @_ZN5test31AC1Ev([[A]]* {{[^,]*}} [[RESULT]])
|
2011-02-21 13:25:38 +08:00
|
|
|
// CHECK-NEXT: br label
|
2020-11-17 07:04:55 +08:00
|
|
|
// CHECK: call void @_ZN5test31BD1Ev([[B]]* {{[^,]*}} [[TEMP]])
|
2011-02-21 13:25:38 +08:00
|
|
|
// CHECK-NEXT: ret void
|
|
|
|
extern B test3_helper();
|
|
|
|
return test3_helper() ?: A();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2012-01-25 13:04:17 +08:00
|
|
|
|
|
|
|
namespace test4 {
|
|
|
|
// Make sure this doesn't crash.
|
|
|
|
void f() {
|
|
|
|
const int a = 10, b = 20;
|
|
|
|
const int *c = &(a ?: b);
|
|
|
|
}
|
|
|
|
}
|