From 232d17b7cfffbefb5eaf0a70365768b6f7c6f490 Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Wed, 6 Dec 2023 17:56:47 +0200 Subject: [PATCH] Fix assertions seen in clang13 due to type mismatches. (#664) 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 | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/Differentiator/VisitorBase.cpp b/lib/Differentiator/VisitorBase.cpp index 404a350dd..80b6678c6 100644 --- a/lib/Differentiator/VisitorBase.cpp +++ b/lib/Differentiator/VisitorBase.cpp @@ -325,10 +325,14 @@ 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>