diff --git a/infer/src/pulse/PulseDiagnostic.ml b/infer/src/pulse/PulseDiagnostic.ml index 61a3d1f1b98..baf5b924174 100644 --- a/infer/src/pulse/PulseDiagnostic.ml +++ b/infer/src/pulse/PulseDiagnostic.ml @@ -918,6 +918,27 @@ let get_message_and_suggestion diagnostic = , Some (get_suggestion_msg source_opt) ) ) +let get_autofix pdesc diagnostic = + match diagnostic with + | UnnecessaryCopy {copied_into; source_opt; copied_location= None} -> ( + let is_formal pvar = + let pvar_name = Pvar.get_name pvar in + List.exists (Procdesc.get_formals pdesc) ~f:(fun (formal, _, _) -> + Mangled.equal pvar_name formal ) + in + match (copied_into, source_opt) with + | IntoField {field}, Some (DecompilerExpr.PVar pvar, [Dereference]) + when Procname.is_constructor (Procdesc.get_proc_name pdesc) && is_formal pvar -> + let param = Pvar.to_string pvar in + Some + { Jsonbug_t.original= F.asprintf "%a(%s)" Fieldname.pp field param + ; replacement= F.asprintf "%a(std::move(%s))" Fieldname.pp field param } + | _ -> + None ) + | _ -> + None + + let add_errlog_header ~nesting ~title location errlog = let tags = [] in Errlog.make_trace_element nesting location title tags :: errlog diff --git a/infer/src/pulse/PulseDiagnostic.mli b/infer/src/pulse/PulseDiagnostic.mli index 425b423d08c..a178a01550b 100644 --- a/infer/src/pulse/PulseDiagnostic.mli +++ b/infer/src/pulse/PulseDiagnostic.mli @@ -132,6 +132,8 @@ val aborts_execution : t -> bool val get_message_and_suggestion : t -> string * string option +val get_autofix : Procdesc.t -> t -> Jsonbug_t.autofix option + val get_location : t -> Location.t val get_location_instantiated : t -> Location.t option diff --git a/infer/src/pulse/PulseReport.ml b/infer/src/pulse/PulseReport.ml index 6ec374780d0..8e67d923508 100644 --- a/infer/src/pulse/PulseReport.ml +++ b/infer/src/pulse/PulseReport.ml @@ -137,10 +137,11 @@ let report {InterproceduralAnalysis.tenv; proc_desc; err_log} ~is_suppressed ~la in let issue_type = get_issue_type tenv ~latent diagnostic proc_desc in let message, suggestion = get_message_and_suggestion diagnostic in + let autofix = get_autofix proc_desc diagnostic in L.d_printfln ~color:Red "Reporting issue: %a: %s" IssueType.pp issue_type message ; Reporting.log_issue proc_desc err_log ~loc:(get_location diagnostic) ?loc_instantiated ~ltr:(extra_trace @ get_trace diagnostic) - ~extras ?suggestion Pulse issue_type message + ~extras ?autofix ?suggestion Pulse issue_type message let report_latent_issue analysis_data latent_issue ~is_suppressed =