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

via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 30 01:38:06 PDT 2023


Author: Timm Baeder
Date: 2023-10-30T09:38:02+01:00
New Revision: b72732c37fd8d193cfa64e693b879dabdec813a5

URL: https://github.com/llvm/llvm-project/commit/b72732c37fd8d193cfa64e693b879dabdec813a5
DIFF: https://github.com/llvm/llvm-project/commit/b72732c37fd8d193cfa64e693b879dabdec813a5.diff

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

Just do the same thing the current interpreter does: Ignore all handlers
and visit the try block like normal.

Added: 
    

Modified: 
    clang/lib/AST/Interp/ByteCodeStmtGen.cpp
    clang/lib/AST/Interp/ByteCodeStmtGen.h
    clang/test/AST/Interp/cxx20.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
index 509abe3ae867f93..b1ab5fcf9cb64c3 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -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 {
 

diff  --git a/clang/lib/AST/Interp/ByteCodeStmtGen.h b/clang/lib/AST/Interp/ByteCodeStmtGen.h
index 31f9dbb8064c73c..64e03587ab2112d 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.h
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.h
@@ -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);
 

diff  --git a/clang/test/AST/Interp/cxx20.cpp b/clang/test/AST/Interp/cxx20.cpp
index f0bb4e9e0d0711b..50a7c02925878d5 100644
--- a/clang/test/AST/Interp/cxx20.cpp
+++ b/clang/test/AST/Interp/cxx20.cpp
@@ -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);
+}


        


More information about the cfe-commits mailing list