Skip to content

Commit 94ac41b

Browse files
authored
Merge pull request #23325 from github/copilot/move-default-case-guard
Guards: Make irrelevant isDefaultCase predicate optional
2 parents 895a078 + 514e782 commit 94ac41b

5 files changed

Lines changed: 7 additions & 14 deletions

File tree

‎cpp/ql/lib/semmle/code/cpp/controlflow/IRGuards.qll‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,6 @@ module GuardsInput implements SharedGuards::InputSig<Cpp::Location, Instruction,
165165
*/
166166
Expr getSwitchExpr() { result = switch.getExpression() }
167167

168-
/**
169-
* Holds if this case is the default case.
170-
*/
171-
predicate isDefaultCase() { edge.isDefault() }
172-
173168
/**
174169
* Gets the expression matched by this case.
175170
*/
@@ -181,6 +176,9 @@ module GuardsInput implements SharedGuards::InputSig<Cpp::Location, Instruction,
181176
}
182177
}
183178

179+
/** Holds if `c` is the default case. */
180+
predicate isDefaultCase(Case c) { c.getEdge().isDefault() }
181+
184182
/**
185183
* Holds if the case `c` takes control-flow from `bb1` to `bb2` when
186184
* the case matches the scrutinee.

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ private module GuardsInput implements SharedGuards::InputSig<Location, ControlFl
8383
class Case extends AstNode instanceof CS::Case {
8484
Expr getSwitchExpr() { super.getExpr() = result }
8585

86-
predicate isDefaultCase() { this instanceof DefaultCase }
87-
8886
AstNode getAPattern() { super.getPattern() = result }
8987
}
9088

‎go/ql/lib/semmle/go/controlflow/Guards.qll‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ private module GuardsInput implements
101101

102102
Expr getSwitchExpr() { result = switch.getExpr() }
103103

104-
predicate isDefaultCase() { this = switch.getDefault() }
105-
106104
AstNode getAPattern() { result = this.(G::CaseClause).getAnExpr() }
107105
}
108106

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,6 @@ private module GuardsInput implements SharedGuards::InputSig<Location, ControlFl
163163
class Case extends ExprParent instanceof J::SwitchCase {
164164
Expr getSwitchExpr() { result = super.getSelectorExpr() }
165165

166-
predicate isDefaultCase() { this instanceof DefaultCase }
167-
168166
AstNode getAPattern() {
169167
result = this.(ConstCase).getValue(_) or result = this.(J::PatternCase).getAPattern()
170168
}

‎shared/controlflow/codeql/controlflow/Guards.qll‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,12 @@ signature module InputSig<LocationSig Location, TypSig ControlFlowNode, TypSig B
103103
class Case extends AstNode {
104104
Expr getSwitchExpr();
105105

106-
predicate isDefaultCase();
107-
108106
AstNode getAPattern();
109107
}
110108

109+
/** Holds if `c` is the default case in a legacy jump-table CFG. */
110+
default predicate isDefaultCase(Case c) { none() }
111+
111112
/** Holds if the case `c` has a legacy jump-table CFG with a match edge from `bb1` to `bb2`. */
112113
default predicate caseMatchEdge(Case c, BasicBlock bb1, BasicBlock bb2) { none() }
113114

@@ -606,7 +607,7 @@ module Make<
606607
or
607608
exists(Case c1, Expr switchExpr |
608609
g1 = c1 and
609-
c1.isDefaultCase() and
610+
isDefaultCase(c1) and
610611
c1.getSwitchExpr() = switchExpr and
611612
v1.asBooleanValue() = true and
612613
g2.(Case).getSwitchExpr() = switchExpr and

0 commit comments

Comments
 (0)