Skip to content

Commit 072166b

Browse files
committed
C#/Java: Adjust Guards instantiations.
1 parent 48785a0 commit 072166b

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

  • csharp/ql/lib/semmle/code/csharp/controlflow
  • java/ql/lib/semmle/code/java/controlflow

csharp/ql/lib/semmle/code/csharp/controlflow/Guards.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ private module GuardsInput implements SharedGuards::InputSig<Location, ControlFl
8585

8686
predicate matchEdge(BasicBlock bb1, BasicBlock bb2) {
8787
bb1.getASuccessor(any(MatchingSuccessor s | s.getValue() = true)) = bb2 and
88-
bb1.getLastNode() = AstNode.super.getControlFlowNode()
88+
bb1.getLastNode() = super.getPattern().getControlFlowNode()
8989
}
9090

9191
predicate nonMatchEdge(BasicBlock bb1, BasicBlock bb2) {
9292
bb1.getASuccessor(any(MatchingSuccessor s | s.getValue() = false)) = bb2 and
93-
bb1.getLastNode() = AstNode.super.getControlFlowNode()
93+
bb1.getLastNode() = super.getPattern().getControlFlowNode()
9494
}
9595
}
9696

java/ql/lib/semmle/code/java/controlflow/Guards.qll

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,20 @@ private module GuardsInput implements SharedGuards::InputSig<Location, ControlFl
168168
)
169169
}
170170

171+
private ControlFlowNode getPatternNode() {
172+
result = this.(J::PatternCase).getUniquePattern().getControlFlowNode()
173+
or
174+
result = unique(Expr e | this.(J::ConstCase).getValue(_) = e).getControlFlowNode()
175+
}
176+
171177
predicate matchEdge(BasicBlock bb1, BasicBlock bb2) {
172178
bb1.getASuccessor(any(MatchingSuccessor s | s.getValue() = true)) = bb2 and
173-
bb1.getLastNode() = super.getControlFlowNode()
179+
bb1.getLastNode() = this.getPatternNode()
174180
}
175181

176182
predicate nonMatchEdge(BasicBlock bb1, BasicBlock bb2) {
177183
bb1.getASuccessor(any(MatchingSuccessor s | s.getValue() = false)) = bb2 and
178-
bb1.getLastNode() = super.getControlFlowNode()
184+
bb1.getLastNode() = this.getPatternNode()
179185
}
180186
}
181187

0 commit comments

Comments
 (0)