Skip to content

Commit

Permalink
[uninit][hack] Set Uninitialized attribute at sinit
Browse files Browse the repository at this point in the history
Summary: This diff sets `Uninitialized` attributes for all constant fields at the start of `sinit` method.

Reviewed By: davidpichardie

Differential Revision: D49727571

fbshipit-source-id: bb2f5fab0f9e7370ce06984cbcf0c99e6ac05d18
  • Loading branch information
skcho authored and facebook-github-bot committed Oct 10, 2023
1 parent d237df0 commit a9ff3d4
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion infer/src/IR/Mangled.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ let pp f pn = F.pp_print_string f (to_string pn)

let this = from_string "this"

let is_this = function {plain= "this"} -> true | _ -> false
let is_this = function {plain= "this" | "$this"} -> true | _ -> false

let self = from_string "self"

Expand Down
7 changes: 7 additions & 0 deletions infer/src/IR/Procname.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,13 @@ let is_hack_builtins = function
false


let is_hack_sinit = function
| Hack {function_name} ->
String.equal function_name "_86sinit"
| _ ->
false


let has_hack_classname = function Hack {class_name= Some _} -> true | _ -> false

let get_global_name_of_initializer t =
Expand Down
2 changes: 2 additions & 0 deletions infer/src/IR/Procname.mli
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,8 @@ val is_erlang_call_qualified : t -> bool

val is_hack_builtins : t -> bool

val is_hack_sinit : t -> bool

val has_hack_classname : t -> bool

module Normalizer : HashNormalizer.S with type t = t
27 changes: 26 additions & 1 deletion infer/src/pulse/Pulse.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1426,13 +1426,38 @@ let with_html_debug_node node ~desc ~f =
~f


let set_uninitialize_prop path tenv ({ProcAttributes.loc} as proc_attrs) astate =
let pname = ProcAttributes.get_proc_name proc_attrs in
if Procname.is_hack_sinit pname then
let ( let* ) x f = match x with None -> astate | Some x -> f x in
let* name = Procname.get_class_type_name pname in
let* {Struct.fields} = Tenv.lookup tenv name in
let class_global_var = PulseModelsHack.get_static_companion_var name in
let typ = Typ.mk_struct name in
List.fold fields ~init:astate ~f:(fun astate (fld, {Typ.quals= fld_quals}, _) ->
(* Ideally, we would like to analyze `abstract const` fields only, but current SIL cannot
express the `abstract` field at the moment. *)
if Typ.is_const fld_quals then
match
PulseOperations.eval path NoAccess loc (Lfield (Lvar class_global_var, fld, typ)) astate
with
| Sat (Ok (astate, (fld, _))) ->
AbductiveDomain.AddressAttributes.add_one fld (Uninitialized Const) astate
| _ ->
astate
else astate )
else astate


let initial tenv proc_attrs specialization =
let path = PathContext.initial in
let initial_astate =
AbductiveDomain.mk_initial tenv proc_attrs specialization
|> PulseSummary.initial_with_positive_self proc_attrs
|> PulseTaintOperations.taint_initial tenv proc_attrs
|> set_uninitialize_prop path tenv proc_attrs
in
[(ContinueProgram initial_astate, PathContext.initial)]
[(ContinueProgram initial_astate, path)]


let should_analyze proc_desc =
Expand Down
2 changes: 2 additions & 0 deletions infer/src/pulse/PulseModelsHack.mli
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ val get_static_companion :
-> Typ.name
-> PulseAbductiveDomain.t
-> PulseBaseStack.value * PulseAbductiveDomain.t

val get_static_companion_var : Typ.name -> Pvar.t

0 comments on commit a9ff3d4

Please sign in to comment.