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 authored and vgvassilev committed Jan 18, 2024
1 parent d8ef790 commit d5a8ac9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/Differentiator/StmtClone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,9 @@ 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(),
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 d5a8ac9

Please sign in to comment.