mirror of
https://github.com/github/codeql.git
synced 2026-01-06 19:20:25 +01:00
41 lines
1.3 KiB
Plaintext
41 lines
1.3 KiB
Plaintext
import cpp
|
|
import TestUtilities.InlineExpectationsTest
|
|
import semmle.code.cpp.dataflow.new.DataFlow::DataFlow
|
|
|
|
bindingset[s]
|
|
string quote(string s) { if s.matches("% %") then result = "\"" + s + "\"" else result = s }
|
|
|
|
string formatNumberOfNodesForIndirectExpr(Expr e) {
|
|
exists(int n | n = strictcount(Node node | node.asIndirectExpr() = e) |
|
|
n > 1 and result = ": " + n
|
|
)
|
|
}
|
|
|
|
module AsIndirectExprTest implements TestSig {
|
|
string getARelevantTag() { result = ["asIndirectExpr", "numberOfIndirectNodes"] }
|
|
|
|
predicate hasActualResult(Location location, string element, string tag, string value) {
|
|
exists(Node n, Expr e, string exprString |
|
|
e = n.asIndirectExpr() and
|
|
location = e.getLocation() and
|
|
element = n.toString() and
|
|
exprString = e.toString()
|
|
|
|
|
tag = "asIndirectExpr" and
|
|
(
|
|
// The toString on an indirect is often formatted like `***myExpr`.
|
|
// If the node's `toString` is of that form then we don't show it in
|
|
// the expected output.
|
|
if element.matches("%" + exprString)
|
|
then value = quote(exprString)
|
|
else value = quote(exprString + "(" + element + ")")
|
|
)
|
|
or
|
|
tag = "numberOfIndirectNodes" and
|
|
value = quote(exprString + formatNumberOfNodesForIndirectExpr(e))
|
|
)
|
|
}
|
|
}
|
|
|
|
import MakeTest<AsIndirectExprTest>
|