C++: Add a new test that demonstrates multiple out nodes.

This commit is contained in:
Mathias Vorreiter Pedersen
2023-02-09 16:23:32 +00:00
parent 946e301ed6
commit 7439de37a3
2 changed files with 49 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
| dispatch.cpp:60:18:60:29 | Call: new | Unexpected result: ir-count(indirect return)=3 |
| dispatch.cpp:61:18:61:29 | Call: new | Unexpected result: ir-count(indirect return)=3 |
| dispatch.cpp:65:10:65:21 | Call: new | Unexpected result: ir-count(indirect return)=3 |

View File

@@ -0,0 +1,46 @@
import TestUtilities.InlineExpectationsTest
import cpp
module AstTest {
private import semmle.code.cpp.dataflow.old.DataFlow::DataFlow
private import semmle.code.cpp.dataflow.old.internal.DataFlowPrivate
class ASTMultipleOutNodesTest extends InlineExpectationsTest {
ASTMultipleOutNodesTest() { this = "ASTMultipleOutNodesTest" }
override string getARelevantTag() { result = "ast-count(" + any(ReturnKind k).toString() + ")" }
override predicate hasActualResult(Location location, string element, string tag, string value) {
exists(DataFlowCall call, int n, ReturnKind kind |
call.getLocation() = location and
n = strictcount(getAnOutNode(call, kind)) and
n > 1 and
element = call.toString() and
tag = "ast-count(" + kind.toString() + ")" and
value = n.toString()
)
}
}
}
module IRTest {
private import semmle.code.cpp.ir.dataflow.DataFlow
private import semmle.code.cpp.ir.dataflow.internal.DataFlowPrivate
class IRMultipleOutNodesTest extends InlineExpectationsTest {
IRMultipleOutNodesTest() { this = "IRMultipleOutNodesTest" }
override string getARelevantTag() { result = "ir-count(" + any(ReturnKind k).toString() + ")" }
override predicate hasActualResult(Location location, string element, string tag, string value) {
exists(DataFlowCall call, int n, ReturnKind kind |
call.getLocation() = location and
n = strictcount(getAnOutNode(call, kind)) and
n > 1 and
element = call.toString() and
tag = "ir-count(" + kind.toString() + ")" and
value = n.toString()
)
}
}
}