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++: Reduce number of FPs cpp/guarded-free and turn if(x) { free(x) } cases from FNs to TPs #17986

Merged
merged 8 commits into from
Nov 20, 2024

Conversation

jketema
Copy link
Contributor

@jketema jketema commented Nov 14, 2024

The additional conditions to reduce FPs are maybe somewhat on the strict side, but given that a MRVA 1000 experiment already gives over 5k results, I don't think that this much of a problem. As far as I can tell there is just one remaining FP in MRVA (which occurs a few times), and which comes from the libpng library.

https://github.com/naturalatlas/node-gdal/blob/c83e7858a9ec566cc91d65db74fd07b99789c0f0/deps/libgdal/gdal/frmts/png/libpng/pngmem.c#L541-L560

Given that this is now the only FP, I did not investigate this further. I think we could promote the query with these changes from this PR.

Pull Request checklist

All query authors

Internal query authors only

  • Autofixes generated based on these changes are valid, only needed if this PR makes significant changes to .ql, .qll, or .qhelp files. See the documentation (internal access required).
  • Changes are validated at scale (internal access required).
  • Adding a new query? Consider also adding the query to autofix.

@github-actions github-actions bot added the C++ label Nov 14, 2024
@jketema jketema requested a review from geoffw0 November 14, 2024 12:05
@jketema jketema marked this pull request as ready for review November 14, 2024 12:44
@jketema jketema requested a review from a team as a code owner November 14, 2024 12:44
Copy link
Contributor

@geoffw0 geoffw0 left a comment

Choose a reason for hiding this comment

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

Couple of small requests, otherwise LGTM.

Also deserves a DCA run before merging. I gather you have reviewed MRVA differences already.

strictcount(bb.(BlockStmt).getAStmt()) = 1
) and
strictcount(BasicBlock bb2 | gc.ensuresEq(_, 0, bb2, _) | bb2) = 1 and
not fc.isInMacroExpansion() and
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't particularly like this exclusion, but I can see that it circumvents some really difficult cases and helps get us a good set of results.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed.

@jketema
Copy link
Contributor Author

jketema commented Nov 18, 2024

Also deserves a DCA run before merging.

How do you propose I run DCA? Note that this is still an experimental query, so it won't be run by default.

I gather you have reviewed MRVA differences already.

Correct. Checking for the file when in the proprocessor block case, might deserve some further investigation though.

@geoffw0
Copy link
Contributor

geoffw0 commented Nov 18, 2024

How do you propose I run DCA? Note that this is still an experimental query, so it won't be run by default.

Ah, perhaps we can save this until the PR that promotes the query then. FWIW I think it is possible to specify a single query rather than a suite when running DCA - if so, that might work around the problem, though I guess nothing would be cached so the performance data might still be a bit off.

Checking for the file when in the proprocessor block case, might deserve some further investigation though.

Yeah, this bug could have been almost randomly hiding results - good or bad.

Copy link
Contributor

@geoffw0 geoffw0 left a comment

Choose a reason for hiding this comment

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

👍

Approved, on the assumption that you briefly re-check some results on MRVA following the fix to blockContainsPreprocessorBranches.

@jketema
Copy link
Contributor Author

jketema commented Nov 18, 2024

FWIW I think it is possible to specify a single query rather than a suite when running DCA

Good point. Let me run that anyway, so we can at least see if there are any alert differences, and it doesn't blow up completely analysis time-wise.

@geoffw0
Copy link
Contributor

geoffw0 commented Nov 19, 2024

DCA shows 99 added, 2866 removed results for cpp/guarded-free. Unfortunately we don't seem to be able to see the individual changes, but I suppose we were expecting some new results for the { free(x); } pattern. Analysis time looks to be unaffected. 👍

@jketema
Copy link
Contributor Author

jketema commented Nov 19, 2024

Approved, on the assumption that you briefly re-check some results on MRVA following the fix to blockContainsPreprocessorBranches.

There are about 1.6k new results. They all look genuine.

DCA shows 99 added, 2866 removed results for cpp/guarded-free. Unfortunately we don't seem to be able to see the individual changes, but I suppose we were expecting some new results for the { free(x); } pattern. Analysis time looks to be unaffected. 👍

Yup. I've asked internally whether I can still somehow generate the table.

@jketema
Copy link
Contributor Author

jketema commented Nov 20, 2024

I spot checked some of the alerts that disappeared in DCA. Most of them seem to be due to

 strictcount(BasicBlock bb2 | gc.ensuresEq(_, 0, bb2, _) | bb2) = 1

And it's correct that they disappeared, because the code depends on the guard being there.

@jketema jketema merged commit b471879 into github:main Nov 20, 2024
13 checks passed
@jketema jketema deleted the guarded-free2 branch November 20, 2024 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants