[InstCombine] Preserve NSW flags for `lshr (mul nuw X, C1), C2 -> mul nuw nsw X,...
[llvm-project.git] / clang / test / CodeGenCXX / throw-expressions.cpp
blob807c460d3ec6caca66dd5f5207c69c3931ebe450
1 // RUN: %clang_cc1 -fcxx-exceptions -fexceptions -Wno-unreachable-code -Werror -triple x86_64-linux-gnu -emit-llvm -o - %s | FileCheck %s
3 int val = 42;
4 int& test1() {
5 return throw val, val;
8 int test2() {
9 return val ? throw val : val;
12 void test3() {
13 throw false;
16 // PR10582
17 int test4() {
18 return 1 ? throw val : val;
21 // PR15923
22 int test5(bool x, bool y, int z) {
23 return (x ? throw 1 : y) ? z : throw 2;
25 // CHECK-LABEL: define{{.*}} i32 @_Z5test5bbi(
26 // CHECK: br i1
28 // x.true:
29 // CHECK: call void @__cxa_throw(
30 // CHECK-NEXT: unreachable
32 // x.false:
33 // CHECK: br i1
35 // y.true:
36 // CHECK: load i32, ptr
37 // CHECK: br label
39 // y.false:
40 // CHECK: call void @__cxa_throw(
41 // CHECK-NEXT: unreachable
43 // end:
44 // CHECK: ret i32
46 int test6(bool x, bool y, int z) {
47 return (x ? throw 1 : y) ? z : (throw 2);
49 // CHECK-LABEL: define{{.*}} i32 @_Z5test6bbi(
50 // CHECK: br i1
52 // x.true:
53 // CHECK: call void @__cxa_throw(
54 // CHECK-NEXT: unreachable
56 // x.false:
57 // CHECK: br i1
59 // y.true:
60 // CHECK: load i32, ptr
61 // CHECK: br label
63 // y.false:
64 // CHECK: call void @__cxa_throw(
65 // CHECK-NEXT: unreachable
67 // end:
68 // CHECK: ret i32
70 namespace DR1560 {
71 struct A {
72 ~A();
74 extern bool b;
75 A get();
76 // CHECK-LABEL: @_ZN6DR15601bE
77 const A &r = b ? get() : throw 0;
78 // CHECK-NOT: call {{.*}}@_ZN6DR15601AD1Ev
79 // CHECK: call {{.*}} @__cxa_atexit(ptr @_ZN6DR15601AD1Ev, ptr @_ZGRN6DR15601rE
80 // CHECK-NOT: call {{.*}}@_ZN6DR15601AD1Ev
82 // PR28184
83 void conditional_throw() {
84 int a;
85 (true ? throw 0 : a) = 0; // CHECK: call void @__cxa_throw({{.*}})
89 // CHECK-LABEL: define{{.*}} void @_Z5test7b(
90 void test7(bool cond) {
91 // CHECK: br i1
93 // x.true:
94 // CHECK: call void @__cxa_throw(
95 // CHECK-NEXT: unreachable
97 // x.false:
98 // CHECK: br label
100 // end:
101 // CHECK: ret void
102 cond ? throw test7 : val;
105 // CHECK-LABEL: define{{.*}} nonnull align 4 dereferenceable(4) ptr @_Z5test8b(
106 int &test8(bool cond) {
107 // CHECK: br i1
109 // x.true:
110 // CHECK: br label
112 // x.false:
113 // CHECK: call void @__cxa_throw(
114 // CHECK-NEXT: unreachable
116 // end:
117 // CHECK: ret ptr @val
118 return cond ? val : ((throw "foo"));