@@ -5,6 +5,7 @@ overlay[local?]
55module ;
66
77private import go
8+ private import semmle.go.controlflow.Guards
89private import semmle.go.dataflow.FunctionInputsAndOutputs
910private import semmle.go.dataflow.ExternalFlow
1011private import DataFlowPrivate
@@ -388,51 +389,47 @@ module BarrierGuard<guardChecksSig/3 guardChecks> {
388389module ParameterizedBarrierGuard< ParamSig P, WithParam< P > :: guardChecksSig / 4 guardChecks> {
389390 /** Gets a node that is safely guarded by the given guard check. */
390391 Node getABarrierNode ( P param ) {
391- exists ( ControlFlow :: ConditionGuardNode guard , SsaWithFields var |
392+ exists ( Guard guard , boolean branch , SsaWithFields var |
392393 result = pragma [ only_bind_out ] ( var ) .getAUse ( )
393394 |
394- guards ( _, guard , _, var , param ) and
395- pragma [ only_bind_out ] ( guard ) .dominates ( result .getBasicBlock ( ) )
395+ guards ( _, guard , branch , _, var , param ) and
396+ pragma [ only_bind_out ] ( guard ) .controls ( result .getBasicBlock ( ) , branch )
396397 )
397398 }
398399
399400 /**
400401 * Gets a node that is safely guarded by the given guard check.
401402 */
402403 Node getABarrierNodeForGuard ( Node guardCheck , P param ) {
403- exists ( ControlFlow :: ConditionGuardNode guard , SsaWithFields var | result = var .getAUse ( ) |
404- guards ( guardCheck , guard , _, var , param ) and
405- guard .dominates ( result .getBasicBlock ( ) )
404+ exists ( Guard guard , boolean branch , SsaWithFields var | result = var .getAUse ( ) |
405+ guards ( guardCheck , guard , branch , _, var , param ) and
406+ guard .controls ( result .getBasicBlock ( ) , branch )
406407 )
407408 }
408409
409410 /**
410- * Holds if `guard` marks a point in the control-flow graph where `g`
411- * is known to validate `nd`, which is represented by `ap`.
411+ * Holds if `guard` evaluating to `branch` marks a point in the control-flow
412+ * graph where `g` is known to validate `nd`, which is represented by `ap`.
412413 *
413414 * This predicate exists to enforce a good join order in `getAGuardedNode`.
414415 */
415416 pragma [ noinline]
416- private predicate guards (
417- Node g , ControlFlow:: ConditionGuardNode guard , Node nd , SsaWithFields ap , P param
418- ) {
419- guards ( g , guard , nd , param ) and nd = ap .getAUse ( )
417+ private predicate guards ( Node g , Guard guard , boolean branch , Node nd , SsaWithFields ap , P param ) {
418+ guards ( g , guard , branch , nd , param ) and nd = ap .getAUse ( )
420419 }
421420
422421 /**
423- * Holds if `guard` marks a point in the control-flow graph where `g`
424- * is known to validate `nd`.
422+ * Holds if `guard` evaluating to `branch` marks a point in the control-flow
423+ * graph where `g` is known to validate `nd`.
425424 */
426- private predicate guards ( Node g , ControlFlow:: ConditionGuardNode guard , Node nd , P param ) {
427- exists ( boolean branch |
428- guardChecks ( g , nd .asExpr ( ) , branch , param ) and
429- guard .ensures ( g , branch )
430- )
425+ private predicate guards ( Node g , Guard guard , boolean branch , Node nd , P param ) {
426+ guardChecks ( g , nd .asExpr ( ) , branch , param ) and
427+ guard = g .asExpr ( )
431428 or
432- exists ( DataFlow:: Property p , Node resNode , Node check , boolean outcome |
429+ exists ( DataFlow:: Property p , Node resNode , Node check |
433430 guardingCall ( g , _, _, _, p , _, nd , resNode , param ) and
434- p .checkOn ( check , outcome , resNode ) and
435- guard . ensures ( pragma [ only_bind_into ] ( check ) , outcome )
431+ p .checkOn ( check , branch , resNode ) and
432+ guard = pragma [ only_bind_into ] ( check ) . asExpr ( )
436433 )
437434 }
438435
@@ -487,9 +484,9 @@ module ParameterizedBarrierGuard<ParamSig P, WithParam<P>::guardChecksSig/4 guar
487484 localFlow ( inp .getExitNode ( fd ) , pragma [ only_bind_out ] ( arg ) ) and
488485 (
489486 // Case: a function like "if someBarrierGuard(arg) { return true } else { return false }"
490- exists ( ControlFlow :: ConditionGuardNode guard |
491- guards ( g , pragma [ only_bind_out ] ( guard ) , arg , param ) and
492- guard .dominates ( pragma [ only_bind_out ] ( ret ) .getBasicBlock ( ) )
487+ exists ( Guard guard , boolean branch |
488+ guards ( g , pragma [ only_bind_out ] ( guard ) , branch , arg , param ) and
489+ guard .controls ( pragma [ only_bind_out ] ( ret ) .getBasicBlock ( ) , branch )
493490 |
494491 onlyPossibleReturnSatisfyingProperty ( fd , outp , ret , p )
495492 )
0 commit comments