mirror of
https://github.com/github/codeql.git
synced 2025-12-21 03:06:31 +01:00
C++: Make proper use of barrier guards in test.
This commit is contained in:
@@ -7,14 +7,17 @@ module AstTest {
|
||||
* S in `if (guarded(x)) S`.
|
||||
*/
|
||||
// This is tested in `BarrierGuard.cpp`.
|
||||
predicate testBarrierGuard(GuardCondition g, Expr checked, boolean isTrue) {
|
||||
g.(FunctionCall).getTarget().getName() = "guarded" and
|
||||
checked = g.(FunctionCall).getArgument(0) and
|
||||
isTrue = true
|
||||
or
|
||||
g.(FunctionCall).getTarget().getName() = "unsafe" and
|
||||
checked = g.(FunctionCall).getArgument(0) and
|
||||
isTrue = false
|
||||
predicate testBarrierGuard(GuardCondition g, Expr checked, boolean branch) {
|
||||
exists(Call call, boolean b |
|
||||
checked = call.getArgument(0) and
|
||||
g.comparesEq(call, 0, b, any(BooleanValue bv | bv.getValue() = branch))
|
||||
|
|
||||
call.getTarget().hasName("guarded") and
|
||||
b = false
|
||||
or
|
||||
call.getTarget().hasName("unsafe") and
|
||||
b = true
|
||||
)
|
||||
}
|
||||
|
||||
/** Common data flow configuration to be used by tests. */
|
||||
@@ -106,16 +109,16 @@ module IRTest {
|
||||
* S in `if (guarded(x)) S`.
|
||||
*/
|
||||
// This is tested in `BarrierGuard.cpp`.
|
||||
predicate testBarrierGuard(IRGuardCondition g, Expr checked, boolean isTrue) {
|
||||
exists(Call call |
|
||||
call = g.getUnconvertedResultExpression() and
|
||||
checked = call.getArgument(0)
|
||||
predicate testBarrierGuard(IRGuardCondition g, Expr checked, boolean branch) {
|
||||
exists(CallInstruction call, boolean b |
|
||||
checked = call.getArgument(0).getUnconvertedResultExpression() and
|
||||
g.comparesEq(call.getAUse(), 0, b, any(BooleanValue bv | bv.getValue() = branch))
|
||||
|
|
||||
call.getTarget().hasName("guarded") and
|
||||
isTrue = true
|
||||
call.getStaticCallTarget().hasName("guarded") and
|
||||
b = false
|
||||
or
|
||||
call.getTarget().hasName("unsafe") and
|
||||
isTrue = false
|
||||
call.getStaticCallTarget().hasName("unsafe") and
|
||||
b = true
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user