Skip to content

Commit b72732c

Browse files
authored
[clang][Interp] Handle CXXTryStmts (#70584)
Just do the same thing the current interpreter does: Ignore all handlers and visit the try block like normal.
1 parent e79f050 commit b72732c

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

clang/lib/AST/Interp/ByteCodeStmtGen.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ bool ByteCodeStmtGen<Emitter>::visitStmt(const Stmt *S) {
255255
return visitAsmStmt(cast<AsmStmt>(S));
256256
case Stmt::AttributedStmtClass:
257257
return visitAttributedStmt(cast<AttributedStmt>(S));
258+
case Stmt::CXXTryStmtClass:
259+
return visitCXXTryStmt(cast<CXXTryStmt>(S));
258260
case Stmt::NullStmtClass:
259261
return true;
260262
default: {
@@ -643,6 +645,12 @@ bool ByteCodeStmtGen<Emitter>::visitAttributedStmt(const AttributedStmt *S) {
643645
return this->visitStmt(S->getSubStmt());
644646
}
645647

648+
template <class Emitter>
649+
bool ByteCodeStmtGen<Emitter>::visitCXXTryStmt(const CXXTryStmt *S) {
650+
// Ignore all handlers.
651+
return this->visitStmt(S->getTryBlock());
652+
}
653+
646654
namespace clang {
647655
namespace interp {
648656

clang/lib/AST/Interp/ByteCodeStmtGen.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class ByteCodeStmtGen final : public ByteCodeExprGen<Emitter> {
6565
bool visitDefaultStmt(const DefaultStmt *S);
6666
bool visitAsmStmt(const AsmStmt *S);
6767
bool visitAttributedStmt(const AttributedStmt *S);
68+
bool visitCXXTryStmt(const CXXTryStmt *S);
6869

6970
bool emitLambdaStaticInvokerBody(const CXXMethodDecl *MD);
7071

clang/test/AST/Interp/cxx20.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,3 +739,16 @@ namespace NonPrimitiveOpaqueValue
739739

740740
static_assert(!ternary(), "");
741741
}
742+
743+
namespace TryCatch {
744+
constexpr int foo() {
745+
int a = 10;
746+
try {
747+
++a;
748+
} catch(int m) {
749+
--a;
750+
}
751+
return a;
752+
}
753+
static_assert(foo() == 11);
754+
}

0 commit comments

Comments
 (0)