Skip to content

Commit b58927e

Browse files
committed
[test] Test __attribute__((noreturn)), _Noreturn, and [[return]] with conditional operator
1 parent 2828a54 commit b58927e

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

clang/test/CodeGen/attr-noreturn.c

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// RUN: %clang_cc1 -S -emit-llvm %s -o - | FileCheck %s
1+
// RUN: %clang_cc1 -emit-llvm -std=c2x %s -o - | FileCheck %s
2+
// RUN: %clang_cc1 -triple %itanium_abi_triple -x c++ -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK-CXX
23

34
typedef void (*fptrs_t[4])(void);
45
fptrs_t p __attribute__((noreturn));
@@ -8,3 +9,47 @@ void __attribute__((noreturn)) f(void) {
89
}
910
// CHECK: call void
1011
// CHECK-NEXT: unreachable
12+
13+
// CHECK-LABEL: @test_conditional_gnu(
14+
// CHECK: %cond = select i1 %tobool, ptr @t1, ptr @t2
15+
// CHECK: call void %cond(
16+
// CHECK-NEXT: unreachable
17+
18+
// CHECK-CXX-LABEL: @_Z20test_conditional_gnui(
19+
// CHECK-CXX: %cond{{.*}} = phi ptr [ @_Z2t1i, %{{.*}} ], [ @_Z2t2i, %{{.*}} ]
20+
// CHECK-CXX: call void %cond{{.*}}(
21+
// CHECK-CXX: %cond{{.*}} = phi ptr [ @_Z2t1i, %{{.*}} ], [ @_Z2t1i, %{{.*}} ]
22+
// CHECK-CXX: call void %cond{{.*}}(
23+
// CHECK-CXX-NEXT: unreachable
24+
void t1(int) __attribute__((noreturn));
25+
void t2(int);
26+
__attribute__((noreturn)) void test_conditional_gnu(int a) {
27+
// The conditional operator isn't noreturn because t2 isn't.
28+
(a ? t1 : t2)(a);
29+
// The conditional operator is noreturn.
30+
(a ? t1 : t1)(a);
31+
}
32+
33+
// CHECK-LABEL: @test_conditional_Noreturn(
34+
// CHECK: %cond = select i1 %tobool, ptr @t3, ptr @t2
35+
// CHECK: call void %cond(
36+
// CHECK: %cond2 = select i1 %tobool1, ptr @t3, ptr @t3
37+
// CHECK: call void %cond2(
38+
// CHECK-NEXT: ret void
39+
_Noreturn void t3(int);
40+
_Noreturn void test_conditional_Noreturn(int a) {
41+
(a ? t3 : t2)(a);
42+
(a ? t3 : t3)(a);
43+
}
44+
45+
// CHECK-LABEL: @test_conditional_std(
46+
// CHECK: %cond = select i1 %tobool, ptr @t4, ptr @t2
47+
// CHECK: call void %cond(
48+
// CHECK: %cond2 = select i1 %tobool1, ptr @t4, ptr @t4
49+
// CHECK: call void %cond2(
50+
// CHECK-NEXT: ret void
51+
[[noreturn]] void t4(int);
52+
[[noreturn]] void test_conditional_std(int a) {
53+
(a ? t4 : t2)(a);
54+
(a ? t4 : t4)(a);
55+
}

0 commit comments

Comments
 (0)