Skip to content

Commit

Permalink
[pulse] suppress mutual recursion reports for hack xinit
Browse files Browse the repository at this point in the history
Summary:
These have been observed to cause false positives, as in the test.

Also strengthen the test for `hack_internal` in case someone ever tries
to use it outside of Hack.

Reviewed By: geralt-encore

Differential Revision:
D66667344

Privacy Context Container: L1208441

fbshipit-source-id: 4cfa8c9127bf44a9dc49a492b3334c891908ddf5
  • Loading branch information
jvillard authored and facebook-github-bot committed Dec 3, 2024
1 parent 12399f4 commit c269e0f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 18 deletions.
9 changes: 7 additions & 2 deletions infer/src/IR/Procname.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1009,8 +1009,13 @@ let is_hack_xinit = function Hack classname -> Hack.is_xinit classname | _ -> fa

let is_hack_internal procname =
if is_hack_xinit procname || is_hack_builtins procname || is_hack_construct procname then true
else match procname with (* models are implemented as C functions *)
| C _ -> true | _ -> false
else
match procname with
(* Hack models are implemented as C functions *)
| C _ when Language.curr_language_is Hack ->
true
| _ ->
false


let has_hack_classname = function Hack {class_name= Some _} -> true | _ -> false
Expand Down
3 changes: 3 additions & 0 deletions infer/src/pulse/PulseCallOperations.ml
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,9 @@ let on_recursive_call ({InterproceduralAnalysis.proc_desc} as analysis_data) cal
| Some formals when List.length formals <> List.length actuals ->
print_arity_mismatch_message ~extra_call_prefix:" recursive" (Some callee_pname) ~formals
~actuals
| _ when Procname.is_hack_xinit callee_pname ->
L.d_printfln "Suppressing recursive call report for non-user-visible function %a"
Procname.pp callee_pname
| _ ->
PulseReport.report analysis_data ~is_suppressed:false ~latent:false
(MutualRecursionCycle
Expand Down
43 changes: 27 additions & 16 deletions infer/src/pulse/PulseInterproc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -965,22 +965,33 @@ let report_mutual_recursion_cycle

let record_recursive_calls ({InterproceduralAnalysis.proc_desc} as analysis_data) callee_proc_name
call_loc callee_summary call_state =
let callee_recursive_calls =
PulseMutualRecursion.Set.filter_map
(fun cycle ->
let cycle = PulseMutualRecursion.add_call callee_proc_name call_loc cycle in
if
Procname.equal
(PulseMutualRecursion.get_inner_call cycle)
(Procdesc.get_proc_name proc_desc)
then (
report_mutual_recursion_cycle analysis_data cycle ;
None )
else Some cycle )
(AbductiveDomain.Summary.get_recursive_calls callee_summary)
in
let astate = AbductiveDomain.add_recursive_calls callee_recursive_calls call_state.astate in
{call_state with astate}
if Procname.is_hack_xinit (Procdesc.get_proc_name proc_desc) then (
L.d_printfln "Not recording recursive calls for Hack xinit caller function %a" Procname.pp
(Procdesc.get_proc_name proc_desc) ;
call_state )
else if Procname.is_hack_xinit callee_proc_name then (
(* shouldn't get there normally since we are careful never to record a recursive cycle for xinit
functions in the first place *)
L.d_printfln "Not recording recursive calls for Hack xinit callee function %a" Procname.pp
callee_proc_name ;
call_state )
else
let callee_recursive_calls =
PulseMutualRecursion.Set.filter_map
(fun cycle ->
let cycle = PulseMutualRecursion.add_call callee_proc_name call_loc cycle in
if
Procname.equal
(PulseMutualRecursion.get_inner_call cycle)
(Procdesc.get_proc_name proc_desc)
then (
report_mutual_recursion_cycle analysis_data cycle ;
None )
else Some cycle )
(AbductiveDomain.Summary.get_recursive_calls callee_summary)
in
let astate = AbductiveDomain.add_recursive_calls callee_recursive_calls call_state.astate in
{call_state with astate}


let record_skipped_calls callee_proc_name call_loc callee_summary call_state =
Expand Down
5 changes: 5 additions & 0 deletions infer/tests/codetoanalyze/hack/pulse/constinit.hack
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,8 @@ class Tester {
};
}
}

class SeveralConsts {
const int X = 42;
const int Y = SeveralConsts::X + 1; // FP reported here
}

0 comments on commit c269e0f

Please sign in to comment.