Skip to content

Commit

Permalink
Use AddInitializerToDecl instead of setInit for safety
Browse files Browse the repository at this point in the history
  • Loading branch information
PetroZarytskyi committed Jul 30, 2024
1 parent 263a1b5 commit 68d4ecf
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/Differentiator/ReverseModeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2789,7 +2789,8 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context,
derivedVDE = BuildDeclRef(reverseSweepDerivativePointerE);
}
} else {
VDDerived->setInit(initDiff.getExpr_dx());
m_Sema.AddInitializerToDecl(VDDerived, initDiff.getExpr_dx(), true);
VDDerived->setInitStyle(VarDecl::InitializationStyle::CInit);
}
}
if (derivedVDE)
Expand Down Expand Up @@ -2951,7 +2952,9 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context,
decl, Clone(getArraySizeExpr(AT, m_Context, *this)), true);
decl->setInitStyle(VarDecl::InitializationStyle::CallInit);
} else {
decl->setInit(getZeroInit(VD->getType()));
m_Sema.AddInitializerToDecl(decl, getZeroInit(VD->getType()),
/*DirectInit=*/true);
decl->setInitStyle(VarDecl::InitializationStyle::CInit);
}
}
}
Expand Down

0 comments on commit 68d4ecf

Please sign in to comment.