From 785e934bba5b5ccaa6278e3490f99b4cb39a2172 Mon Sep 17 00:00:00 2001 From: Vaibhav Thakkar Date: Thu, 18 Jan 2024 16:04:27 +0100 Subject: [PATCH] Fix seg fault for catch(...) fixes #86 --- lib/Differentiator/StmtClone.cpp | 5 ++++- test/FirstDerivative/DiffInterface.C | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/Differentiator/StmtClone.cpp b/lib/Differentiator/StmtClone.cpp index 4d9db2464..139a304a5 100644 --- a/lib/Differentiator/StmtClone.cpp +++ b/lib/Differentiator/StmtClone.cpp @@ -426,7 +426,10 @@ DEFINE_CLONE_STMT(ForStmt, (Ctx, Clone(Node->getInit()), Clone(Node->getCond()), Node->getForLoc(), Node->getLParenLoc(), Node->getRParenLoc())) DEFINE_CLONE_STMT(ContinueStmt, (Node->getContinueLoc())) DEFINE_CLONE_STMT(BreakStmt, (Node->getBreakLoc())) -DEFINE_CLONE_STMT(CXXCatchStmt, (Node->getCatchLoc(), static_cast(CloneDecl(Node->getExceptionDecl())), Clone(Node->getHandlerBlock()))) +DEFINE_CLONE_STMT(CXXCatchStmt, (Node->getCatchLoc(), + static_cast( + CloneDeclOrNull(Node->getExceptionDecl())), + Clone(Node->getHandlerBlock()))) Stmt* StmtClone::VisitCXXTryStmt(CXXTryStmt* Node) { llvm::SmallVector CatchStmts(std::max(1u, Node->getNumHandlers())); diff --git a/test/FirstDerivative/DiffInterface.C b/test/FirstDerivative/DiffInterface.C index 13bd42394..dda26f136 100644 --- a/test/FirstDerivative/DiffInterface.C +++ b/test/FirstDerivative/DiffInterface.C @@ -75,6 +75,9 @@ int f_try_catch(int x) catch (int) { return 0; } + catch (...) { + return 1; + } // CHECK: int f_try_catch_darg0(int x) { // CHECK-NEXT: int _d_x = 1; @@ -82,6 +85,8 @@ int f_try_catch(int x) // CHECK-NEXT: return x; // CHECK-NEXT: } catch (int) { // CHECK-NEXT: return 0; +// CHECK-NEXT: } catch (...) { +// CHECK-NEXT: return 1; // CHECK-NEXT: } // CHECK-NEXT: }