-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18486 from MathiasVP/indirect-instruction-barriers
C++: Add a `BarrierGuard` module for indirect instruction/operand nodes.
- Loading branch information
Showing
5 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
cpp/ql/lib/change-notes/2025-01-13-indirect-instruction-barrier-guard.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
category: feature | ||
--- | ||
* Add a new predicate `getAnIndirectBarrier` to the parameterized module `InstructionBarrierGuard` in `semmle.code.cpp.dataflow.new.DataFlow` for computing indirect dataflow nodes that are guarded by a given instruction. This predicate is similar to the `getAnIndirectBarrier` predicate on the parameterized module `BarrierGuard`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
cpp/ql/test/library-tests/dataflow/ir-barrier-guards/test.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
bool checkArgument(int* x); | ||
|
||
void sink(int); | ||
|
||
void testCheckArgument(int* p) { | ||
if (checkArgument(p)) { | ||
sink(*p); // $ barrier barrier=1 | ||
} | ||
} |
Empty file.
42 changes: 42 additions & 0 deletions
42
cpp/ql/test/library-tests/dataflow/ir-barrier-guards/test.ql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |