Skip to content

Commit a7aa852

Browse files
authored
[CIR] Upstream CXXNoexceptExpr (#171462)
Upstream the support for CXXNoexceptExpr
1 parent 36865a1 commit a7aa852

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,10 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
870870
return {};
871871
}
872872

873+
mlir::Value VisitCXXNoexceptExpr(CXXNoexceptExpr *e) {
874+
return builder.getBool(e->getValue(), cgf.getLoc(e->getExprLoc()));
875+
}
876+
873877
/// Emit a conversion from the specified type to the specified destination
874878
/// type, both of which are CIR scalar types.
875879
/// TODO: do we need ScalarConversionOpts here? Should be done in another
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-cir %s -o %t.cir
2+
// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR
3+
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-llvm %s -o %t-cir.ll
4+
// RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVM
5+
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -Wno-unused-value -emit-llvm %s -o %t.ll
6+
// RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG
7+
8+
void function_may_throw();
9+
10+
void function_no_except() noexcept;
11+
12+
void no_except() {
13+
bool a = noexcept(1);
14+
bool b = noexcept(function_may_throw());
15+
bool c = noexcept(function_no_except());
16+
}
17+
18+
// CIR: %[[A_ADDR:.*]] = cir.alloca !cir.bool, !cir.ptr<!cir.bool>, ["a", init]
19+
// CIR: %[[B_ADDR:.*]] = cir.alloca !cir.bool, !cir.ptr<!cir.bool>, ["b", init]
20+
// CIR: %[[C_ADDR:.*]] = cir.alloca !cir.bool, !cir.ptr<!cir.bool>, ["c", init]
21+
// CIR: %[[CONST_TRUE:.*]] = cir.const #true
22+
// CIR: cir.store {{.*}} %[[CONST_TRUE]], %[[A_ADDR]] : !cir.bool, !cir.ptr<!cir.bool>
23+
// CIR: %[[CONST_FALSE:.*]] = cir.const #false
24+
// CIR: cir.store {{.*}} %[[CONST_FALSE]], %[[B_ADDR]] : !cir.bool, !cir.ptr<!cir.bool>
25+
// CIR: %[[CONST_TRUE:.*]] = cir.const #true
26+
// CIR: cir.store {{.*}} %[[CONST_TRUE]], %[[C_ADDR]] : !cir.bool, !cir.ptr<!cir.bool>
27+
28+
// LLVM: %[[A_ADDR:.*]] = alloca i8, i64 1, align 1
29+
// LLVM: %[[B_ADDR:.*]] = alloca i8, i64 1, align 1
30+
// LLVM: %[[C_ADDR:.*]] = alloca i8, i64 1, align 1
31+
// LLVM: store i8 1, ptr %[[A_ADDR]], align 1
32+
// LLVM: store i8 0, ptr %[[B_ADDR]], align 1
33+
// LLVM: store i8 1, ptr %[[C_ADDR]], align 1
34+
35+
// OGCG: %[[A_ADDR:.*]] = alloca i8, align 1
36+
// OGCG: %[[B_ADDR:.*]] = alloca i8, align 1
37+
// OGCG: %[[C_ADDR:.*]] = alloca i8, align 1
38+
// OGCG: store i8 1, ptr %[[A_ADDR]], align 1
39+
// OGCG: store i8 0, ptr %[[B_ADDR]], align 1
40+
// OGCG: store i8 1, ptr %[[C_ADDR]], align 1

0 commit comments

Comments
 (0)