From efe56768767100e4223447767f21b74d26315a1f Mon Sep 17 00:00:00 2001 From: "petro.zarytskyi" Date: Mon, 29 Jul 2024 17:25:19 +0300 Subject: [PATCH] Use AddInitializerToDecl instead of setInit for safety --- lib/Differentiator/ReverseModeVisitor.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/Differentiator/ReverseModeVisitor.cpp b/lib/Differentiator/ReverseModeVisitor.cpp index 16758e0f6..2656eae2a 100644 --- a/lib/Differentiator/ReverseModeVisitor.cpp +++ b/lib/Differentiator/ReverseModeVisitor.cpp @@ -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) @@ -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()), + true); + decl->setInitStyle(VarDecl::InitializationStyle::CInit); } } }