Skip to content

Commit f8c144b

Browse files
authored
Merge pull request #21018 from aschackmull/csharp/guards-connect-barrierguard
C#: Connect shared Guards to SSA BarrierGuards.
2 parents 6f27863 + 1142f4a commit f8c144b

File tree

1 file changed

+20
-36
lines changed
  • csharp/ql/lib/semmle/code/csharp/dataflow/internal

1 file changed

+20
-36
lines changed

csharp/ql/lib/semmle/code/csharp/dataflow/internal/SsaImpl.qll

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -967,18 +967,22 @@ private module Cached {
967967

968968
cached // nothing is actually cached
969969
module BarrierGuard<guardChecksSig/3 guardChecks> {
970-
private predicate guardChecksAdjTypes(
971-
DataFlowIntegrationInput::Guard g, DataFlowIntegrationInput::Expr e,
972-
DataFlowIntegrationInput::GuardValue branch
970+
private import codeql.util.Unit
971+
972+
private predicate guardChecksAdjTypes(Guards::Guards::Guard g, Expr e, Guards::GuardValue v) {
973+
guardChecks(g, e, v)
974+
}
975+
976+
private predicate guardChecksWithWrappers(
977+
Guards::Guard g, Definition def, Guards::GuardValue val, Unit state
973978
) {
974-
exists(Guards::GuardValue v |
975-
guardChecks(g, e.getAstNode(), v) and
976-
branch = v.asBooleanValue()
977-
)
979+
Guards::Guards::ValidationWrapper<guardChecksAdjTypes/3>::guardChecksDef(g, def, val) and
980+
exists(state)
978981
}
979982

980983
private Node getABarrierNodeImpl() {
981-
result = DataFlowIntegrationImpl::BarrierGuard<guardChecksAdjTypes/3>::getABarrierNode()
984+
result =
985+
DataFlowIntegrationImpl::BarrierGuardDefWithState<Unit, guardChecksWithWrappers/4>::getABarrierNode(_)
982986
}
983987

984988
predicate getABarrierNode = getABarrierNodeImpl/0;
@@ -1037,38 +1041,18 @@ private module DataFlowIntegrationInput implements Impl::DataFlowIntegrationInpu
10371041
)
10381042
}
10391043

1040-
class GuardValue = Boolean;
1044+
class GuardValue = Guards::GuardValue;
10411045

1042-
class Guard extends Guards::Guard {
1043-
/**
1044-
* Holds if the evaluation of this guard to `branch` corresponds to the edge
1045-
* from `bb1` to `bb2`.
1046-
*/
1047-
predicate hasValueBranchEdge(BasicBlock bb1, BasicBlock bb2, GuardValue branch) {
1048-
exists(ControlFlow::ConditionalSuccessor s |
1049-
this.getAControlFlowNode() = bb1.getLastNode() and
1050-
bb2 = bb1.getASuccessor(s) and
1051-
s.getValue() = branch
1052-
)
1053-
}
1046+
class Guard = Guards::Guard;
10541047

1055-
/**
1056-
* Holds if this guard evaluating to `branch` controls the control-flow
1057-
* branch edge from `bb1` to `bb2`. That is, following the edge from
1058-
* `bb1` to `bb2` implies that this guard evaluated to `branch`.
1059-
*/
1060-
predicate valueControlsBranchEdge(BasicBlock bb1, BasicBlock bb2, GuardValue branch) {
1061-
this.hasValueBranchEdge(bb1, bb2, branch)
1062-
}
1048+
/** Holds if the guard `guard` directly controls block `bb` upon evaluating to `val`. */
1049+
predicate guardDirectlyControlsBlock(Guard guard, BasicBlock bb, GuardValue val) {
1050+
guard.directlyValueControls(bb, val)
10631051
}
10641052

1065-
/** Holds if the guard `guard` controls block `bb` upon evaluating to `branch`. */
1066-
predicate guardDirectlyControlsBlock(Guard guard, ControlFlow::BasicBlock bb, GuardValue branch) {
1067-
exists(ConditionBlock conditionBlock, ControlFlow::ConditionalSuccessor s |
1068-
guard.getAControlFlowNode() = conditionBlock.getLastNode() and
1069-
s.getValue() = branch and
1070-
conditionBlock.edgeDominates(bb, s)
1071-
)
1053+
/** Holds if the guard `guard` controls block `bb` upon evaluating to `val`. */
1054+
predicate guardControlsBlock(Guard guard, BasicBlock bb, GuardValue val) {
1055+
guard.valueControls(bb, val)
10721056
}
10731057
}
10741058

0 commit comments

Comments
 (0)