From a307338e71825dcaf5661331f1fcfb95ac8c0b06 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 | 2 ++ test/FirstDerivative/DiffInterface.C | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/lib/Differentiator/StmtClone.cpp b/lib/Differentiator/StmtClone.cpp index 4d9db2464..91afe9743 100644 --- a/lib/Differentiator/StmtClone.cpp +++ b/lib/Differentiator/StmtClone.cpp @@ -459,6 +459,8 @@ VarDecl* StmtClone::CloneDeclOrNull(VarDecl* Node) { } Decl* StmtClone::CloneDecl(Decl* Node) { + if (!Node) + return nullptr; // we support only exactly this class, so no visitor is needed (yet?) if (Node->getKind() == Decl::Var) { VarDecl* VD = static_cast(Node); 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: }