C++: Make proper use of barrier guards in test.

This commit is contained in:
Mathias Vorreiter Pedersen
2024-06-06 20:38:17 +01:00
parent 7b92554cf2
commit b5a3575130

View File

@@ -7,14 +7,17 @@ module AstTest {
* S in `if (guarded(x)) S`. * S in `if (guarded(x)) S`.
*/ */
// This is tested in `BarrierGuard.cpp`. // This is tested in `BarrierGuard.cpp`.
predicate testBarrierGuard(GuardCondition g, Expr checked, boolean isTrue) { predicate testBarrierGuard(GuardCondition g, Expr checked, boolean branch) {
g.(FunctionCall).getTarget().getName() = "guarded" and exists(Call call, boolean b |
checked = g.(FunctionCall).getArgument(0) and checked = call.getArgument(0) and
isTrue = true g.comparesEq(call, 0, b, any(BooleanValue bv | bv.getValue() = branch))
or |
g.(FunctionCall).getTarget().getName() = "unsafe" and call.getTarget().hasName("guarded") and
checked = g.(FunctionCall).getArgument(0) and b = false
isTrue = false or
call.getTarget().hasName("unsafe") and
b = true
)
} }
/** Common data flow configuration to be used by tests. */ /** Common data flow configuration to be used by tests. */
@@ -106,16 +109,16 @@ module IRTest {
* S in `if (guarded(x)) S`. * S in `if (guarded(x)) S`.
*/ */
// This is tested in `BarrierGuard.cpp`. // This is tested in `BarrierGuard.cpp`.
predicate testBarrierGuard(IRGuardCondition g, Expr checked, boolean isTrue) { predicate testBarrierGuard(IRGuardCondition g, Expr checked, boolean branch) {
exists(Call call | exists(CallInstruction call, boolean b |
call = g.getUnconvertedResultExpression() and checked = call.getArgument(0).getUnconvertedResultExpression() and
checked = call.getArgument(0) g.comparesEq(call.getAUse(), 0, b, any(BooleanValue bv | bv.getValue() = branch))
| |
call.getTarget().hasName("guarded") and call.getStaticCallTarget().hasName("guarded") and
isTrue = true b = false
or or
call.getTarget().hasName("unsafe") and call.getStaticCallTarget().hasName("unsafe") and
isTrue = false b = true
) )
} }