@@ -581,7 +581,8 @@ StmtDiff BaseForwardModeVisitor::VisitConditionalOperator(
581581 .ActOnConditionalOp (noLoc, noLoc, cond, ifTrueDiff.getExpr (),
582582 ifFalseDiff.getExpr ())
583583 .get ();
584-
584+ if (condExpr->getType ()->isVoidType ())
585+ return StmtDiff (condExpr, nullptr );
585586 // cond is already used by the value conditional above; clone it for the
586587 // derivative conditional so the two do not share the stored condition.
587588 Expr* condExprDiff =
@@ -1262,7 +1263,7 @@ StmtDiff BaseForwardModeVisitor::VisitCallExpr(const CallExpr* CE) {
12621263 if (!isa<CXXOperatorCallExpr>(CE ) && !isa<CXXMemberCallExpr>(CE ) &&
12631264 !needsForwPass) {
12641265 bool allArgsHaveZeroDerivatives = true ;
1265- for (unsigned i = 0 , e = CE -> getNumArgs (); i < e; ++i) {
1266+ for (unsigned i = 0 , e = diffArgs. size (); i < e; ++i) {
12661267 Expr* dArg = diffArgs[i];
12671268 // If argDiff.expr_dx is nullptr or is a constant 0, then the derivative
12681269 // of the function call is 0.
@@ -1321,7 +1322,7 @@ StmtDiff BaseForwardModeVisitor::VisitCallExpr(const CallExpr* CE) {
13211322 // If clad failed to derive it, try finding its derivative using
13221323 // numerical diff.
13231324 if (!callDiff) {
1324- Multiplier = diffArgs[0 ];
1325+ Multiplier = diffArgs. empty () ? nullptr : diffArgs [0 ];
13251326 Expr* call =
13261327 m_Sema
13271328 .ActOnCallExpr (getCurrentScope (), Clone (CE ->getCallee ()), validLoc,
@@ -1533,7 +1534,7 @@ BaseForwardModeVisitor::VisitBinaryOperator(const BinaryOperator* BinOp) {
15331534 } else if (opCode == BO_Comma) {
15341535 // if expression is (E1, E2) then derivative is (E1', E1, E2')
15351536 // because E1 may change some variables that E2 depends on.
1536- if (!isUnusedResult (Ldiff.getExpr_dx ())) {
1537+ if (Ldiff. getExpr_dx () && !isUnusedResult (Ldiff.getExpr_dx ())) {
15371538 opDiff = BuildOp (BO_Comma, BuildParens (Ldiff.getExpr_dx ()),
15381539 BuildParens (Ldiff.getExpr ()));
15391540 opDiff = BuildOp (BO_Comma, BuildParens (opDiff),
@@ -1874,6 +1875,13 @@ StmtDiff BaseForwardModeVisitor::VisitStringLiteral(const StringLiteral* SL) {
18741875 SL ->getType (), utils::GetValidSLoc (m_Sema)));
18751876}
18761877
1878+ StmtDiff
1879+ BaseForwardModeVisitor::VisitSourceLocExpr (const clang::SourceLocExpr* E) {
1880+ auto * Constant0 =
1881+ ConstantFolder::synthesizeLiteral (m_Context.IntTy , m_Context, /* val=*/ 0 );
1882+ return StmtDiff (CloneNode (E), Constant0);
1883+ }
1884+
18771885StmtDiff BaseForwardModeVisitor::VisitWhileStmt (const WhileStmt* WS ) {
18781886 // Scope for the whole while loop.
18791887 ScopeRAII whileScope (*this , Scope::ContinueScope | Scope::BreakScope |
0 commit comments