diff --git a/infer/src/bufferoverrun/bufferOverrunSemantics.ml b/infer/src/bufferoverrun/bufferOverrunSemantics.ml index e93f93604..77519e442 100644 --- a/infer/src/bufferoverrun/bufferOverrunSemantics.ml +++ b/infer/src/bufferoverrun/bufferOverrunSemantics.ml @@ -159,9 +159,9 @@ let rec eval : Typ.IntegerWidths.t -> Exp.t -> Mem.t -> Val.t = match bop with | Binop.(PlusA _ | MinusA _ | MinusPP) -> Val.set_itv_updated_by_addition v - | Binop.(Mult _ | Div | Mod | Shiftlt | Shiftrt | BAnd | BXor | BOr) -> + | Binop.(Mult _ | Div | Mod | Shiftlt | Shiftrt) -> Val.set_itv_updated_by_multiplication v - | Binop.(PlusPI | MinusPI | Lt | Gt | Le | Ge | Eq | Ne | LAnd | LOr) -> + | Binop.(PlusPI | MinusPI | Lt | Gt | Le | Ge | Eq | Ne | LAnd | LOr | BAnd | BXor | BOr) -> Val.set_itv_updated_by_unknown v ) | Exp.Const c -> eval_const integer_type_widths c diff --git a/infer/tests/codetoanalyze/java/performance/IntTest.java b/infer/tests/codetoanalyze/java/performance/IntTest.java index 2e4f6531f..9d344ce0e 100644 --- a/infer/tests/codetoanalyze/java/performance/IntTest.java +++ b/infer/tests/codetoanalyze/java/performance/IntTest.java @@ -19,4 +19,34 @@ class IntTest { Integer x = p; // call to valueOf for (int count = 0; count < x; count++) {} } + + boolean unknown_bool; + + void control_var_band_constant(int x, int y) { + int z; + for (int i = 0; i < 10; i++) { + if (unknown_bool) { + z = x & y; + } else { + z = x | y; + } + if (z == 0) { + break; + } + } + } + + void control_var_band_add_constant_FP(int x, int y) { + int z; + for (int i = 0; i < 10; i++) { + if (unknown_bool) { + z = (x & y) + 1; + } else { + z = (x | y) + 1; + } + if (z == 0) { + break; + } + } + } } diff --git a/infer/tests/codetoanalyze/java/performance/issues.exp b/infer/tests/codetoanalyze/java/performance/issues.exp index 82ca3ebfe..2ef28afb0 100644 --- a/infer/tests/codetoanalyze/java/performance/issues.exp +++ b/infer/tests/codetoanalyze/java/performance/issues.exp @@ -116,6 +116,9 @@ codetoanalyze/java/performance/Cost_test_deps.java, codetoanalyze.java.performan codetoanalyze/java/performance/Cost_test_deps.java, codetoanalyze.java.performance.Cost_test_deps.two_loops():int, 7, EXPENSIVE_EXECUTION_TIME, no_bucket, ERROR, [with estimated cost 545, O(1), degree = 0] codetoanalyze/java/performance/EvilCfg.java, EvilCfg.foo(int,int,boolean):void, 0, INFINITE_EXECUTION_TIME, no_bucket, ERROR, [Unbounded loop,Loop at line 15] codetoanalyze/java/performance/FieldAccess.java, codetoanalyze.java.performance.FieldAccess.iterate_upto_field_size(codetoanalyze.java.performance.FieldAccess$Test):void, 1, EXPENSIVE_EXECUTION_TIME, no_bucket, ERROR, [with estimated cost 2 + 6 ⋅ test.a, O(test.a), degree = 1,{test.a},Loop at line 16] +codetoanalyze/java/performance/IntTest.java, IntTest.control_var_band_add_constant_FP(int,int):void, 0, INFINITE_EXECUTION_TIME, no_bucket, ERROR, [Unbounded loop,Loop at line 41] +codetoanalyze/java/performance/IntTest.java, IntTest.control_var_band_add_constant_FP(int,int):void, 4, INTEGER_OVERFLOW_L5, no_bucket, ERROR, [,Parameter `x`,Binary operation: ([-oo, +oo] + 1):signed32] +codetoanalyze/java/performance/IntTest.java, IntTest.control_var_band_add_constant_FP(int,int):void, 6, INTEGER_OVERFLOW_L5, no_bucket, ERROR, [,Parameter `x`,Binary operation: ([-oo, +oo] + 1):signed32] codetoanalyze/java/performance/IntTest.java, IntTest.intValue_linear(java.lang.Integer):void, 1, EXPENSIVE_EXECUTION_TIME, no_bucket, ERROR, [with estimated cost 2 + 5 ⋅ mKBytesToSend + 3 ⋅ (1+max(0, mKBytesToSend)), O(mKBytesToSend), degree = 1,{1+max(0, mKBytesToSend)},Loop at line 9,{mKBytesToSend},Loop at line 9] codetoanalyze/java/performance/IntTest.java, IntTest.static_Integer_top():void, 0, INFINITE_EXECUTION_TIME, no_bucket, ERROR, [Unbounded loop,Loop at line 15] codetoanalyze/java/performance/IntTest.java, IntTest.static_Integer_top():void, 1, INTEGER_OVERFLOW_L5, no_bucket, ERROR, [,Assignment,Binary operation: ([0, +oo] + 1):signed32]