-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Try to improve literal types #998
Changes from 13 commits
2b2af14
61982a1
4432e1f
4b57f76
1f4e2a3
97acf5f
aee91cd
6130c91
98352a8
1de6bbe
17012c0
9feae1b
03fbcec
1a1e25b
2dc1126
ac042f9
69075f1
3a593d0
d3740e4
2e6b9d0
2a8655e
df2617d
6816d9a
f7b3caa
c74882d
fd45301
0413ab7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1070,8 +1070,11 @@ | |
// If DRE is of type pointer, then the derivative is a null pointer. | ||
if (clonedDRE->getType()->isPointerType()) | ||
return StmtDiff(clonedDRE, nullptr); | ||
QualType literalTy = utils::GetValueType(clonedDRE->getType()); | ||
if (!literalTy->isRealType()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need this special check here? |
||
literalTy = m_Context.IntTy; | ||
return StmtDiff(clonedDRE, ConstantFolder::synthesizeLiteral( | ||
m_Context.IntTy, m_Context, /*val=*/0)); | ||
literalTy, m_Context, /*val=*/0)); | ||
} | ||
|
||
StmtDiff BaseForwardModeVisitor::VisitIntegerLiteral(const IntegerLiteral* IL) { | ||
|
@@ -1374,8 +1377,12 @@ | |
} else if (opKind == UnaryOperatorKind::UO_Deref) { | ||
if (Expr* dx = diff.getExpr_dx()) | ||
return StmtDiff(op, BuildOp(opKind, dx)); | ||
return StmtDiff(op, ConstantFolder::synthesizeLiteral( | ||
m_Context.IntTy, m_Context, /*val=*/0)); | ||
QualType literalTy = | ||
utils::GetValueType(UnOp->getSubExpr()->getType()->getPointeeType()); | ||
if (!literalTy->isRealType()) | ||
literalTy = m_Context.IntTy; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should not need this. This gets handled in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True, it was a leftover from Vaibhav's PR. I will remove these lines. |
||
return StmtDiff( | ||
op, ConstantFolder::synthesizeLiteral(literalTy, m_Context, /*val=*/0)); | ||
} else if (opKind == UnaryOperatorKind::UO_AddrOf) { | ||
return StmtDiff(op, BuildOp(opKind, diff.getExpr_dx())); | ||
} else if (opKind == UnaryOperatorKind::UO_LNot) { | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -379,9 +379,8 @@ namespace clad { | |||||
// FIXME: Consolidate other uses of synthesizeLiteral for creation 0 or 1. | ||||||
if (T->isVoidType()) | ||||||
return nullptr; | ||||||
if (T->isScalarType()) { | ||||||
ExprResult Zero = | ||||||
ConstantFolder::synthesizeLiteral(m_Context.IntTy, m_Context, 0); | ||||||
if (T->isScalarType() && !T->isPointerType()) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need this here? Shouldn't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right now, the pointers are initialized as an empty list, which is equivalent to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that'd be more readable, too. |
||||||
ExprResult Zero = ConstantFolder::synthesizeLiteral(T, m_Context, 0); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: argument comment missing for literal argument 'val' [bugprone-argument-comment] ExprResult Zero = ConstantFolder::synthesizeLiteral(T, m_Context, 0);
^ this fix will not be applied because it overlaps with another fix There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: argument comment missing for literal argument 'val' [bugprone-argument-comment]
Suggested change
|
||||||
CastKind CK = m_Sema.PrepareScalarCast(Zero, T); | ||||||
return m_Sema.ImpCastExprToType(Zero.get(), T, CK).get(); | ||||||
} | ||||||
vgvassilev marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should extend visitorbase::getZeroInit as discussed here #989 (comment)
cc: @gojakuch