This is an archive of the discontinued LLVM Phabricator instance.

[CGExprAgg] Fix infinite loop in `findPeephole`
ClosedPublic

Authored by ekatz on Apr 14 2020, 4:32 AM.

Details

Summary

Simplify the function using IgnoreParenNoopCasts.

Fix PR45476

Diff Detail

Event Timeline

ekatz created this revision.Apr 14 2020, 4:32 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 14 2020, 4:32 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Can test be added here?

ekatz updated this revision to Diff 257299.Apr 14 2020, 5:45 AM

Added test.

rjmccall added inline comments.Apr 14 2020, 12:15 PM
clang/lib/CodeGen/CGExprAgg.cpp
687

I liked the structure of the old code better, in case we want to look through other kinds of expressions. Please just add op = castE->getSubExpr() before the continue.

ekatz marked an inline comment as done.Apr 14 2020, 1:36 PM
ekatz added inline comments.
clang/lib/CodeGen/CGExprAgg.cpp
687

I see your point. I'll change that.
Though I must say that the old structure is a little strange with the return nullptr in the end of the loop...

ekatz updated this revision to Diff 257482.Apr 14 2020, 1:45 PM

Use the old structure of the algorithm, with the fix, as requested.

rjmccall added inline comments.Apr 14 2020, 2:28 PM
clang/lib/CodeGen/CGExprAgg.cpp
687

Oh, you know, there's also an IgnoreParenNoopCasts that we could just use instead of this loop if we're willing to ignore other possible expressions we might want to look through.

ekatz marked an inline comment as done.Apr 14 2020, 7:00 PM
ekatz added inline comments.
clang/lib/CodeGen/CGExprAgg.cpp
687

I am not familiar enough with clang's code to make the decision to remove this function.
Personally I wanted to fix the bug, and I guess this function is here for a reason..?

rjmccall added inline comments.Apr 14 2020, 8:10 PM
clang/lib/CodeGen/CGExprAgg.cpp
687

I don't think there's anything here really worth keeping. Please keep the function around but replace its body with something like:

op = op->IgnoreParenNoopCasts();
if (auto castE = dyn_cast<CastExpr>(op)) {
  if (castE->getCastKind() == kind)
    return castE->getSubExpr();
}
return nullptr;
ekatz marked an inline comment as done.Apr 15 2020, 3:51 AM
ekatz added inline comments.
clang/lib/CodeGen/CGExprAgg.cpp
687

Sorry, I, kinda, misunderstood you suggestion before.
This is a really good implementation, but as you said, this function should, and I quote from its description, "look through various unimportant expressions". So I guess it is better to leave it this way (with the loop), as it is already in the base code. What do you say?

ekatz marked an inline comment as done.Apr 15 2020, 3:58 AM
ekatz added inline comments.
clang/lib/CodeGen/CGExprAgg.cpp
687

I'll counter myself. (COVID-19 + Kids = TOTAL Tiredness)
This still gives us the opportunity to add "various unimportant expressions". I'll change to the suggested implementation.
Thanks! :)

ekatz updated this revision to Diff 257665.Apr 15 2020, 3:59 AM
ekatz edited the summary of this revision. (Show Details)

Simplify function using IgnoreParenNoopCasts.

rjmccall accepted this revision.Apr 15 2020, 10:52 AM

Thanks, LGTM.

This revision is now accepted and ready to land.Apr 15 2020, 10:52 AM

Oh, no, not quite. Please name the test case to something more specific; pr45476.cpp would be fine.

ekatz updated this revision to Diff 257794.Apr 15 2020, 12:05 PM

Changed the name of the test file to pr45476.cpp.

rjmccall accepted this revision.Apr 15 2020, 12:09 PM
This revision was automatically updated to reflect the committed changes.