Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,33 @@

import cpp

predicate possiblyIncompleteFile(File f) {
Comment thread
geoffw0 marked this conversation as resolved.
exists(Diagnostic d | d.getFile() = f and d.getSeverity() >= 3)
or
exists(ErrorExpr ee | ee.getFile() = f)
Comment thread
geoffw0 marked this conversation as resolved.
Outdated
}

predicate immediatelyReachableFunction(Function f) {
not f.isStatic() or
exists(BlockExpr be | be.getFunction() = f) or
f instanceof MemberFunction or
f instanceof TemplateFunction or
f.getFile() instanceof HeaderFile or
f.getAnAttribute().hasName("constructor") or
f.getAnAttribute().hasName("destructor") or
f.getAnAttribute().hasName("used") or
not f.isStatic()
or
exists(BlockExpr be | be.getFunction() = f)
or
f instanceof MemberFunction
or
f instanceof TemplateFunction
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")
or
// a compiler error in the same file suggests we may be missing data
possiblyIncompleteFile(f.getFile())
}

predicate immediatelyReachableVariable(Variable v) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
@@ -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;
}