From 815d6f3cb87f73ced7284a93049b58b9f8cfd6c8 Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Sun, 3 Dec 2023 20:08:19 +0000 Subject: [PATCH] Fix assertions seen in clang13 due to type mismatches. When we synthesize the 0 constant we do not take into account if the corresponding type matches to IntTy. In case it does not match we need to add the necessary implicit casts. This patch fixes an issue that became visible after landing PR #655. --- lib/Differentiator/VisitorBase.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/Differentiator/VisitorBase.cpp b/lib/Differentiator/VisitorBase.cpp index 404a350dd..b198fa544 100644 --- a/lib/Differentiator/VisitorBase.cpp +++ b/lib/Differentiator/VisitorBase.cpp @@ -325,10 +325,13 @@ namespace clad { } Expr* VisitorBase::getZeroInit(QualType T) { - if (T->isScalarType()) - return ConstantFolder::synthesizeLiteral(m_Context.IntTy, m_Context, 0); - else - return m_Sema.ActOnInitList(noLoc, {}, noLoc).get(); + // FIXME: Consolidate other uses of synthesizeLiteral for creation 0 or 1. + if (T->isScalarType()) { + ExprResult Zero = ConstantFolder::synthesizeLiteral(m_Context.IntTy, m_Context, 0); + CastKind CK = m_Sema.PrepareScalarCast(Zero, T); + return m_Sema.ImpCastExprToType(Zero.get(), T, CK).get(); + } + return m_Sema.ActOnInitList(noLoc, {}, noLoc).get(); } std::pair>