Skip to content

Commit 675e04e

Browse files
authored
Merge branch 'main' into main
2 parents ae65781 + c16e1cc commit 675e04e

File tree

130 files changed

+1353
-621
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+1353
-621
lines changed

Makefile.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ define copy_or_same_file
119119
$(COPY) "$(1)" "$(2)" || diff -q "$(1)" "$(2)"
120120
endef
121121

122-
INTERACTIVE := $(shell [ -t 0 ] && echo 1)
122+
INTERACTIVE := $(shell [ -t 0 ] && ! [ x"$$TERM" = xdumb ] && echo 1)
123123
SILENT := $(findstring s,$(filter-out -%,$(firstword $(MAKEFLAGS))))
124124

125125
ifeq (1,$(INTERACTIVE))
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
This is reported when Infer detects an unnecessary copy of an object via `optional` value
2+
construction where the source is not modified before it goes out of scope. To avoid the copy, we
3+
can move the source object or change the callee's type.
4+
5+
For example,
6+
7+
```cpp
8+
void get_optional_value(std::optional<A> x) {}
9+
10+
void pass_non_optional_value(A x) {
11+
get_optional_value(x);
12+
// fix is to move as follows
13+
// get_optional_value(std::move(x));
14+
}
15+
```

infer/man/man1/infer-capture.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,17 @@ BUCK OPTIONS
202202
Skip capture of buck targets matched by the specified regular
203203
expression.
204204

205+
--buck2-bxl-target string
206+
Buck2 BXL script (as a buck target) to run when capturing with
207+
buck2/clang integration.
208+
205209
--buck2-root dir
206210
Specify the parent directory of buck-out (used only for buck2).
207211

212+
--buck2-use-bxl
213+
Activates: Use BXL script when capturing with buck2. (Conversely:
214+
--no-buck2-use-bxl)
215+
208216
--Xbuck +string
209217
Pass values as command-line arguments to invocations of `buck
210218
build`. Only valid for --buck-clang.

infer/man/man1/infer-full.txt

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,18 @@ OPTIONS
223223
Skip capture of buck targets matched by the specified regular
224224
expression. See also infer-capture(1) and infer-run(1).
225225

226+
--buck2-bxl-target string
227+
Buck2 BXL script (as a buck target) to run when capturing with
228+
buck2/clang integration. See also infer-capture(1).
229+
226230
--buck2-root dir
227231
Specify the parent directory of buck-out (used only for buck2).
228232
See also infer-capture(1) and infer-run(1).
229233

234+
--buck2-use-bxl
235+
Activates: Use BXL script when capturing with buck2. (Conversely:
236+
--no-buck2-use-bxl) See also infer-capture(1).
237+
230238
--bufferoverrun
231239
Activates: checker bufferoverrun: InferBO is a detector for
232240
out-of-bounds array accesses. (Conversely: --no-bufferoverrun)
@@ -615,19 +623,20 @@ OPTIONS
615623
PRECONDITION_NOT_MET (enabled by default),
616624
PREMATURE_NIL_TERMINATION_ARGUMENT (enabled by default),
617625
PULSE_CONST_REFABLE (disabled by default),
618-
PULSE_READONLY_SHARED_PTR_PARAM (disabled by default),
626+
PULSE_READONLY_SHARED_PTR_PARAM (enabled by default),
619627
PULSE_RESOURCE_LEAK (enabled by default),
620628
PULSE_UNINITIALIZED_VALUE (enabled by default),
621629
PULSE_UNINITIALIZED_VALUE_LATENT (disabled by default),
622-
PULSE_UNNECESSARY_COPY (disabled by default),
623-
PULSE_UNNECESSARY_COPY_ASSIGNMENT (disabled by default),
630+
PULSE_UNNECESSARY_COPY (enabled by default),
631+
PULSE_UNNECESSARY_COPY_ASSIGNMENT (enabled by default),
624632
PULSE_UNNECESSARY_COPY_ASSIGNMENT_CONST (disabled by default),
625-
PULSE_UNNECESSARY_COPY_ASSIGNMENT_MOVABLE (disabled by
626-
default),
633+
PULSE_UNNECESSARY_COPY_ASSIGNMENT_MOVABLE (enabled by default),
627634
PULSE_UNNECESSARY_COPY_INTERMEDIATE (disabled by default),
628635
PULSE_UNNECESSARY_COPY_INTERMEDIATE_CONST (disabled by
629636
default),
630-
PULSE_UNNECESSARY_COPY_MOVABLE (disabled by default),
637+
PULSE_UNNECESSARY_COPY_MOVABLE (enabled by default),
638+
PULSE_UNNECESSARY_COPY_OPTIONAL (disabled by default),
639+
PULSE_UNNECESSARY_COPY_OPTIONAL_CONST (disabled by default),
631640
PULSE_UNNECESSARY_COPY_RETURN (disabled by default),
632641
PURE_FUNCTION (enabled by default),
633642
QUANDARY_TAINT_ERROR (enabled by default),
@@ -1918,6 +1927,9 @@ INTERNAL OPTIONS
19181927
--buck-targets-block-list-reset
19191928
Set --buck-targets-block-list to the empty list.
19201929

1930+
--buck2-bxl-target-reset
1931+
Cancel the effect of --buck2-bxl-target.
1932+
19211933
--buck2-root-reset
19221934
Cancel the effect of --buck2-root.
19231935

infer/man/man1/infer-report.txt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -265,19 +265,20 @@ OPTIONS
265265
PRECONDITION_NOT_MET (enabled by default),
266266
PREMATURE_NIL_TERMINATION_ARGUMENT (enabled by default),
267267
PULSE_CONST_REFABLE (disabled by default),
268-
PULSE_READONLY_SHARED_PTR_PARAM (disabled by default),
268+
PULSE_READONLY_SHARED_PTR_PARAM (enabled by default),
269269
PULSE_RESOURCE_LEAK (enabled by default),
270270
PULSE_UNINITIALIZED_VALUE (enabled by default),
271271
PULSE_UNINITIALIZED_VALUE_LATENT (disabled by default),
272-
PULSE_UNNECESSARY_COPY (disabled by default),
273-
PULSE_UNNECESSARY_COPY_ASSIGNMENT (disabled by default),
272+
PULSE_UNNECESSARY_COPY (enabled by default),
273+
PULSE_UNNECESSARY_COPY_ASSIGNMENT (enabled by default),
274274
PULSE_UNNECESSARY_COPY_ASSIGNMENT_CONST (disabled by default),
275-
PULSE_UNNECESSARY_COPY_ASSIGNMENT_MOVABLE (disabled by
276-
default),
275+
PULSE_UNNECESSARY_COPY_ASSIGNMENT_MOVABLE (enabled by default),
277276
PULSE_UNNECESSARY_COPY_INTERMEDIATE (disabled by default),
278277
PULSE_UNNECESSARY_COPY_INTERMEDIATE_CONST (disabled by
279278
default),
280-
PULSE_UNNECESSARY_COPY_MOVABLE (disabled by default),
279+
PULSE_UNNECESSARY_COPY_MOVABLE (enabled by default),
280+
PULSE_UNNECESSARY_COPY_OPTIONAL (disabled by default),
281+
PULSE_UNNECESSARY_COPY_OPTIONAL_CONST (disabled by default),
281282
PULSE_UNNECESSARY_COPY_RETURN (disabled by default),
282283
PURE_FUNCTION (enabled by default),
283284
QUANDARY_TAINT_ERROR (enabled by default),

infer/man/man1/infer.txt

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,18 @@ OPTIONS
223223
Skip capture of buck targets matched by the specified regular
224224
expression. See also infer-capture(1) and infer-run(1).
225225

226+
--buck2-bxl-target string
227+
Buck2 BXL script (as a buck target) to run when capturing with
228+
buck2/clang integration. See also infer-capture(1).
229+
226230
--buck2-root dir
227231
Specify the parent directory of buck-out (used only for buck2).
228232
See also infer-capture(1) and infer-run(1).
229233

234+
--buck2-use-bxl
235+
Activates: Use BXL script when capturing with buck2. (Conversely:
236+
--no-buck2-use-bxl) See also infer-capture(1).
237+
230238
--bufferoverrun
231239
Activates: checker bufferoverrun: InferBO is a detector for
232240
out-of-bounds array accesses. (Conversely: --no-bufferoverrun)
@@ -615,19 +623,20 @@ OPTIONS
615623
PRECONDITION_NOT_MET (enabled by default),
616624
PREMATURE_NIL_TERMINATION_ARGUMENT (enabled by default),
617625
PULSE_CONST_REFABLE (disabled by default),
618-
PULSE_READONLY_SHARED_PTR_PARAM (disabled by default),
626+
PULSE_READONLY_SHARED_PTR_PARAM (enabled by default),
619627
PULSE_RESOURCE_LEAK (enabled by default),
620628
PULSE_UNINITIALIZED_VALUE (enabled by default),
621629
PULSE_UNINITIALIZED_VALUE_LATENT (disabled by default),
622-
PULSE_UNNECESSARY_COPY (disabled by default),
623-
PULSE_UNNECESSARY_COPY_ASSIGNMENT (disabled by default),
630+
PULSE_UNNECESSARY_COPY (enabled by default),
631+
PULSE_UNNECESSARY_COPY_ASSIGNMENT (enabled by default),
624632
PULSE_UNNECESSARY_COPY_ASSIGNMENT_CONST (disabled by default),
625-
PULSE_UNNECESSARY_COPY_ASSIGNMENT_MOVABLE (disabled by
626-
default),
633+
PULSE_UNNECESSARY_COPY_ASSIGNMENT_MOVABLE (enabled by default),
627634
PULSE_UNNECESSARY_COPY_INTERMEDIATE (disabled by default),
628635
PULSE_UNNECESSARY_COPY_INTERMEDIATE_CONST (disabled by
629636
default),
630-
PULSE_UNNECESSARY_COPY_MOVABLE (disabled by default),
637+
PULSE_UNNECESSARY_COPY_MOVABLE (enabled by default),
638+
PULSE_UNNECESSARY_COPY_OPTIONAL (disabled by default),
639+
PULSE_UNNECESSARY_COPY_OPTIONAL_CONST (disabled by default),
631640
PULSE_UNNECESSARY_COPY_RETURN (disabled by default),
632641
PURE_FUNCTION (enabled by default),
633642
QUANDARY_TAINT_ERROR (enabled by default),

infer/models/Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ OBJC_MODELS_DIR = objc/src
1313

1414
RESULTS_DIR = infer-out
1515
RESULTS_DB = $(RESULTS_DIR)/results.db
16+
CAPTURE_DB = $(RESULTS_DIR)/capture.db
17+
1618
INFER_OPTIONS = --jobs 1 --biabduction-only --results-dir $(RESULTS_DIR) --biabduction-models-mode
1719

1820
JAVA_MODELS_OUT = java/models
@@ -28,6 +30,10 @@ SQL_DUMP_MODEL_SPECS = \
2830
-cmd ".output $(MODELS_RESULTS_FILE)" \
2931
-cmd "select * from specs order by proc_uid ;"
3032

33+
SQL_DUMP_MODEL_PROCS = \
34+
-cmd ".mode insert procedures" \
35+
-cmd "select * from procedures order by proc_uid ;"
36+
3137

3238
.PHONY: all
3339
all: $(MODELS_RESULTS_FILE)
@@ -66,7 +72,7 @@ $(MODELS_RESULTS_FILE): $(MAKEFILE_LIST)
6672
$(MAKE) capture
6773
$(QUIET)$(call silent_on_success,Analyzing models,$(INFER_BIN) analyze $(INFER_OPTIONS))
6874
sqlite3 $(RESULTS_DB) $(SQL_DUMP_MODEL_SPECS) </dev/null
69-
75+
sqlite3 $(CAPTURE_DB) $(SQL_DUMP_MODEL_PROCS) </dev/null >> $(MODELS_RESULTS_FILE)
7076

7177
ifeq ($(BUILD_C_ANALYZERS),yes)
7278
$(MODELS_RESULTS_FILE): $(CLANG_DEPS_NO_MODELS)

infer/src/IR/Attributes.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ let load_from_uid, load, clear_cache, store =
6868
(load_from_uid, load, clear_cache, store)
6969

7070

71+
let load_exn pname = Option.value_exn (load pname)
72+
7173
let load_formal_types pname =
7274
match load pname with Some {formals} -> List.map formals ~f:snd3 | None -> []
7375

infer/src/IR/Attributes.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ val load_from_uid : string -> ProcAttributes.t option
1818
val load : Procname.t -> ProcAttributes.t option
1919
(** Load the attributes for the procedure from the attributes database. *)
2020

21+
val load_exn : Procname.t -> ProcAttributes.t
22+
(** like [load], but raises an exception if no attributes are found. *)
23+
2124
val is_no_return : Procname.t -> bool
2225

2326
val load_formal_types : Procname.t -> Typ.t list

infer/src/IR/ProcAttributes.ml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ type specialized_with_aliasing_info = {orig_proc: Procname.t; aliases: Pvar.t li
5757

5858
type 'captured_var passed_closure =
5959
| Closure of (Procname.t * 'captured_var list)
60-
| Fields of 'captured_var passed_closure Fieldname.Map.t
60+
| Fields of (Fieldname.t * 'captured_var passed_closure) list
6161
[@@deriving compare, equal]
6262

6363
type specialized_with_closures_info =
@@ -130,6 +130,8 @@ let get_proc_name attributes = attributes.proc_name
130130

131131
let get_loc attributes = attributes.loc
132132

133+
let get_loc_instantiated attributes = attributes.loc_instantiated
134+
133135
let to_return_type attributes =
134136
if attributes.has_added_return_param then
135137
match List.last attributes.formals with
@@ -201,7 +203,10 @@ let pp_specialized_with_closures_info fmt info =
201203
let pp_captured_vars = Pp.semicolon_seq ~print_env:Pp.text_break CapturedVar.pp in
202204
Pp.pair ~fst:Procname.pp ~snd:pp_captured_vars fmt closure
203205
| Fields field_to_function_map ->
204-
Fieldname.Map.pp ~pp_value:pp_passed_closure fmt field_to_function_map
206+
PrettyPrintable.pp_collection
207+
~pp_item:(fun fmt (fld, func) ->
208+
F.fprintf fmt "%a->%a" Fieldname.pp fld pp_passed_closure func )
209+
fmt field_to_function_map
205210
in
206211
F.fprintf fmt "orig_procname=%a, formals_to_closures=%a" Procname.pp info.orig_proc
207212
(Pvar.Map.pp ~pp_value:pp_passed_closure)

infer/src/IR/ProcAttributes.mli

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type specialized_with_aliasing_info =
3535

3636
type 'captured_var passed_closure =
3737
| Closure of (Procname.t * 'captured_var list)
38-
| Fields of 'captured_var passed_closure Fieldname.Map.t
38+
| Fields of (Fieldname.t * 'captured_var passed_closure) list
3939
[@@deriving compare, equal]
4040

4141
type specialized_with_closures_info =
@@ -109,6 +109,9 @@ val get_formals : t -> (Mangled.t * Typ.t * Annot.Item.t) list
109109
val get_loc : t -> Location.t
110110
(** Return loc information for the procedure *)
111111

112+
val get_loc_instantiated : t -> Location.t option
113+
(** Return instantiated loc information for the procedure *)
114+
112115
val get_proc_name : t -> Procname.t
113116

114117
val get_pvar_formals : t -> (Pvar.t * Typ.t) list

infer/src/IR/Procdesc.ml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -774,19 +774,19 @@ end
774774

775775
module WTO = WeakTopologicalOrder.Bourdoncle_SCC (PreProcCfg)
776776

777+
let init_wto pdesc =
778+
let wto = WTO.make pdesc in
779+
let (_ : int) =
780+
WeakTopologicalOrder.Partition.fold_nodes wto ~init:0 ~f:(fun idx node ->
781+
node.Node.wto_index <- idx ;
782+
idx + 1 )
783+
in
784+
pdesc.wto <- Some wto
785+
786+
777787
let get_wto pdesc =
778-
match pdesc.wto with
779-
| Some wto ->
780-
wto
781-
| None ->
782-
let wto = WTO.make pdesc in
783-
let (_ : int) =
784-
WeakTopologicalOrder.Partition.fold_nodes wto ~init:0 ~f:(fun idx node ->
785-
node.Node.wto_index <- idx ;
786-
idx + 1 )
787-
in
788-
pdesc.wto <- Some wto ;
789-
wto
788+
if Option.is_none pdesc.wto then init_wto pdesc ;
789+
Option.value_exn pdesc.wto
790790

791791

792792
(** Get loop heads for widening. It collects all target nodes of back-edges in a depth-first
@@ -965,6 +965,8 @@ let load =
965965
(run_query load_statement_adb)
966966

967967

968+
let load_exn procname = load procname |> Option.value_exn
969+
968970
let mark_if_unchanged ~old_pdesc ~new_pdesc =
969971
(* map from exp names in [old_pdesc] to exp names in [new_pdesc] *)
970972
let exp_map = ref Exp.Map.empty in

infer/src/IR/Procdesc.mli

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,8 @@ val set_exit_node : t -> Node.t -> unit
344344

345345
val set_start_node : t -> Node.t -> unit
346346

347+
val init_wto : t -> unit
348+
347349
val get_wto : t -> Node.t WeakTopologicalOrder.Partition.t
348350

349351
val is_loop_head : t -> Node.t -> bool
@@ -380,5 +382,8 @@ module SQLite : SqliteUtils.Data with type t = t option
380382

381383
val load : Procname.t -> t option
382384

385+
val load_exn : Procname.t -> t
386+
(** like [load], but raises an exception if no procdesc is available. *)
387+
383388
val mark_if_unchanged : old_pdesc:t -> new_pdesc:t -> unit
384389
(** Record the [changed] attribute in-place on [new_pdesc] if it is unchanged wrt [old_pdsec] *)

infer/src/IR/Procname.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ module ObjC_Cpp : sig
156156
; kind: kind
157157
; method_name: string
158158
; parameters: Parameter.clang_parameter list
159+
(** NOTE: [parameters] should NOT include additional [this/self] or [__return_param]. *)
159160
; template_args: Typ.template_spec_info }
160161
[@@deriving compare]
161162

infer/src/absint/AnalysisCallbacks.ml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ type callbacks =
1515
-> pp_name:(Format.formatter -> unit)
1616
-> Procdesc.Node.t
1717
-> f:(unit -> 'a)
18-
-> 'a
19-
; get_model_proc_desc_f: Procname.t -> Procdesc.t option }
18+
-> 'a }
2019

2120
let callbacks_ref : callbacks option ref = ref None
2221

@@ -32,6 +31,3 @@ let get_callbacks () =
3231

3332
let html_debug_new_node_session ?kind ~pp_name node ~f =
3433
(get_callbacks ()).html_debug_new_node_session_f ?kind ~pp_name node ~f
35-
36-
37-
let get_model_proc_desc proc_name = (get_callbacks ()).get_model_proc_desc_f proc_name

infer/src/absint/AnalysisCallbacks.mli

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ open! IStd
99

1010
(** {2 Analysis API} *)
1111

12-
val get_model_proc_desc : Procname.t -> Procdesc.t option
13-
(** get the preanalysed procdesc of a model; raises if procname given is not a biabduction model *)
14-
1512
val html_debug_new_node_session :
1613
?kind:[`ComputePre | `ExecNode | `ExecNodeNarrowing | `WTO]
1714
-> pp_name:(Format.formatter -> unit)
@@ -32,8 +29,7 @@ type callbacks =
3229
-> pp_name:(Format.formatter -> unit)
3330
-> Procdesc.Node.t
3431
-> f:(unit -> 'a)
35-
-> 'a
36-
; get_model_proc_desc_f: Procname.t -> Procdesc.t option }
32+
-> 'a }
3733

3834
val set_callbacks : callbacks -> unit
3935
(** make sure this is called before starting any actual analysis *)

infer/src/absint/ClosureSpecialization.ml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ let pname_with_closure_actuals callee_pname formals_to_closures =
1616
| ProcAttributes.Closure (pname, _) when Procname.is_objc_block pname || Procname.is_c pname ->
1717
Procname.to_function_parameter pname :: acc
1818
| ProcAttributes.Fields passed_closures ->
19-
Fieldname.Map.fold
20-
(fun _ passed_closure acc -> get_function_parameters acc passed_closure)
21-
passed_closures acc
19+
List.fold_right passed_closures ~init:acc ~f:(fun (_, passed_closure) acc ->
20+
get_function_parameters acc passed_closure )
2221
| _ ->
2322
acc
2423
in
@@ -56,9 +55,9 @@ let rec get_captured_in_passed_closure captured_vars_acc = function
5655
| ProcAttributes.Closure (_, captured_vars) ->
5756
captured_vars :: captured_vars_acc
5857
| ProcAttributes.Fields passed_closures ->
59-
Fieldname.Map.fold
60-
(fun _ actual captured_vars_acc -> get_captured_in_passed_closure captured_vars_acc actual)
61-
passed_closures captured_vars_acc
58+
List.fold_right passed_closures ~init:captured_vars_acc
59+
~f:(fun (_, actual) captured_vars_acc ->
60+
get_captured_in_passed_closure captured_vars_acc actual )
6261

6362

6463
let get_captured actuals =

0 commit comments

Comments
 (0)