Skip to content

Commit

Permalink
Add invalidation / reporting structure for map reference invalidation
Browse files Browse the repository at this point in the history
Summary: A digestible atomic bit of work. This adds a bit of necessary structure to be able to report errors properly with the reference stability checker.

Reviewed By: ezgicicek

Differential Revision: D49957619

fbshipit-source-id: 7e68a5bda400c8a4758233af87e86ab3780addac
  • Loading branch information
nicovank authored and facebook-github-bot committed Oct 6, 2023
1 parent d06e9a2 commit f425864
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 3 deletions.
2 changes: 1 addition & 1 deletion infer/src/base/IssueType.mli
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ val user_controlled_sql_risk : t

val vector_invalidation : latent:bool -> t

val pulse_reference_stability : t [@@warning "-unused-value-declaration"]
val pulse_reference_stability : t

val weak_self_in_noescape_block : t

Expand Down
3 changes: 2 additions & 1 deletion infer/src/pulse/PulseDiagnostic.ml
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,8 @@ let invalidation_titles (invalidation : Invalidation.t) =
| EndIterator
| GoneOutOfScope _
| OptionalEmpty
| StdVector _ ->
| StdVector _
| CppMap _ ->
( "invalidation part of the trace starts here"
, "use-after-lifetime part of the trace starts here" )

Expand Down
56 changes: 56 additions & 0 deletions infer/src/pulse/PulseInvalidation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,54 @@ let pp_std_vector_function f = function
F.fprintf f "std::vector::shrink_to_fit"


type map_type = FollyF14Value | FollyF14Vector | FollyF14Fast
[@@warning "-unused-constructor"] [@@deriving compare, equal]

type map_function =
| Clear
| Rehash
| Reserve
| OperatorEqual
| Insert
| InsertOrAssign
| Emplace
| TryEmplace
| EmplaceHint
| OperatorBracket
[@@warning "-unused-constructor"] [@@deriving compare, equal]

let pp_map_type f = function
| FollyF14Value ->
F.fprintf f "folly::F14ValueMap"
| FollyF14Vector ->
F.fprintf f "folly::F14VectorMap"
| FollyF14Fast ->
F.fprintf f "folly::F14FastMap"


let pp_map_function f = function
| Clear ->
F.fprintf f "clear"
| Rehash ->
F.fprintf f "rehash"
| Reserve ->
F.fprintf f "reserve"
| OperatorEqual ->
F.fprintf f "operator="
| Insert ->
F.fprintf f "insert"
| InsertOrAssign ->
F.fprintf f "insert_or_assign"
| Emplace ->
F.fprintf f "emplace"
| TryEmplace ->
F.fprintf f "try_emplace"
| EmplaceHint ->
F.fprintf f "emplace_hint"
| OperatorBracket ->
F.fprintf f "operator[]"


type t =
| CFree
| ConstantDereference of IntLit.t
Expand All @@ -46,6 +94,7 @@ type t =
| GoneOutOfScope of Pvar.t * Typ.t
| OptionalEmpty
| StdVector of std_vector_function
| CppMap of map_type * map_function
[@@deriving compare, equal]

type must_be_valid_reason =
Expand Down Expand Up @@ -99,6 +148,8 @@ let issue_type_of_cause ~latent invalidation must_be_valid_reason =
IssueType.optional_empty_access ~latent
| StdVector _ ->
IssueType.vector_invalidation ~latent
| CppMap _ ->
IssueType.pulse_reference_stability


let describe f cause =
Expand Down Expand Up @@ -126,6 +177,9 @@ let describe f cause =
F.pp_print_string f "is assigned an empty value"
| StdVector std_vector_f ->
F.fprintf f "was potentially invalidated by `%a()`" pp_std_vector_function std_vector_f
| CppMap (map_t, map_f) ->
F.fprintf f "was potentially invalidated by `%a::%a()`" pp_map_type map_t pp_map_function
map_f


let pp f invalidation =
Expand All @@ -140,3 +194,5 @@ let pp f invalidation =
describe f invalidation
| StdVector _ ->
F.fprintf f "StdVector(%a)" describe invalidation
| CppMap _ ->
F.fprintf f "CppMap(%a)" describe invalidation
19 changes: 19 additions & 0 deletions infer/src/pulse/PulseInvalidation.mli
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@ type std_vector_function =

val pp_std_vector_function : F.formatter -> std_vector_function -> unit

type map_type = FollyF14Value | FollyF14Vector | FollyF14Fast

type map_function =
| Clear
| Rehash
| Reserve
| OperatorEqual
| Insert
| InsertOrAssign
| Emplace
| TryEmplace
| EmplaceHint
| OperatorBracket

val pp_map_type : F.formatter -> map_type -> unit [@@warning "-unused-value-declaration"]

val pp_map_function : F.formatter -> map_function -> unit [@@warning "-unused-value-declaration"]

type t =
| CFree
| ConstantDereference of IntLit.t
Expand All @@ -29,6 +47,7 @@ type t =
| GoneOutOfScope of Pvar.t * Typ.t
| OptionalEmpty
| StdVector of std_vector_function
| CppMap of map_type * map_function
[@@deriving compare, equal]

val pp : F.formatter -> t -> unit
Expand Down
3 changes: 2 additions & 1 deletion infer/src/pulse/PulseReport.ml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ let is_constant_deref_without_invalidation (invalidation : Invalidation.t) acces
| EndIterator
| GoneOutOfScope _
| OptionalEmpty
| StdVector _ ->
| StdVector _
| CppMap _ ->
false
in
if res then
Expand Down

0 comments on commit f425864

Please sign in to comment.