forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathidentity_string.ql
More file actions
79 lines (62 loc) · 2.33 KB
/
identity_string.ql
File metadata and controls
79 lines (62 loc) · 2.33 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import cpp
import semmle.code.cpp.Print
abstract class CheckCall extends FunctionCall {
abstract string getActualString();
final string getExpectedString() {
exists(int lastArgIndex |
lastArgIndex = getNumberOfArguments() - 1 and
(
result = getArgument(lastArgIndex).getValue()
or
not exists(getArgument(lastArgIndex).getValue()) and result = "<missing>"
)
)
}
abstract string explain();
}
class CheckTypeCall extends CheckCall {
CheckTypeCall() {
getTarget().(FunctionTemplateInstantiation).getTemplate().hasGlobalName("check_type")
}
override string getActualString() {
result = getTypeIdentityString(getSpecifiedType())
or
not exists(getTypeIdentityString(getSpecifiedType())) and result = "<missing>"
}
override string explain() { result = getSpecifiedType().explain() }
final Type getSpecifiedType() { result = getTarget().getTemplateArgument(0) }
}
class CheckFuncCall extends CheckCall {
CheckFuncCall() {
getTarget().(FunctionTemplateInstantiation).getTemplate().hasGlobalName("check_func")
}
override string getActualString() {
result = getIdentityString(getSpecifiedFunction())
or
not exists(getIdentityString(getSpecifiedFunction())) and result = "<missing>"
}
override string explain() { result = getSpecifiedFunction().toString() }
final Function getSpecifiedFunction() { result = getArgument(0).(FunctionAccess).getTarget() }
}
class CheckVarCall extends CheckCall {
CheckVarCall() {
getTarget().(FunctionTemplateInstantiation).getTemplate().hasGlobalName("check_var")
}
override string getActualString() {
result = getIdentityString(getSpecifiedVariable())
or
not exists(getIdentityString(getSpecifiedVariable())) and result = "<missing>"
}
override string explain() { result = getSpecifiedVariable().toString() }
final Variable getSpecifiedVariable() { result = getArgument(0).(VariableAccess).getTarget() }
}
bindingset[s]
private string normalizeLambdas(string s) {
result = s.regexpReplaceAll("line \\d+, col\\. \\d+", "line ?, col. ?")
}
from CheckCall call, string expected, string actual
where
expected = call.getExpectedString() and
actual = normalizeLambdas(call.getActualString()) and
expected != actual
select call, "Expected: '" + expected + "'", "Actual: '" + actual + "'", call.explain()