Skip to content
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 (second attempt) #17938

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

MathiasVP
Copy link
Contributor

@MathiasVP MathiasVP commented Nov 8, 2024

#16009 gave good results, but was unfortunately closed due to performance problems in DCA. Initially, I had concluded that GVN was causing ensuresEq(test, e, ..., block, ...) to hold for too many (e, block) pairs and thus causing a slowdown.

After working through some performance problems in Ben's alternative PR #17907 I realized that the performance problem was actually coming from an existing problem in the unary_simple_comparison_eq predicate: currently, on main, there is a very large QLDoc and some very ad-hoc conjunctions in the second disjunct of unary_simple_comparison_eq to reduce the size of the predicate. However, it turns out that this is too doing a very good job.

Instead, the second commit is restricting the predicate properly by pruning the set down to only those tests that are used in unary comparisons that we actually care about.

Commits a40c1d5 and db38069 are taken from #16009 which @jketema has already looked at (although I don't blame you for wanting to re-review it if you want to. Let me know if you want me to split up the complex commit again like in #16009). The only new thing is the pruning in 442968c

The commits that were tested at the latest DCA is consistent with the HEAD of this branch. I just force-pushed to clean up tests remove some spurious imports I had when experimenting with stuff.

@github-actions github-actions bot added the C++ label Nov 8, 2024
@MathiasVP MathiasVP force-pushed the fix-fp-in-missing-check-scanf-fixing-take-2 branch 2 times, most recently from e0f0b0a to 930efc2 Compare November 11, 2024 11:22
@MathiasVP
Copy link
Contributor Author

MathiasVP commented Nov 13, 2024

Bahh.... WAY too many join orders are broken by this and I don't feel like fixing them all 😪 I'll go back to keeping the non-GVN interface Done!

@MathiasVP MathiasVP force-pushed the fix-fp-in-missing-check-scanf-fixing-take-2 branch 4 times, most recently from d01d8f1 to 7a802d5 Compare November 14, 2024 14:16
@MathiasVP MathiasVP force-pushed the fix-fp-in-missing-check-scanf-fixing-take-2 branch from 7a802d5 to ac2630c Compare November 14, 2024 16:20
@MathiasVP MathiasVP force-pushed the fix-fp-in-missing-check-scanf-fixing-take-2 branch from ac2630c to bb85aa2 Compare November 14, 2024 16:30
@MathiasVP MathiasVP marked this pull request as ready for review November 14, 2024 16:33
@MathiasVP MathiasVP requested a review from a team as a code owner November 14, 2024 16:33
@jketema jketema changed the title C++: #16009 (second attempt) C++: Fix some FPs in cpp/missing-check-scanf (second attempt) Nov 14, 2024
@MathiasVP MathiasVP added the no-change-note-required This PR does not need a change note label Nov 14, 2024
Copy link
Contributor

@jketema jketema left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments on the first two commits. There's a few comments to occur in several places. Feel free to only react to one of those if you think nothing needs to be changed.

cpp/ql/lib/semmle/code/cpp/controlflow/IRGuards.qll Outdated Show resolved Hide resolved
cpp/ql/lib/semmle/code/cpp/controlflow/IRGuards.qll Outdated Show resolved Hide resolved
Comment on lines +84 to +106
private class CompareEQValueNumber extends CompareValueNumber {
override CompareEQInstruction cmp;
}

private class CompareNEValueNumber extends CompareValueNumber {
override CompareNEInstruction cmp;
}

private class CompareLTValueNumber extends CompareValueNumber {
override CompareLTInstruction cmp;
}

private class CompareGTValueNumber extends CompareValueNumber {
override CompareGTInstruction cmp;
}

private class CompareLEValueNumber extends CompareValueNumber {
override CompareLEInstruction cmp;
}

private class CompareGEValueNumber extends CompareValueNumber {
override CompareGEInstruction cmp;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these all possible cases?

cpp/ql/lib/semmle/code/cpp/controlflow/IRGuards.qll Outdated Show resolved Hide resolved
* A value number such that at least one of the instructions is an
* insruction that is used in a `SwitchInstruction`'s expression.
*/
private class ScrutineeValueNumber extends ValueNumber {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe ControllingValueNumber?

Comment on lines -1084 to +1167
CompareInstruction cmp, Operand left, Operand right, int k, boolean isLt, AbstractValue value
ValueNumber cmp, Operand left, Operand right, int k, boolean isLt, AbstractValue value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not CompareValueNumber?

Comment on lines -1102 to +1185
CompareInstruction cmp, Operand left, Operand right, int k, boolean isLt, AbstractValue value
ValueNumber cmp, Operand left, Operand right, int k, boolean isLt, AbstractValue value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not CompareValueNumber?

Comment on lines -1152 to +1235
CompareInstruction cmp, Operand left, Operand right, int k, boolean isLt, AbstractValue value
ValueNumber cmp, Operand left, Operand right, int k, boolean isLt, AbstractValue value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not CompareValueNumber?

Comment on lines -1220 to +1303
CompareInstruction cmp, Operand left, Operand right, int k, boolean areEqual, AbstractValue value
ValueNumber cmp, Operand left, Operand right, int k, boolean areEqual, AbstractValue value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not CompareValueNumber?

Comment on lines -1275 to +1358
CompareInstruction cmp, Operand left, Operand right, int k, boolean areEqual, AbstractValue value
ValueNumber cmp, Operand left, Operand right, int k, boolean areEqual, AbstractValue value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not CompareValueNumber?

MathiasVP and others added 3 commits November 14, 2024 21:28
Co-authored-by: Jeroen Ketema <[email protected]>
Co-authored-by: Jeroen Ketema <[email protected]>
Co-authored-by: Jeroen Ketema <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C++ no-change-note-required This PR does not need a change note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants