-
Notifications
You must be signed in to change notification settings - Fork 1.7k
C++: Fix some FPs in cpp/missing-check-scanf (third attempt!) #18207
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
C++: Fix some FPs in cpp/missing-check-scanf (third attempt!) #18207
Conversation
9abf985
to
b1add73
Compare
* Beware making mistaken logical implications here relating `areEqual` and `testIsTrue`. | ||
*/ | ||
cached | ||
predicate compares_eq( |
Check warning
Code scanning / CodeQL
Missing QLDoc for parameter Warning
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 913357b
|
||
/** Holds if `left < right + k` evaluates to `isLt` given that test is `testIsTrue`. */ | ||
cached | ||
predicate compares_lt( |
Check warning
Code scanning / CodeQL
Missing QLDoc for parameter Warning
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 913357b
C++: Fix a join-order problem that happens on #18207
b1add73
to
961599d
Compare
23da208
to
ec3b877
Compare
… be inlined to prevent explosions. Also remove the caching since this is't necessary now that the main recursion is cached.
…line the predicates.
ec3b877
to
913357b
Compare
GuardCondition() { | ||
exists(IRGuardCondition ir | this = ir.getUnconvertedResultExpression()) | ||
or | ||
// no binary operators in the IR | ||
this.(BinaryLogicalOperation).getAnOperand() instanceof GuardCondition | ||
} |
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.
Why was this removed?
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.
Before the introduction of final
aliases this class couldn't be made abstract
(since it would expose a abstract class from our libraries to queries). So instead of having this class be abstract we followed the pattern of:
- Specifying each subclass of this "pseudo-abstract" class in the charpred
- Provide a subclass that extended this "pseudo-abstract" class and repeated the required charpred to define the subclass.
That is, we've had to do:
class Base {
Base() {
myImpl1(this) or myImpl2(this)
}
}
class MyImpl1 extends Base {
MyImpl1() {
myImpl1(this)
}
}
class MyImpl2 extends Base {
MyImpl2() {
myImpl1(this)
}
}
Now that we have final classes we can get rid of this pattern (as we've done many other places) and actually use abstract classes. And abstract classes don't need this charpred since they're defined as the union of all the subclasses.
That is, we can rewrite the above example to:
private abstract class BaseImpl { } // <--- Note: We can now remove the charpred and only have it in the subclasses
final class Base = BaseImpl;
class MyImpl1 extends BaseImpl {
MyImpl1() {
myImpl1(this)
}
}
class MyImpl2 extends BaseImpl {
MyImpl2() {
myImpl1(this)
}
}
Does that make sense?
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.
Makes total sense.
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.
Additional changes after the revert-revert make sense.
Thanks a lot, Jeroen! DCA results are in and shows nothing of interest 🎉 |
This PR brings back the changes from #17938 and fixes the performance by inlining the
ensures
(and to some degree thecompares
) predicates which became too large after the improvements.Commit-by-commit review recommended:
abstract
classes in user-facing classes by using final extensions.ensures
predicates, and move thecache
ing to the implementation predicates. This should that we don't get expensive recomputations and that the user-facing predicates are never materialized.As an extra bonus, the inlining makes the performance fix added in 19d53fb unnecessary 🎉
After several rounds of join order fixes QA looks good 🎉 (0.55% analysis time difference). You can find the QA run in the backlink if you're curious.