@@ -16,10 +16,10 @@ private import internal.rangeanalysis.SsaReadPositionCommon
1616private 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 */
9099private 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
0 commit comments