[clang] [clang][Interp] Handle CXXTryStmts (PR #70584)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Oct 28 23:47:39 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
Just do the same thing the current interpreter does: Ignore all handlerrs and visit the try block like normal.
---
Full diff: https://github.com/llvm/llvm-project/pull/70584.diff
3 Files Affected:
- (modified) clang/lib/AST/Interp/ByteCodeStmtGen.cpp (+8)
- (modified) clang/lib/AST/Interp/ByteCodeStmtGen.h (+1)
- (modified) clang/test/AST/Interp/cxx20.cpp (+13)
``````````diff
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);
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/70584
More information about the cfe-commits
mailing list