|
| 1 | +import cpp |
| 2 | +import semmle.code.cpp.dataflow.new.DataFlow |
| 3 | +import semmle.code.cpp.controlflow.IRGuards |
| 4 | +import utils.test.InlineExpectationsTest |
| 5 | + |
| 6 | +predicate instructionGuardChecks(IRGuardCondition gc, Instruction checked, boolean branch) { |
| 7 | + exists(CallInstruction call | |
| 8 | + call.getStaticCallTarget().hasName("checkArgument") and |
| 9 | + checked = call.getAnArgument() and |
| 10 | + gc.comparesEq(call.getAUse(), 0, false, any(BooleanValue bv | bv.getValue() = branch)) |
| 11 | + ) |
| 12 | +} |
| 13 | + |
| 14 | +module BarrierGuard = DataFlow::InstructionBarrierGuard<instructionGuardChecks/3>; |
| 15 | + |
| 16 | +predicate indirectBarrierGuard(DataFlow::Node node, int indirectionIndex) { |
| 17 | + node = BarrierGuard::getAnIndirectBarrierNode(indirectionIndex) |
| 18 | +} |
| 19 | + |
| 20 | +predicate barrierGuard(DataFlow::Node node) { node = BarrierGuard::getABarrierNode() } |
| 21 | + |
| 22 | +module Test implements TestSig { |
| 23 | + string getARelevantTag() { result = "barrier" } |
| 24 | + |
| 25 | + predicate hasActualResult(Location location, string element, string tag, string value) { |
| 26 | + exists(DataFlow::Node node | |
| 27 | + barrierGuard(node) and |
| 28 | + value = "" |
| 29 | + or |
| 30 | + exists(int indirectionIndex | |
| 31 | + indirectBarrierGuard(node, indirectionIndex) and |
| 32 | + value = indirectionIndex.toString() |
| 33 | + ) |
| 34 | + | |
| 35 | + tag = "barrier" and |
| 36 | + element = node.toString() and |
| 37 | + location = node.getLocation() |
| 38 | + ) |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +import MakeTest<Test> |
0 commit comments