Skip to content

Commit

Permalink
Fix assertions seen in clang13 due to type mismatches.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vgvassilev committed Dec 3, 2023
1 parent ec76b70 commit 815d6f3
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/Differentiator/VisitorBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const clang::Expr*, llvm::SmallVector<const clang::Expr*, 4>>
Expand Down

0 comments on commit 815d6f3

Please sign in to comment.