C++: Support (bool)x and !x in SimpleRangeAnalysis#4227
Conversation
|
I've learned my lesson from #4204, so I'm running https://jenkins.internal.semmle.com/job/Changes/job/CPP-Differences/1419/ before we merge this PR. |
| exists(VariableAccess access, float neConstant, float upper | | ||
| isNEPhi(v, phi, access, neConstant) and | ||
| upper = getFullyConvertedUpperBounds(access) and | ||
| upper = getTruncatedUpperBounds(access) and |
There was a problem hiding this comment.
This change is required because in C++ when we write if (myInt) there will be a BoolConversion on access, and so the fully-converted upper bounds will be at most 1.
I thought getTruncatedUpperBounds would be right for the upperBoundFromGuard case above too, but if I make that change then I break the tests that this PR adds in two_bounds_from_one_test. No other tests break, so our coverage was lacking before.
|
Can you add a test using |
Based on the code I've seen, I don't think |
geoffw0
left a comment
There was a problem hiding this comment.
This is quite a complicated change. LGTM, but I wouldn't mind a second opinion.
| // both an upper bound and a lower bound even when there is only one | ||
| // inequality in the source. For example `signedInt < 4U` establishes that | ||
| // `signedInt >= 0` since if `signedInt` were negative then it would be | ||
| // greater than 4 in the unsigned comparison. |
MathiasVP
left a comment
There was a problem hiding this comment.
I second Geoffrey's LGTM (but also his comment that it's a complicated PR on top of an already complicated library).
|
In which case, I propose one of us merges this once the diff job is complete, assuming the results of it are good. |
|
The CPP-Differences job has finally succeeded. The result changes all LGTM. I especially like that it's finding this bug in Linux, which has since been fixed. The performance changes LGTM also. While the overall numbers vary within the noise threshold, the per-query numbers show a 10-30s slowdown in |


This was harder than I thought because of the complication that in
if (x)there is no particular expression that comparesxto zero, andSimpleRangeAnalysisis built around having such an expression. It's also different in C and C++: in C++ there's aBoolConversionwhile in C there is none.