-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathVoidContext.qll
More file actions
42 lines (39 loc) · 1.27 KB
/
VoidContext.qll
File metadata and controls
42 lines (39 loc) · 1.27 KB
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
32
33
34
35
36
37
38
39
40
41
42
import semmle.code.cpp.exprs.Expr
/**
* An expression that is used to qualify some other expression.
*/
class Qualifier extends Expr {
Qualifier() {
exists(VariableAccess a | a.getQualifier() = this) or
exists(Call c | c.getQualifier() = this) or
exists(VacuousDestructorCall v | v.getQualifier() = this)
}
}
/**
* An expression that occurs in a void context, i.e. either as the toplevel expression of
* an expression statement or on the left hand side of the comma operator.
*
* Expressions that are explicitly cast to void are not considered to be in void context.
*/
class ExprInVoidContext extends Expr {
ExprInVoidContext() { exprInVoidContext(this) }
}
private predicate exprInVoidContext(Expr e) {
(
exists(ExprStmt s |
s = e.getParent() and
not exists(StmtExpr se | s = se.getStmt().(BlockStmt).getLastStmt())
)
or
exists(ConditionalExpr c | c.getThen() = e and c instanceof ExprInVoidContext)
or
exists(ConditionalExpr c | c.getElse() = e and c instanceof ExprInVoidContext)
or
exists(CommaExpr c | c.getLeftOperand() = e)
or
exists(CommaExpr c | c.getRightOperand() = e and c instanceof ExprInVoidContext)
or
exists(ForStmt for | for.getUpdate() = e)
) and
not e.getActualType() instanceof VoidType
}