Skip to content

Commit

Permalink
Fix assertions seen in clang13 due to type mismatches. (#664)
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 authored Dec 6, 2023
1 parent 5c248da commit 232d17b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/Differentiator/VisitorBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const clang::Expr*, llvm::SmallVector<const clang::Expr*, 4>>
Expand Down

0 comments on commit 232d17b

Please sign in to comment.