From e9c47b7f990de937fed46967baf1a2f85e45eff6 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 621ca8ee8..f95f2c60f 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()), + /*DirectInit=*/true); + decl->setInitStyle(VarDecl::InitializationStyle::CInit); } } }