Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bufferoverrun Analysis - small fixes and improvements #1736

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions infer/src/bufferoverrun/bounds.ml
Original file line number Diff line number Diff line change
Expand Up @@ -950,25 +950,25 @@ module Bound = struct
let plus_l : weak:bool -> t -> t -> t =
plus_exact ~otherwise:(fun x y ->
match (x, y) with
| MinMax (c1, Plus, Max, d1, _), Linear (c2, x2)
| Linear (c2, x2), MinMax (c1, Plus, Max, d1, _) ->
Linear (Z.(c1 + d1 + c2), x2)
| MinMax (c1, Minus, Min, d1, _), Linear (c2, x2)
| Linear (c2, x2), MinMax (c1, Minus, Min, d1, _) ->
Linear (Z.(c1 - d1 + c2), x2)
| MinMax (c1, Plus, Max, d1, x1), Linear (c2, x2)
| Linear (c2, x2), MinMax (c1, Plus, Max, d1, x1) ->
mk_MinMaxB (Max, (Linear (Z.(c1 + d1 + c2), x2)), (Linear (Z.(c1 + c2), SymLinear.plus (SymLinear.singleton_one x1) x2)))
| MinMax (c1, Minus, Min, d1, x1), Linear (c2, x2)
| Linear (c2, x2), MinMax (c1, Minus, Min, d1, x1) ->
mk_MinMaxB (Max, (Linear (Z.(c1 - d1 + c2), x2)), (Linear (Z.(c1 + c2), SymLinear.plus (SymLinear.singleton_minus_one x1) x2)))
Comment on lines +953 to +958
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While MinMaxB was introduced to express more complex min/max expressions, it is NOT always a better choice than others. By its complex nature, many operations may easily lose precision on MinMaxB bound, for example, during widening it is more likely to have infinity bounds according to my experience. Therefore, if we want to introduce MinMaxB here for the plus operation, we should evaluate overall precision impacts. Let me check if it is fine for our use cases.

| _, _ ->
MInf )


let plus_u : weak:bool -> t -> t -> t =
plus_exact ~otherwise:(fun x y ->
match (x, y) with
| MinMax (c1, Plus, Min, d1, _), Linear (c2, x2)
| Linear (c2, x2), MinMax (c1, Plus, Min, d1, _) ->
Linear (Z.(c1 + d1 + c2), x2)
| MinMax (c1, Minus, Max, d1, _), Linear (c2, x2)
| Linear (c2, x2), MinMax (c1, Minus, Max, d1, _) ->
Linear (Z.(c1 - d1 + c2), x2)
| MinMax (c1, Plus, Min, d1, x1), Linear (c2, x2)
| Linear (c2, x2), MinMax (c1, Plus, Min, d1, x1) ->
mk_MinMaxB (Min, (Linear (Z.(c1 + d1 + c2), x2)), (Linear (Z.(c1 + c2), SymLinear.plus (SymLinear.singleton_one x1) x2)))
| MinMax (c1, Minus, Max, d1, x1), Linear (c2, x2)
| Linear (c2, x2), MinMax (c1, Minus, Max, d1, x1) ->
mk_MinMaxB (Min, (Linear (Z.(c1 - d1 + c2), x2)), (Linear (Z.(c1 + c2), SymLinear.plus (SymLinear.singleton_minus_one x1) x2)))
| _, _ ->
PInf )

Expand Down