Unverified Commit b72732c3 authored by Timm Baeder's avatar Timm Baeder Committed by GitHub
Browse files

[clang][Interp] Handle CXXTryStmts (#70584)

Just do the same thing the current interpreter does: Ignore all handlers
and visit the try block like normal.
parent e79f0506
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -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: {
@@ -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 {

+1 −0
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ private:
  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);

+13 −0
Original line number Diff line number Diff line
@@ -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);
}