Skip to content

Commit

Permalink
Product of references in different scope
Browse files Browse the repository at this point in the history
  • Loading branch information
Max Andriychuk authored and Max Andriychuk committed Aug 6, 2024
1 parent 7cec7c8 commit aee9fec
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/Differentiator/ReverseModeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2295,7 +2295,15 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context,
StmtDiff RResult;
// If R has no side effects, it can be just cloned
// (no need to store it).
if (!ShouldRecompute(R)) {

// Check if the local variable declaration is reference type, since it is moved to the global scope and the right side should be recomputed
bool promoteToFnScope = false;
auto* RDeclRef = dyn_cast<DeclRefExpr>(R->IgnoreImplicit());
if (RDeclRef)
promoteToFnScope = RDeclRef->getDecl()->getType()->isReferenceType() &&
!getCurrentScope()->isFunctionScope();

if (!ShouldRecompute(R) || promoteToFnScope) {
RDelayed = std::unique_ptr<DelayedStoreResult>(
new DelayedStoreResult(DelayedGlobalStoreAndRef(R)));
RResult = RDelayed->Result;
Expand Down

0 comments on commit aee9fec

Please sign in to comment.