Skip to content

[CIR][CodeGen] Implemented noexcept expression handling #1752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
return nullptr;
}
mlir::Value VisitCXXNoexceptExpr(CXXNoexceptExpr *E) {
llvm_unreachable("NYI");
return CGF.getBuilder().getBool(E->getValue(), CGF.getLoc(E->getExprLoc()));
}

/// Perform a pointer to boolean conversion.
Expand Down
36 changes: 36 additions & 0 deletions clang/test/CIR/CodeGen/noexcept.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// RUN: %clang_cc1 -x c++ -triple x86_64-unknown-linux-gnu -fclangir -emit-cir -std=c++11 %s -o %t.cir
// RUN: FileCheck --input-file=%t.cir %s

void may_throw();
void no_throw() noexcept;

bool test_noexcept_func_false() {
return noexcept(may_throw());
}
// CHECK-LABEL: cir.func{{.*}} @_Z24test_noexcept_func_falsev
// CHECK: %[[CONST:.*]] = cir.const #false
// CHECK: cir.return

bool test_noexcept_func_true() {
return noexcept(no_throw());
}
// CHECK-LABEL: cir.func{{.*}} @_Z23test_noexcept_func_truev
// CHECK: %[[CONST:.*]] = cir.const #true
// CHECK: cir.return

auto lambda_may_throw = []() {};
auto lambda_no_throw = []() noexcept {};

bool test_noexcept_lambda_false() {
return noexcept(lambda_may_throw());
}
// CHECK-LABEL: cir.func{{.*}} @_Z26test_noexcept_lambda_falsev
// CHECK: %[[CONST:.*]] = cir.const #false
// CHECK: cir.return

bool test_noexcept_lambda_true() {
return noexcept(lambda_no_throw());
}
// CHECK-LABEL: cir.func{{.*}} @_Z25test_noexcept_lambda_truev
// CHECK: %[[CONST:.*]] = cir.const #true
// CHECK: cir.return
Loading