Skip to content

Commit fb38c6d

Browse files
hvitvedCopilot
andcommitted
Shared: Fix PR-caused CI failures
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 697064d commit fb38c6d

7 files changed

Lines changed: 40 additions & 18 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ module GuardsInput implements SharedGuards::InputSig<Cpp::Location, Instruction,
194194
class Pattern extends AstNode {
195195
Pattern() { none() }
196196

197+
/** Gets a subpattern of this pattern. */
197198
Pattern getASubPattern() { none() }
198199
}
199200

‎csharp/ql/lib/semmle/code/csharp/dataflow/ModulusAnalysis.qll‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
overlay[local?]
77
module;
88

9-
private import csharp as CS
109
private import internal.rangeanalysis.ModulusAnalysisSpecific::Private
1110
private import Bound
1211
private import internal.rangeanalysis.SsaReadPositionCommon
@@ -82,13 +81,12 @@ private Guard moduloCheck(SsaVariable v, int val, int mod, GuardValue testValue)
8281
val = 1 - r and
8382
(
8483
r = 0
85-
or
8684
// A signed remainder may be -1, so excluding 1 need not imply 0.
85+
or
8786
r = 1 and
8887
(
8988
rem instanceof BitwiseAndExpr
90-
or
91-
rem.(RemExpr).getLeftOperand().getExpr().getType().(CS::SimpleType).minValue() >= 0
89+
or isDefinitelyNonNegative(rem.(RemExpr).getLeftOperand())
9290
)
9391
)
9492
)

‎csharp/ql/lib/semmle/code/csharp/dataflow/internal/rangeanalysis/ModulusAnalysisSpecific.qll‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ module Private {
1313

1414
class Expr = CS::ControlFlowNodes::ExprNode;
1515

16+
predicate isDefinitelyNonNegative(Expr e) {
17+
e.getExpr().getType().(CS::SimpleType).minValue() >= 0
18+
}
19+
1620
class Guard = RU::Guard;
1721

1822
class GuardValue = RU::GuardValue;

‎java/ql/lib/semmle/code/java/dataflow/ModulusAnalysis.qll‎

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ private import internal.rangeanalysis.SsaReadPositionCommon
1616
private predicate valueFlowStepSsa(SsaVariable v, SsaReadPosition pos, Expr e, int delta) {
1717
ssaUpdateStep(v, e, delta) and pos.hasReadOfVar(v)
1818
or
19-
exists(Guard guard, boolean testIsTrue |
19+
exists(Guard guard, GuardValue testValue |
2020
pos.hasReadOfVar(v) and
21-
guard = eqFlowCond(v, e, delta, true, testIsTrue) and
22-
guardControlsSsaRead(guard, pos, any(GuardValue gv | gv.asBooleanValue() = testIsTrue))
21+
guard = eqFlowCond(v, e, delta, true, testValue) and
22+
guardControlsSsaRead(guard, pos, testValue)
2323
)
2424
}
2525

@@ -65,21 +65,30 @@ private Expr modExpr(Expr arg, int mod) {
6565
}
6666

6767
/**
68-
* Gets a guard that tests whether `v` is congruent with `val` modulo `mod` on
69-
* its `testIsTrue` branch.
68+
* Gets a guard that tests whether `v` is congruent with `val` modulo `mod`
69+
* when evaluating to `testValue`.
7070
*/
71-
private Guard moduloCheck(SsaVariable v, int val, int mod, boolean testIsTrue) {
71+
private Guard moduloCheck(SsaVariable v, int val, int mod, GuardValue testValue) {
7272
exists(Expr rem, ConstantIntegerExpr c, int r, GuardValue polarity |
7373
result.isEquality(rem, c, polarity) and
7474
c.getIntValue() = r and
7575
rem = modExpr(v.getAUse(), mod) and
7676
(
77-
testIsTrue = polarity.asBooleanValue() and val = r
77+
testValue = polarity and val = remainder(r, mod)
7878
or
79-
testIsTrue = polarity.asBooleanValue().booleanNot() and
79+
testValue = polarity.getDualValue() and
8080
mod = 2 and
8181
val = 1 - r and
82-
(r = 0 or r = 1)
82+
(
83+
r = 0
84+
// A signed remainder may be -1, so excluding 1 need not imply 0.
85+
or
86+
r = 1 and
87+
(
88+
rem instanceof BitwiseAndExpr
89+
or isDefinitelyNonNegative(rem.(RemExpr).getLeftOperand())
90+
)
91+
)
8392
)
8493
)
8594
}
@@ -88,10 +97,10 @@ private Guard moduloCheck(SsaVariable v, int val, int mod, boolean testIsTrue) {
8897
* Holds if a guard ensures that `v` at `pos` is congruent with `val` modulo `mod`.
8998
*/
9099
private predicate moduloGuardedRead(SsaVariable v, SsaReadPosition pos, int val, int mod) {
91-
exists(Guard guard, boolean testIsTrue |
100+
exists(Guard guard, GuardValue testValue |
92101
pos.hasReadOfVar(v) and
93-
guard = moduloCheck(v, val, mod, testIsTrue) and
94-
guardControlsSsaRead(guard, pos, any(GuardValue gv | gv.asBooleanValue() = testIsTrue))
102+
guard = moduloCheck(v, val, mod, testValue) and
103+
guardControlsSsaRead(guard, pos, testValue)
95104
)
96105
}
97106

‎java/ql/lib/semmle/code/java/dataflow/internal/rangeanalysis/ModulusAnalysisSpecific.qll‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ module Private {
1919

2020
class Expr = J::Expr;
2121

22+
predicate isDefinitelyNonNegative(Expr e) { none() }
23+
2224
class GuardValue = G::GuardValue;
2325

2426
class Guard extends G::Guards_v2::Guard {
@@ -123,7 +125,14 @@ module Private {
123125

124126
predicate valueFlowStep = RU::valueFlowStep/3;
125127

126-
predicate eqFlowCond = RU::eqFlowCond/5;
128+
Guard eqFlowCond(
129+
SsaVariable v, Expr e, int delta, boolean isEq, GuardValue testValue
130+
) {
131+
exists(boolean testIsTrue |
132+
testValue.asBooleanValue() = testIsTrue and
133+
result = RU::eqFlowCond(v, e, delta, isEq, testIsTrue)
134+
)
135+
}
127136

128137
predicate ssaUpdateStep = RU::ssaUpdateStep/3;
129138

‎java/ql/test/library-tests/switch-default-impossible-dispatch/Test.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ case Wrapper(String s) -> { }
4545

4646
switch(i) {
4747
case WrapperWrapper(Wrapper(Object o)) -> { }
48-
default -> i.take(source()); // Can't call WrapperWrapper.take
48+
default -> i.take(source()); // Can call WrapperWrapper.take when its w component is null.
4949
}
5050

5151
switch(i) {

‎java/ql/test/library-tests/switch-default-impossible-dispatch/test.expected‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
| Test.java:48:25:48:32 | source(...) | Test.java:7:65:7:65 | x |
2222
| Test.java:48:25:48:32 | source(...) | Test.java:8:65:8:65 | x |
2323
| Test.java:48:25:48:32 | source(...) | Test.java:9:74:9:74 | x |
24+
| Test.java:48:25:48:32 | source(...) | Test.java:10:82:10:82 | x |
2425
| Test.java:53:25:53:32 | source(...) | Test.java:7:65:7:65 | x |
2526
| Test.java:53:25:53:32 | source(...) | Test.java:8:65:8:65 | x |
2627
| Test.java:53:25:53:32 | source(...) | Test.java:9:74:9:74 | x |

0 commit comments

Comments
 (0)