Skip to content

Commit

Permalink
Fix seg fault for catch(...)
Browse files Browse the repository at this point in the history
  • Loading branch information
vaithak committed Jan 18, 2024
1 parent d8ef790 commit 785e934
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/Differentiator/StmtClone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<VarDecl*>(CloneDecl(Node->getExceptionDecl())), Clone(Node->getHandlerBlock())))
DEFINE_CLONE_STMT(CXXCatchStmt, (Node->getCatchLoc(),
static_cast<VarDecl*>(
CloneDeclOrNull(Node->getExceptionDecl())),
Clone(Node->getHandlerBlock())))

Stmt* StmtClone::VisitCXXTryStmt(CXXTryStmt* Node) {
llvm::SmallVector<Stmt*, 4> CatchStmts(std::max(1u, Node->getNumHandlers()));
Expand Down
5 changes: 5 additions & 0 deletions test/FirstDerivative/DiffInterface.C
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,18 @@ 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;
// CHECK-NEXT: try {
// CHECK-NEXT: return x;
// CHECK-NEXT: } catch (int) {
// CHECK-NEXT: return 0;
// CHECK-NEXT: } catch (...) {
// CHECK-NEXT: return 1;
// CHECK-NEXT: }
// CHECK-NEXT: }

Expand Down

0 comments on commit 785e934

Please sign in to comment.