-
Notifications
You must be signed in to change notification settings - Fork 1.9k
C++: Consider columns in Location.isBefore
#8525
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
Conversation
896d888 to
fe0e970
Compare
|
@geoffw0 convinced me that we shouldn't change the behavior of the existing predicate. So I've force-pushed a backward-compatible version. I've changed IR generation so that it uses the new predicate to get the behavior I described in the PR description. |
|
You might want to add the goto example to the IR tests? |
Good point! I'll do that. |
fe0e970 to
93346a5
Compare
|
Done. I did another force-push to insert the test in the right commit. |
| pragma[inline] | ||
| predicate isBefore(Location l) { | ||
| this.getFile() = l.getFile() and this.getEndLine() < l.getStartLine() | ||
| predicate isBefore(Location l) { isBefore(l, false) } |
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.
It shows a warning about an implicit this here. Should that be fixed?
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.
Yeah, it really should. I'll add the explicit this, but I won't force-push the change since that will mess up the DCA run.
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.
Otherwise this LGTM.
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.
Fixed in c35b385.
jketema
left a comment
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.
LGTM.
I was hacking on a solution to #8497 and was surprised to learn that
Location.isBeforeis reallyLocation.lineIsBefore.As an added bonus to this PR, this will improve our IR generation for code that uses
gotos:Currently, our only use of
Location.isBeforepredicate is to determine whether agotostatement creates a back edge in the control-flow graph. So onmain, the following program:gets translated as:
i.e., we conservatively assume that the goto could be a back edge. However, with this PR the same code is translated as:
with no back edge!
I admit this is a bit of a niche case. But it's nice to see that it actually does have the intended effect.