Skip to content

Commit

Permalink
[clang][Interp] Handle CXXTryStmts (#70584)
Browse files Browse the repository at this point in the history
Just do the same thing the current interpreter does: Ignore all handlers
and visit the try block like normal.
  • Loading branch information
tbaederr committed Oct 30, 2023
1 parent e79f050 commit b72732c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions clang/lib/AST/Interp/ByteCodeStmtGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ bool ByteCodeStmtGen<Emitter>::visitStmt(const Stmt *S) {
return visitAsmStmt(cast<AsmStmt>(S));
case Stmt::AttributedStmtClass:
return visitAttributedStmt(cast<AttributedStmt>(S));
case Stmt::CXXTryStmtClass:
return visitCXXTryStmt(cast<CXXTryStmt>(S));
case Stmt::NullStmtClass:
return true;
default: {
Expand Down Expand Up @@ -643,6 +645,12 @@ bool ByteCodeStmtGen<Emitter>::visitAttributedStmt(const AttributedStmt *S) {
return this->visitStmt(S->getSubStmt());
}

template <class Emitter>
bool ByteCodeStmtGen<Emitter>::visitCXXTryStmt(const CXXTryStmt *S) {
// Ignore all handlers.
return this->visitStmt(S->getTryBlock());
}

namespace clang {
namespace interp {

Expand Down
1 change: 1 addition & 0 deletions clang/lib/AST/Interp/ByteCodeStmtGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class ByteCodeStmtGen final : public ByteCodeExprGen<Emitter> {
bool visitDefaultStmt(const DefaultStmt *S);
bool visitAsmStmt(const AsmStmt *S);
bool visitAttributedStmt(const AttributedStmt *S);
bool visitCXXTryStmt(const CXXTryStmt *S);

bool emitLambdaStaticInvokerBody(const CXXMethodDecl *MD);

Expand Down
13 changes: 13 additions & 0 deletions clang/test/AST/Interp/cxx20.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -739,3 +739,16 @@ namespace NonPrimitiveOpaqueValue

static_assert(!ternary(), "");
}

namespace TryCatch {
constexpr int foo() {
int a = 10;
try {
++a;
} catch(int m) {
--a;
}
return a;
}
static_assert(foo() == 11);
}

0 comments on commit b72732c

Please sign in to comment.