2013-05-09 04:32:14 +08:00
|
|
|
// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -Wno-unreachable-code -Werror -triple x86_64-linux-gnu -emit-llvm -o - %s | FileCheck %s
|
2009-12-08 04:25:53 +08:00
|
|
|
|
|
|
|
int val = 42;
|
|
|
|
int& test1() {
|
|
|
|
return throw val, val;
|
|
|
|
}
|
|
|
|
|
|
|
|
int test2() {
|
|
|
|
return val ? throw val : val;
|
|
|
|
}
|
2010-10-29 16:14:02 +08:00
|
|
|
|
|
|
|
// rdar://problem/8608801
|
|
|
|
void test3() {
|
|
|
|
throw false;
|
|
|
|
}
|
2011-10-15 10:10:40 +08:00
|
|
|
|
|
|
|
// PR10582
|
|
|
|
int test4() {
|
|
|
|
return 1 ? throw val : val;
|
|
|
|
}
|
2013-05-08 05:53:22 +08:00
|
|
|
|
|
|
|
// PR15923
|
|
|
|
int test5(bool x, bool y, int z) {
|
|
|
|
return (x ? throw 1 : y) ? z : throw 2;
|
|
|
|
}
|
2020-12-31 16:27:11 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} i32 @_Z5test5bbi(
|
2013-05-08 05:53:22 +08:00
|
|
|
// CHECK: br i1
|
|
|
|
//
|
|
|
|
// x.true:
|
|
|
|
// CHECK: call void @__cxa_throw(
|
|
|
|
// CHECK-NEXT: unreachable
|
|
|
|
//
|
|
|
|
// x.false:
|
|
|
|
// CHECK: br i1
|
|
|
|
//
|
|
|
|
// y.true:
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: load i32, i32*
|
2013-05-08 05:53:22 +08:00
|
|
|
// CHECK: br label
|
|
|
|
//
|
|
|
|
// y.false:
|
|
|
|
// CHECK: call void @__cxa_throw(
|
|
|
|
// CHECK-NEXT: unreachable
|
|
|
|
//
|
|
|
|
// end:
|
|
|
|
// CHECK: ret i32
|
2013-06-02 16:40:42 +08:00
|
|
|
|
|
|
|
int test6(bool x, bool y, int z) {
|
|
|
|
return (x ? throw 1 : y) ? z : (throw 2);
|
|
|
|
}
|
2020-12-31 16:27:11 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} i32 @_Z5test6bbi(
|
2013-06-02 16:40:42 +08:00
|
|
|
// CHECK: br i1
|
|
|
|
//
|
|
|
|
// x.true:
|
|
|
|
// CHECK: call void @__cxa_throw(
|
|
|
|
// CHECK-NEXT: unreachable
|
|
|
|
//
|
|
|
|
// x.false:
|
|
|
|
// CHECK: br i1
|
|
|
|
//
|
|
|
|
// y.true:
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: load i32, i32*
|
2013-06-02 16:40:42 +08:00
|
|
|
// CHECK: br label
|
|
|
|
//
|
|
|
|
// y.false:
|
|
|
|
// CHECK: call void @__cxa_throw(
|
|
|
|
// CHECK-NEXT: unreachable
|
|
|
|
//
|
|
|
|
// end:
|
|
|
|
// CHECK: ret i32
|
2014-01-27 12:19:56 +08:00
|
|
|
|
|
|
|
namespace DR1560 {
|
|
|
|
struct A {
|
|
|
|
~A();
|
|
|
|
};
|
|
|
|
extern bool b;
|
|
|
|
A get();
|
|
|
|
// CHECK-LABEL: @_ZN6DR15601bE
|
|
|
|
const A &r = b ? get() : throw 0;
|
|
|
|
// CHECK-NOT: call {{.*}}@_ZN6DR15601AD1Ev
|
|
|
|
// CHECK: call {{.*}} @__cxa_atexit({{.*}} @_ZN6DR15601AD1Ev {{.*}} @_ZGRN6DR15601rE
|
|
|
|
// CHECK-NOT: call {{.*}}@_ZN6DR15601AD1Ev
|
2020-04-09 03:05:49 +08:00
|
|
|
|
|
|
|
// PR28184
|
|
|
|
void conditional_throw() {
|
|
|
|
int a;
|
|
|
|
(true ? throw 0 : a) = 0; // CHECK: call void @__cxa_throw({{.*}})
|
|
|
|
}
|
2014-01-27 12:19:56 +08:00
|
|
|
}
|
2014-06-21 02:43:47 +08:00
|
|
|
|
2020-12-31 16:27:11 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} void @_Z5test7b(
|
2014-06-21 02:43:47 +08:00
|
|
|
void test7(bool cond) {
|
|
|
|
// CHECK: br i1
|
|
|
|
//
|
|
|
|
// x.true:
|
|
|
|
// CHECK: call void @__cxa_throw(
|
|
|
|
// CHECK-NEXT: unreachable
|
|
|
|
//
|
|
|
|
// x.false:
|
|
|
|
// CHECK: br label
|
|
|
|
//
|
|
|
|
// end:
|
|
|
|
// CHECK: ret void
|
|
|
|
cond ? throw test7 : val;
|
|
|
|
}
|
|
|
|
|
2020-12-31 16:27:11 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} nonnull align 4 dereferenceable(4) i32* @_Z5test8b(
|
2014-06-21 02:43:47 +08:00
|
|
|
int &test8(bool cond) {
|
|
|
|
// CHECK: br i1
|
|
|
|
//
|
|
|
|
// x.true:
|
|
|
|
// CHECK: br label
|
|
|
|
//
|
|
|
|
// x.false:
|
|
|
|
// CHECK: call void @__cxa_throw(
|
|
|
|
// CHECK-NEXT: unreachable
|
|
|
|
//
|
|
|
|
// end:
|
|
|
|
// CHECK: ret i32* @val
|
|
|
|
return cond ? val : ((throw "foo"));
|
|
|
|
}
|