-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathAV Rule 186.ql
More file actions
31 lines (26 loc) · 841 Bytes
/
AV Rule 186.ql
File metadata and controls
31 lines (26 loc) · 841 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* @name AV Rule 186
* @description There shall be no unreachable code.
* @kind problem
* @id cpp/jsf/av-rule-186
* @problem.severity recommendation
* @tags maintainability
* useless-code
* external/jsf
*/
import cpp
// whether f is to be considered an API entry point, and hence reachable by default
predicate isApi(Function f) {
f.hasName("main") or
f.(MemberFunction).hasSpecifier("public")
}
predicate unusedFunction(Function f) {
not isApi(f) and
not exists(FunctionCall c | c.getTarget() = f) and
not exists(Access acc | acc.getTarget() = f) and
f.hasDefinition()
}
predicate unreachableStmt(Stmt s) { not s.getControlFlowScope().getBlock().getASuccessor*() = s }
from ControlFlowNode n
where unreachableStmt(n) or unusedFunction(n)
select n, "AV Rule 186: There shall be no unreachable code."