Skip to content

Commit f9132c5

Browse files
committed
Java: Duplicate a bit more code to postpone Java-C# cleanup.
1 parent 1f4cd74 commit f9132c5

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

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

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module Private {
44
private import semmle.code.java.dataflow.RangeUtils as RU
55
private import semmle.code.java.controlflow.Guards as G
66
private import semmle.code.java.controlflow.BasicBlocks as BB
7+
private import semmle.code.java.controlflow.internal.GuardsLogic as GL
78
private import SsaReadPositionCommon
89

910
class BasicBlock = BB::BasicBlock;
@@ -100,9 +101,31 @@ module Private {
100101
}
101102
}
102103

103-
predicate guardDirectlyControlsSsaRead = RU::guardDirectlyControlsSsaRead/3;
104+
/**
105+
* Holds if `guard` directly controls the position `controlled` with the
106+
* value `testIsTrue`.
107+
*/
108+
pragma[nomagic]
109+
predicate guardDirectlyControlsSsaRead(Guard guard, SsaReadPosition controlled, boolean testIsTrue) {
110+
guard.directlyControls(controlled.(SsaReadPositionBlock).getBlock(), testIsTrue)
111+
or
112+
exists(SsaReadPositionPhiInputEdge controlledEdge | controlledEdge = controlled |
113+
guard.directlyControls(controlledEdge.getOrigBlock(), testIsTrue) or
114+
guard.hasBranchEdge(controlledEdge.getOrigBlock(), controlledEdge.getPhiBlock(), testIsTrue)
115+
)
116+
}
104117

105-
predicate guardControlsSsaRead = RU::guardControlsSsaRead/3;
118+
/**
119+
* Holds if `guard` controls the position `controlled` with the value `testIsTrue`.
120+
*/
121+
predicate guardControlsSsaRead(Guard guard, SsaReadPosition controlled, boolean testIsTrue) {
122+
guardDirectlyControlsSsaRead(guard, controlled, testIsTrue)
123+
or
124+
exists(Guard guard0, boolean testIsTrue0 |
125+
GL::implies_v2(guard0, testIsTrue0, guard, testIsTrue) and
126+
guardControlsSsaRead(guard0, controlled, testIsTrue0)
127+
)
128+
}
106129

107130
predicate valueFlowStep = RU::valueFlowStep/3;
108131

0 commit comments

Comments
 (0)