Fix RULE-0-2-4/A0-1-3 false positives for private functions - #1169
Fix RULE-0-2-4/A0-1-3 false positives for private functions#1169castler wants to merge 1 commit into
Conversation
d16c650 to
f7d8332
Compare
|
Mostly looks good! I just wanted to say I couldn't reproduce this issue: and I couldn't get these I tried to get the eclipse/communication project database to confirm the difference myself, but I ran into issues there that I'll have to figure out. It looked somewhat like the database I got was maybe built with the wrong CodeQL version, though I looked through the project and saw it looked like you're using the correct version everywhere, so I'm not totally sure why I was seeing issues on my side. I also don't see exactly how the Thank you for the PR! |
To be frank, we used the wrong CodeQL version for some amount of time. Maybe you had a CodeQL database from that? But since around a month (https://github.com/eclipse-score/communication/pull/757/changes#diff-6136fc12446089c3db7360e923203dd114b6a1466252e71667c6791c20fe6bdcL440) we should use the correct one. Regarding your finding - I have to apologize - I think you are right. |
|
Thanks @castler, that would plausibly explain it. I'm definitely not against merging, since these fixes are not harmful, if we find that the mystery continues. 👍 |
f7d8332 to
80fb9f6
Compare
80fb9f6 to
a4d1d82
Compare
@MichaelRFairhurst I tried to revisit this topic from ground. I think the changes for the pure-virtual interface are valid, but I am not to sure about: https://github.com/github/codeql-coding-standards/pull/1169/changes#diff-67e20819af17d4736a107e5c7147cf6c52cd27479b579c9a96a26adc004feb39R186-R187 producing false negatives? But I also have no clue how I could test this right now. |
Two categories of false positive are addressed: 1. **Pure virtual private member functions** — RULE-0-2-4 and A0-1-3 require that private member functions be *used*. A pure virtual function (`= 0`) is an interface contract that must be overridden by derived classes; it has no body of its own and cannot be "called" directly. Excluding `PureVirtualFunction` from the `LocalFunction` class prevents spurious reports on these. 2. **Private members of never-instantiated class templates** — when a class template is never instantiated with a concrete type anywhere in the analyzed compilation units, Clang never elaborates a body for its member functions, so `Call`/`FunctionCall` targets within that pattern's own text cannot be resolved by `DynamicCallGraph::getTarget()` or `VirtualDispatch`, even for calls between sibling members of the very same class (e.g. a public entry point calling a private helper). This is common for CRTP-style wrappers that is only ever instantiated by downstream consumers outside of the analyzed codebase. The new `hasNoVisibleInstantiation(fn)` predicate conservatively treats such private members as "used" (out of scope for this analysis) rather than reporting them as dead code — but only when *no* sibling member of the same class-template pattern has any instantiation either, so genuinely dead private helpers in class templates that *are* instantiated elsewhere are still correctly reported. Fixes github#1168
Description
Two categories of false positive are addressed:
Pure virtual private member functions — RULE-0-2-4 and A0-1-3
require that private member functions be used. A pure virtual
function (
= 0) is an interface contract that must be overriddenby derived classes; it has no body of its own and cannot be
"called" directly. Excluding
PureVirtualFunctionfrom theLocalFunctionclass prevents spurious reports on these.Private members of never-instantiated class templates — when a
class template is never instantiated with a concrete type anywhere
in the analyzed compilation units, Clang never elaborates a body for
its member functions, so
Call/FunctionCalltargets within thatpattern's own text cannot be resolved by
DynamicCallGraph::getTarget()orVirtualDispatch, even for callsbetween sibling members of the very same class (e.g. a public entry
point calling a private helper). This is common for CRTP-style wrappers
that is only ever instantiated by
downstream consumers outside of the analyzed codebase. The new
hasNoVisibleInstantiation(fn)predicate conservatively treats suchprivate members as "used" (out of scope for this analysis) rather
than reporting them as dead code — but only when no sibling member
of the same class-template pattern has any instantiation either, so
genuinely dead private helpers in class templates that are
instantiated elsewhere are still correctly reported.
Fixes #1168
Change request type
.ql,.qll,.qlsor unit tests)Rules with added or modified queries
Release change checklist
A change note (development_handbook.md#change-notes) is required for any pull request which modifies:
If you are only adding new rule queries, a change note is not required.
Author: Is a change note required?
🚨🚨🚨
Reviewer: Confirm that format of shared queries (not the .qll file, the
.ql file that imports it) is valid by running them within VS Code.
Reviewer: Confirm that either a change note is not required or the change note is required and has been added.
Query development review checklist
For PRs that add new queries or modify existing queries, the following checklist should be completed by both the author and reviewer:
Author
As a rule of thumb, predicates specific to the query should take no more than 1 minute, and for simple queries be under 10 seconds. If this is not the case, this should be highlighted and agreed in the code review process.
Reviewer
As a rule of thumb, predicates specific to the query should take no more than 1 minute, and for simple queries be under 10 seconds. If this is not the case, this should be highlighted and agreed in the code review process.