|
1 | 1 | import TestUtilities.dataflow.FlowTestCommon |
2 | 2 |
|
| 3 | +module AstTest { |
| 4 | + private import semmle.code.cpp.dataflow.old.DataFlow |
| 5 | + private import semmle.code.cpp.controlflow.Guards |
| 6 | + |
| 7 | + /** |
| 8 | + * A `BarrierGuard` that stops flow to all occurrences of `x` within statement |
| 9 | + * S in `if (guarded(x)) S`. |
| 10 | + */ |
| 11 | + // This is tested in `BarrierGuard.cpp`. |
| 12 | + predicate testBarrierGuard(GuardCondition g, Expr checked, boolean isTrue) { |
| 13 | + g.(FunctionCall).getTarget().getName() = "guarded" and |
| 14 | + checked = g.(FunctionCall).getArgument(0) and |
| 15 | + isTrue = true |
| 16 | + } |
| 17 | + |
| 18 | + /** Common data flow configuration to be used by tests. */ |
| 19 | + class AstTestAllocationConfig extends DataFlow::Configuration { |
| 20 | + AstTestAllocationConfig() { this = "ASTTestAllocationConfig" } |
| 21 | + |
| 22 | + override predicate isSource(DataFlow::Node source) { |
| 23 | + source.asExpr().(FunctionCall).getTarget().getName() = "source" |
| 24 | + or |
| 25 | + source.asParameter().getName().matches("source%") |
| 26 | + or |
| 27 | + source.(DataFlow::DefinitionByReferenceNode).getParameter().getName().matches("ref_source%") |
| 28 | + or |
| 29 | + // Track uninitialized variables |
| 30 | + exists(source.asUninitialized()) |
| 31 | + } |
| 32 | + |
| 33 | + override predicate isSink(DataFlow::Node sink) { |
| 34 | + exists(FunctionCall call | |
| 35 | + call.getTarget().getName() = "sink" and |
| 36 | + sink.asExpr() = call.getAnArgument() |
| 37 | + ) |
| 38 | + } |
| 39 | + |
| 40 | + override predicate isBarrier(DataFlow::Node barrier) { |
| 41 | + barrier.asExpr().(VariableAccess).getTarget().hasName("barrier") or |
| 42 | + barrier = DataFlow::BarrierGuard<testBarrierGuard/3>::getABarrierNode() |
| 43 | + } |
| 44 | + } |
| 45 | +} |
| 46 | + |
3 | 47 | module IRTest { |
4 | 48 | private import semmle.code.cpp.ir.dataflow.DataFlow |
5 | 49 | private import semmle.code.cpp.ir.IR |
|
0 commit comments