Skip to content
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

Fix pointer dereference in fwd mode #975

Merged
merged 1 commit into from
Jul 11, 2024
Merged

Conversation

vaithak
Copy link
Collaborator

@vaithak vaithak commented Jul 9, 2024

fixes #972

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

lib/Differentiator/BaseForwardModeVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/BaseForwardModeVisitor.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

github-actions bot commented Jul 9, 2024

clang-tidy review says "All clean, LGTM! 👍"

Copy link

codecov bot commented Jul 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.95%. Comparing base (f309b61) to head (ec62356).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #975   +/-   ##
=======================================
  Coverage   93.94%   93.95%           
=======================================
  Files          55       55           
  Lines        7962     7967    +5     
=======================================
+ Hits         7480     7485    +5     
  Misses        482      482           
Files Coverage Δ
lib/Differentiator/BaseForwardModeVisitor.cpp 98.99% <100.00%> (+<0.01%) ⬆️
Files Coverage Δ
lib/Differentiator/BaseForwardModeVisitor.cpp 98.99% <100.00%> (+<0.01%) ⬆️

Copy link
Contributor

github-actions bot commented Jul 9, 2024

clang-tidy review says "All clean, LGTM! 👍"

Comment on lines +1009 to +1012
if (clonedDRE->getType()->isPointerType())
return StmtDiff(clonedDRE, nullptr);
return StmtDiff(clonedDRE, ConstantFolder::synthesizeLiteral(
m_Context.IntTy, m_Context, /*val=*/0));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (clonedDRE->getType()->isPointerType())
return StmtDiff(clonedDRE, nullptr);
return StmtDiff(clonedDRE, ConstantFolder::synthesizeLiteral(
m_Context.IntTy, m_Context, /*val=*/0));
QualType clonedDreTy = clonedDRE->getType();
if (clonedDreTy->isPointerType())
return StmtDiff(clonedDRE, nullptr);
return StmtDiff(clonedDRE, ConstantFolder::synthesizeLiteral(
clonedDreTy, m_Context, /*val=*/0));

Comment on lines 1321 to 1325
Expr* dx = diff.getExpr_dx();
if (dx == nullptr)
return StmtDiff(op, ConstantFolder::synthesizeLiteral(
m_Context.IntTy, m_Context, /*val=*/0));
return StmtDiff(op, BuildOp(opKind, dx));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Expr* dx = diff.getExpr_dx();
if (dx == nullptr)
return StmtDiff(op, ConstantFolder::synthesizeLiteral(
m_Context.IntTy, m_Context, /*val=*/0));
return StmtDiff(op, BuildOp(opKind, dx));
if (Expr* dx = diff.getExpr_dx())
return StmtDiff(op, BuildOp(opKind, dx));
return StmtDiff(op, ConstantFolder::synthesizeLiteral(
m_Context.IntTy, m_Context, /*val=*/0));

I know that we are not using this consistently but IntTy here is probably not what we want semantically. Shall we give it a try with a VoidPtrTy or a NullPtrTy?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can't be a ptr type, as we want a numeric type here. So, changed to use the pointee type essentially 👍🏼

Copy link
Contributor

github-actions bot commented Jul 9, 2024

clang-tidy review says "All clean, LGTM! 👍"

Copy link
Contributor

github-actions bot commented Jul 9, 2024

clang-tidy review says "All clean, LGTM! 👍"

Comment on lines 1012 to 1013
if (!clonedDreTy->isRealType())
clonedDreTy = m_Context.IntTy; // force int if not real, ex. custom type
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we fix the implementation of ConstantFolder::synthesizeLiteral to generate maybe {} initializer list which is supposed to call the default constructor of the custom type?

PS: Sorry for making this hard as that's not quite related to this PR...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wouldn't be a good idea.
It can be done, but we will be assuming that a default constructor exists for this custom type, which properly zero initializes the data members. This assumption may constrain what we can differentiate.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but how this is different from what we have now scattered all over the place? I guess I was proposing to centralize the logic there and if the type does not have a default constructor with proper initialization we can complain...

Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@vgvassilev
Copy link
Owner

Maybe we should revert the PR to the old state where everything passed, merge it and continue with this change separately. That would unblock the release.

@vaithak
Copy link
Collaborator Author

vaithak commented Jul 11, 2024

Maybe we should revert the PR to the old state where everything passed, merge it and continue with this change separately. That would unblock the release.

Updated 👍🏼

Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

Copy link
Owner

@vgvassilev vgvassilev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Can you open a new one with the changes that we discussed, too?

@vgvassilev vgvassilev merged commit ef668c7 into vgvassilev:master Jul 11, 2024
89 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dereferencing of input parameters doesn't work in forward mode
2 participants