55private import python
66private import DataFlowPrivate
77import experimental.dataflow.TypeTracker
8+ private import semmle.python.essa.SsaCompute
89
910/**
1011 * IPA type for data flow nodes.
@@ -148,6 +149,18 @@ class ParameterNode extends EssaNode {
148149 override DataFlowCallable getEnclosingCallable ( ) { this .isParameterOf ( result , _) }
149150}
150151
152+ /**
153+ * A node that controls whether other nodes are evaluated.
154+ */
155+ class GuardNode extends ControlFlowNode {
156+ ConditionBlock conditionBlock ;
157+
158+ GuardNode ( ) { this = conditionBlock .getLastNode ( ) }
159+
160+ /** Holds if this guard controls block `b` upon evaluating to `branch`. */
161+ predicate controlsBlock ( BasicBlock b , boolean branch ) { conditionBlock .controls ( b , branch ) }
162+ }
163+
151164/**
152165 * A guard that validates some expression.
153166 *
@@ -157,16 +170,18 @@ class ParameterNode extends EssaNode {
157170 *
158171 * It is important that all extending classes in scope are disjoint.
159172 */
160- class BarrierGuard extends Expr {
161- // /** Holds if this guard validates `e` upon evaluating to `v`. */
162- // abstract predicate checks(Expr e, AbstractValue v);
173+ class BarrierGuard extends GuardNode {
174+ /** Holds if this guard validates `node` upon evaluating to `branch`. */
175+ abstract predicate checks ( ControlFlowNode node , boolean branch ) ;
176+
163177 /** Gets a node guarded by this guard. */
164178 final ExprNode getAGuardedNode ( ) {
165- none ( )
166- // exists(Expr e, AbstractValue v |
167- // this.checks(e, v) and
168- // this.controlsNode(result.getControlFlowNode(), e, v)
169- // )
179+ exists ( EssaDefinition def , ControlFlowNode node , boolean branch |
180+ AdjacentUses:: useOfDef ( def , node ) and
181+ this .checks ( node , branch ) and
182+ AdjacentUses:: useOfDef ( def , result .asCfgNode ( ) ) and
183+ this .controlsBlock ( result .asCfgNode ( ) .getBasicBlock ( ) , branch )
184+ )
170185 }
171186}
172187
0 commit comments