mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Merge pull request #10510 from geoffw0/staticfn
C++: Fix FPs for cpp/unused-static-function in files that were not extracted completely
This commit is contained in:
@@ -13,16 +13,32 @@
|
|||||||
|
|
||||||
import cpp
|
import cpp
|
||||||
|
|
||||||
|
pragma[noinline]
|
||||||
|
predicate possiblyIncompleteFile(File f) {
|
||||||
|
exists(Diagnostic d | d.getFile() = f and d.getSeverity() >= 3)
|
||||||
|
}
|
||||||
|
|
||||||
predicate immediatelyReachableFunction(Function f) {
|
predicate immediatelyReachableFunction(Function f) {
|
||||||
not f.isStatic() or
|
not f.isStatic()
|
||||||
exists(BlockExpr be | be.getFunction() = f) or
|
or
|
||||||
f instanceof MemberFunction or
|
exists(BlockExpr be | be.getFunction() = f)
|
||||||
f instanceof TemplateFunction or
|
or
|
||||||
f.getFile() instanceof HeaderFile or
|
f instanceof MemberFunction
|
||||||
f.getAnAttribute().hasName("constructor") or
|
or
|
||||||
f.getAnAttribute().hasName("destructor") or
|
f instanceof TemplateFunction
|
||||||
f.getAnAttribute().hasName("used") or
|
or
|
||||||
|
f.getFile() instanceof HeaderFile
|
||||||
|
or
|
||||||
|
f.getAnAttribute().hasName("constructor")
|
||||||
|
or
|
||||||
|
f.getAnAttribute().hasName("destructor")
|
||||||
|
or
|
||||||
|
f.getAnAttribute().hasName("used")
|
||||||
|
or
|
||||||
f.getAnAttribute().hasName("unused")
|
f.getAnAttribute().hasName("unused")
|
||||||
|
or
|
||||||
|
// a compiler error in the same file suggests we may be missing data
|
||||||
|
possiblyIncompleteFile(f.getFile())
|
||||||
}
|
}
|
||||||
|
|
||||||
predicate immediatelyReachableVariable(Variable v) {
|
predicate immediatelyReachableVariable(Variable v) {
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
---
|
||||||
|
category: minorAnalysis
|
||||||
|
---
|
||||||
|
* Fixed false positives from the "Unused static function" (`cpp/unused-static-function`) query in files that had errors during compilation.
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
// semmle-extractor-options: --expect_errors
|
||||||
|
|
||||||
|
static void my_function1_called() {} // GOOD
|
||||||
|
static void my_function2_called_after_error() {} // GOOD
|
||||||
|
static void my_function3_not_called() {} // BAD [NOT DETECTED]
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
my_function1_called();
|
||||||
|
|
||||||
|
--- compilation stops here because this line is not valid C code ---
|
||||||
|
|
||||||
|
my_function2_called_after_error();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -33,3 +33,16 @@ static void f6(void);
|
|||||||
static void f5(void) { f6(); }
|
static void f5(void) { f6(); }
|
||||||
static void f6(void) { f5(); }
|
static void f6(void) { f5(); }
|
||||||
|
|
||||||
|
// f7 and f8 are reachable from `function_caller`
|
||||||
|
static int f7() { return 1; } // GOOD
|
||||||
|
static void f8() { } // GOOD
|
||||||
|
|
||||||
|
void function_caller()
|
||||||
|
{
|
||||||
|
auto my_lambda = []() {
|
||||||
|
return f7();
|
||||||
|
}();
|
||||||
|
|
||||||
|
f8();
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user