mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
C++: Add a testcase that needs indirect instruction/operand nodes.
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
bool checkArgument(int* x);
|
||||
|
||||
void sink(int);
|
||||
|
||||
void testCheckArgument(int* p) {
|
||||
if (checkArgument(p)) {
|
||||
sink(*p); // $ barrier MISSING:barrier=1
|
||||
}
|
||||
}
|
||||
42
cpp/ql/test/library-tests/dataflow/ir-barrier-guards/test.ql
Normal file
42
cpp/ql/test/library-tests/dataflow/ir-barrier-guards/test.ql
Normal file
@@ -0,0 +1,42 @@
|
||||
import cpp
|
||||
import semmle.code.cpp.dataflow.new.DataFlow
|
||||
import semmle.code.cpp.controlflow.IRGuards
|
||||
import utils.test.InlineExpectationsTest
|
||||
|
||||
predicate instructionGuardChecks(IRGuardCondition gc, Instruction checked, boolean branch) {
|
||||
exists(CallInstruction call |
|
||||
call.getStaticCallTarget().hasName("checkArgument") and
|
||||
checked = call.getAnArgument() and
|
||||
gc.comparesEq(call.getAUse(), 0, false, any(BooleanValue bv | bv.getValue() = branch))
|
||||
)
|
||||
}
|
||||
|
||||
module BarrierGuard = DataFlow::InstructionBarrierGuard<instructionGuardChecks/3>;
|
||||
|
||||
predicate indirectBarrierGuard(DataFlow::Node node, int indirectionIndex) {
|
||||
node = BarrierGuard::getAnIndirectBarrierNode(indirectionIndex)
|
||||
}
|
||||
|
||||
predicate barrierGuard(DataFlow::Node node) { node = BarrierGuard::getABarrierNode() }
|
||||
|
||||
module Test implements TestSig {
|
||||
string getARelevantTag() { result = "barrier" }
|
||||
|
||||
predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||
exists(DataFlow::Node node |
|
||||
barrierGuard(node) and
|
||||
value = ""
|
||||
or
|
||||
exists(int indirectionIndex |
|
||||
indirectBarrierGuard(node, indirectionIndex) and
|
||||
value = indirectionIndex.toString()
|
||||
)
|
||||
|
|
||||
tag = "barrier" and
|
||||
element = node.toString() and
|
||||
location = node.getLocation()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
import MakeTest<Test>
|
||||
Reference in New Issue
Block a user