C++: Change range-analysis test to not use getAst
#13294
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
For a while we were confused about this range-analysis test:
because the inline-expectations test annotation seemed to suggest that range-analysis was claiming that
i
was bounded upper bounded by the return value of the call tof3_get
(which totally didn't make any sense). However, as @jketema correctly hypothesized, this was actually caused by the fact that we were usingInstruction.getAst
to obtain a string-representation of the bound. Dropping the use ofgetAst
(as I've done in PR) reveals what's really going on:which shows that
i
is upper bounded by a phi instruction generated on the linewhile (f3_get(n)) n+=2;
(which makes a lot more sense 🎉).Motivated by the above, this PR rewrites our range-analysis tests to not use
getAst
. This rewrite reveals that a lot of our bounds are phi instructions, and it would probably make sense to improve the string-representation of these bounds somehow. Currently, thetoString
on the bounds just output whatevertoString
does on instructions, and onPhiInstruction
's that's the wordPhi:
followed by the first thing in the basic block in which the phi instruction occur (which is why we see=Phi: call to f3_get
above). A reasonable follow-up to this PR would be to enrich the output ofPhiInstruction
'stoString
to print the name of the variable tracked by thePhiInstruction
(if any) so that the test would become:I'll leave that to a follow-up PR, though.