Skip to content

Commit c25a2c7

Browse files
authored
[CIR] Upstream Exception with empty try block (llvm#162737)
Upstream, the basic support for the C++ try catch statement with an empty try block Issue llvm#154992
1 parent 04d3965 commit c25a2c7

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

clang/lib/CIR/CodeGen/CIRGenException.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,11 @@ void CIRGenFunction::emitAnyExprToExn(const Expr *e, Address addr) {
6464
// Deactivate the cleanup block.
6565
assert(!cir::MissingFeatures::ehCleanupScope());
6666
}
67+
68+
mlir::LogicalResult CIRGenFunction::emitCXXTryStmt(const CXXTryStmt &s) {
69+
if (s.getTryBlock()->body_empty())
70+
return mlir::LogicalResult::success();
71+
72+
cgm.errorNYI("exitCXXTryStmt: CXXTryStmt with non-empty body");
73+
return mlir::LogicalResult::success();
74+
}

clang/lib/CIR/CodeGen/CIRGenFunction.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,6 +1297,8 @@ class CIRGenFunction : public CIRGenTypeCache {
12971297

12981298
void emitCXXThrowExpr(const CXXThrowExpr *e);
12991299

1300+
mlir::LogicalResult emitCXXTryStmt(const clang::CXXTryStmt &s);
1301+
13001302
void emitCtorPrologue(const clang::CXXConstructorDecl *ctor,
13011303
clang::CXXCtorType ctorType, FunctionArgList &args);
13021304

clang/lib/CIR/CodeGen/CIRGenStmt.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ mlir::LogicalResult CIRGenFunction::emitStmt(const Stmt *s,
154154
return emitWhileStmt(cast<WhileStmt>(*s));
155155
case Stmt::DoStmtClass:
156156
return emitDoStmt(cast<DoStmt>(*s));
157+
case Stmt::CXXTryStmtClass:
158+
return emitCXXTryStmt(cast<CXXTryStmt>(*s));
157159
case Stmt::CXXForRangeStmtClass:
158160
return emitCXXForRangeStmt(cast<CXXForRangeStmt>(*s), attr);
159161
case Stmt::OpenACCComputeConstructClass:
@@ -199,7 +201,6 @@ mlir::LogicalResult CIRGenFunction::emitStmt(const Stmt *s,
199201
case Stmt::CoroutineBodyStmtClass:
200202
return emitCoroutineBody(cast<CoroutineBodyStmt>(*s));
201203
case Stmt::CoreturnStmtClass:
202-
case Stmt::CXXTryStmtClass:
203204
case Stmt::IndirectGotoStmtClass:
204205
case Stmt::OMPParallelDirectiveClass:
205206
case Stmt::OMPTaskwaitDirectiveClass:
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fcxx-exceptions -fexceptions -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 -fcxx-exceptions -fexceptions -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 -fcxx-exceptions -fexceptions -emit-llvm %s -o %t.ll
6+
// RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG
7+
8+
void empty_try_block_with_catch_all() {
9+
try {} catch (...) {}
10+
}
11+
12+
// CIR: cir.func{{.*}} @_Z30empty_try_block_with_catch_allv()
13+
// CIR: cir.return
14+
15+
// LLVM: define{{.*}} void @_Z30empty_try_block_with_catch_allv()
16+
// LLVM: ret void
17+
18+
// OGCG: define{{.*}} void @_Z30empty_try_block_with_catch_allv()
19+
// OGCG: ret void
20+
21+
void empty_try_block_with_catch_with_int_exception() {
22+
try {} catch (int e) {}
23+
}
24+
25+
// CIR: cir.func{{.*}} @_Z45empty_try_block_with_catch_with_int_exceptionv()
26+
// CIR: cir.return
27+
28+
// LLVM: define{{.*}} void @_Z45empty_try_block_with_catch_with_int_exceptionv()
29+
// LLVM: ret void
30+
31+
// OGCG: define{{.*}} void @_Z45empty_try_block_with_catch_with_int_exceptionv()
32+
// OGCG: ret void

0 commit comments

Comments
 (0)