Merge ConditionBlock and BarrierGuard

This commit is contained in:
Harry Maclean
2021-09-14 11:11:12 +01:00
parent 6f32401e5c
commit 4763312e55
2 changed files with 14 additions and 17 deletions

View File

@@ -159,22 +159,6 @@ class Content extends TContent {
Location getLocation() { none() }
}
/**
* A node that controls whether other nodes are evaluated.
*/
class GuardNode extends CfgNodes::ExprCfgNode {
ConditionBlock conditionBlock;
GuardNode() { this = conditionBlock.getLastNode() }
/** Holds if this guard controls block `b` upon evaluating to `branch`. */
predicate controlsBlock(BasicBlock bb, boolean branch) {
exists(SuccessorTypes::BooleanSuccessor s | s.getValue() = branch |
conditionBlock.controls(bb, s)
)
}
}
/**
* A guard that validates some expression.
*
@@ -184,7 +168,18 @@ class GuardNode extends CfgNodes::ExprCfgNode {
*
* It is important that all extending classes in scope are disjoint.
*/
abstract class BarrierGuard extends GuardNode {
abstract class BarrierGuard extends CfgNodes::ExprCfgNode {
private ConditionBlock conditionBlock;
BarrierGuard() { this = conditionBlock.getLastNode() }
/** Holds if this guard controls block `b` upon evaluating to `branch`. */
private predicate controlsBlock(BasicBlock bb, boolean branch) {
exists(SuccessorTypes::BooleanSuccessor s | s.getValue() = branch |
conditionBlock.controls(bb, s)
)
}
/**
* Holds if this guard validates `expr` upon evaluating to `branch`.
* For example, the following code validates `foo` when the condition

View File

@@ -26,6 +26,8 @@ end
unless foo != "foo"
foo
else
foo
end
foo