Skip to content

Commit 9df3f7c

Browse files
committed
[CIR][CodeGen] Implemented noexcept expression handling
Implemented `noexcept` expression handling in CIR generation. Added a `noexcept.cpp` test based on cppreference, no OG test.
1 parent 8f89224 commit 9df3f7c

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
728728
return nullptr;
729729
}
730730
mlir::Value VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
731-
llvm_unreachable("NYI");
731+
return CGF.getBuilder().getBool(E->getValue(), CGF.getLoc(E->getExprLoc()));
732732
}
733733

734734
/// Perform a pointer to boolean conversion.

clang/test/CIR/CodeGen/noexcept.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// RUN: %clang_cc1 -x c++ -triple x86_64-unknown-linux-gnu -fclangir -emit-cir -std=c++11 %s -o %t.cir
2+
// RUN: FileCheck --input-file=%t.cir %s
3+
4+
void may_throw();
5+
void no_throw() noexcept;
6+
7+
bool test_noexcept_func_false() {
8+
return noexcept(may_throw());
9+
}
10+
// CHECK-LABEL: cir.func{{.*}} @_Z24test_noexcept_func_falsev
11+
// CHECK: %[[CONST:.*]] = cir.const #false
12+
// CHECK: cir.return
13+
14+
bool test_noexcept_func_true() {
15+
return noexcept(no_throw());
16+
}
17+
// CHECK-LABEL: cir.func{{.*}} @_Z23test_noexcept_func_truev
18+
// CHECK: %[[CONST:.*]] = cir.const #true
19+
// CHECK: cir.return
20+
21+
auto lambda_may_throw = []() {};
22+
auto lambda_no_throw = []() noexcept {};
23+
24+
bool test_noexcept_lambda_false() {
25+
return noexcept(lambda_may_throw());
26+
}
27+
// CHECK-LABEL: cir.func{{.*}} @_Z26test_noexcept_lambda_falsev
28+
// CHECK: %[[CONST:.*]] = cir.const #false
29+
// CHECK: cir.return
30+
31+
bool test_noexcept_lambda_true() {
32+
return noexcept(lambda_no_throw());
33+
}
34+
// CHECK-LABEL: cir.func{{.*}} @_Z25test_noexcept_lambda_truev
35+
// CHECK: %[[CONST:.*]] = cir.const #true
36+
// CHECK: cir.return

0 commit comments

Comments
 (0)