Skip to content

Commit

Permalink
Fix debug build assertions related to StmtClone
Browse files Browse the repository at this point in the history
  • Loading branch information
vaithak committed Feb 5, 2024
1 parent b58816f commit d50a33f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 2 additions & 0 deletions include/clad/Differentiator/StmtClone.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ namespace utils {
DECLARE_CLONE_FN(MaterializeTemporaryExpr)
DECLARE_CLONE_FN(PseudoObjectExpr)
DECLARE_CLONE_FN(SubstNonTypeTemplateParmExpr)
DECLARE_CLONE_FN(CXXScalarValueInitExpr)
DECLARE_CLONE_FN(ValueStmt)
// `ConstantExpr` node is only available after clang 7.
#if CLANG_VERSION_MAJOR > 7
DECLARE_CLONE_FN(ConstantExpr)
Expand Down
7 changes: 3 additions & 4 deletions lib/Differentiator/BaseForwardModeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1926,15 +1926,14 @@ StmtDiff BaseForwardModeVisitor::VisitCXXStaticCastExpr(
StmtDiff BaseForwardModeVisitor::VisitCXXFunctionalCastExpr(
const clang::CXXFunctionalCastExpr* FCE) {
StmtDiff castExprDiff = Visit(FCE->getSubExpr());
SourceLocation fakeLoc = utils::GetValidSLoc(m_Sema);
Expr* clonedFCE = m_Sema
.BuildCXXFunctionalCastExpr(
FCE->getTypeInfoAsWritten(), FCE->getType(), noLoc,
castExprDiff.getExpr(), noLoc)
FCE->getTypeInfoAsWritten(), FCE->getType(), fakeLoc, castExprDiff.getExpr(), fakeLoc)
.get();
Expr* derivedFCE = m_Sema
.BuildCXXFunctionalCastExpr(
FCE->getTypeInfoAsWritten(), FCE->getType(), noLoc,
castExprDiff.getExpr_dx(), noLoc)
FCE->getTypeInfoAsWritten(), FCE->getType(), fakeLoc, castExprDiff.getExpr_dx(), fakeLoc)
.get();
return {clonedFCE, derivedFCE};
}
Expand Down
2 changes: 2 additions & 0 deletions lib/Differentiator/StmtClone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ DEFINE_CLONE_EXPR(VAArgExpr,
Node->getWrittenTypeInfo(), Node->getRParenLoc(),
CloneType(Node->getType()), Node->isMicrosoftABI()))
DEFINE_CLONE_EXPR(ImplicitValueInitExpr, (CloneType(Node->getType())))
DEFINE_CLONE_EXPR(CXXScalarValueInitExpr, (CloneType(Node->getType()), Node->getTypeSourceInfo(), Node->getRParenLoc()))
DEFINE_CLONE_EXPR(ExtVectorElementExpr, (Node->getType(), Node->getValueKind(), Clone(Node->getBase()), Node->getAccessor(), Node->getAccessorLoc()))
DEFINE_CLONE_EXPR(CXXBoolLiteralExpr, (Node->getValue(), Node->getType(), Node->getSourceRange().getBegin()))
DEFINE_CLONE_EXPR(CXXNullPtrLiteralExpr, (Node->getType(), Node->getSourceRange().getBegin()))
Expand Down Expand Up @@ -429,6 +430,7 @@ DEFINE_CLONE_STMT(BreakStmt, (Node->getBreakLoc()))
DEFINE_CLONE_STMT(CXXCatchStmt, (Node->getCatchLoc(),
CloneDeclOrNull(Node->getExceptionDecl()),
Clone(Node->getHandlerBlock())))
DEFINE_CLONE_STMT(ValueStmt, (Node->getStmtClass()))

Stmt* StmtClone::VisitCXXTryStmt(CXXTryStmt* Node) {
llvm::SmallVector<Stmt*, 4> CatchStmts(std::max(1u, Node->getNumHandlers()));
Expand Down

0 comments on commit d50a33f

Please sign in to comment.