diff --git a/lib/Differentiator/ReverseModeVisitor.cpp b/lib/Differentiator/ReverseModeVisitor.cpp index 276028011..badbf2591 100644 --- a/lib/Differentiator/ReverseModeVisitor.cpp +++ b/lib/Differentiator/ReverseModeVisitor.cpp @@ -2406,7 +2406,7 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context, else { derivedE = BuildOp(UnaryOperatorKind::UO_Deref, diff_dx); // Create the (target += dfdx) statement. - if (dfdx()) { + if (dfdx() && derivedE) { if (shouldUseCudaAtomicOps(diff_dx)) { Expr* atomicCall = BuildCallToCudaAtomicAdd(diff_dx, dfdx()); // Add it to the body statements.