Skip to content

Commit 4763312

Browse files
committed
Merge ConditionBlock and BarrierGuard
1 parent 6f32401 commit 4763312

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

ql/lib/codeql/ruby/dataflow/internal/DataFlowPublic.qll

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -160,31 +160,26 @@ class Content extends TContent {
160160
}
161161

162162
/**
163-
* A node that controls whether other nodes are evaluated.
163+
* A guard that validates some expression.
164+
*
165+
* To use this in a configuration, extend the class and provide a
166+
* characteristic predicate precisely specifying the guard, and override
167+
* `checks` to specify what is being validated and in which branch.
168+
*
169+
* It is important that all extending classes in scope are disjoint.
164170
*/
165-
class GuardNode extends CfgNodes::ExprCfgNode {
166-
ConditionBlock conditionBlock;
171+
abstract class BarrierGuard extends CfgNodes::ExprCfgNode {
172+
private ConditionBlock conditionBlock;
167173

168-
GuardNode() { this = conditionBlock.getLastNode() }
174+
BarrierGuard() { this = conditionBlock.getLastNode() }
169175

170176
/** Holds if this guard controls block `b` upon evaluating to `branch`. */
171-
predicate controlsBlock(BasicBlock bb, boolean branch) {
177+
private predicate controlsBlock(BasicBlock bb, boolean branch) {
172178
exists(SuccessorTypes::BooleanSuccessor s | s.getValue() = branch |
173179
conditionBlock.controls(bb, s)
174180
)
175181
}
176-
}
177182

178-
/**
179-
* A guard that validates some expression.
180-
*
181-
* To use this in a configuration, extend the class and provide a
182-
* characteristic predicate precisely specifying the guard, and override
183-
* `checks` to specify what is being validated and in which branch.
184-
*
185-
* It is important that all extending classes in scope are disjoint.
186-
*/
187-
abstract class BarrierGuard extends GuardNode {
188183
/**
189184
* Holds if this guard validates `expr` upon evaluating to `branch`.
190185
* For example, the following code validates `foo` when the condition

ql/test/library-tests/dataflow/barrier-guards/barrier-guards.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
unless foo != "foo"
2828
foo
29+
else
30+
foo
2931
end
3032

3133
foo

0 commit comments

Comments
 (0)