Skip to content

Commit

Permalink
[clang] Remove parameters from c function procnames
Browse files Browse the repository at this point in the history
Summary: Parameter lists are not needed in C functions. There is mangling in the name already to deal with either C++ mangling or different compilation units in C.

Reviewed By: ngorogiannis

Differential Revision: D53091487

fbshipit-source-id: ce3ee58cfd4168f6e15c9269d332e58ff8b3be8a
  • Loading branch information
dulmarod authored and facebook-github-bot committed Jan 26, 2024
1 parent 8f98065 commit 8a743a2
Show file tree
Hide file tree
Showing 31 changed files with 478 additions and 498 deletions.
34 changes: 11 additions & 23 deletions infer/src/IR/Procname.ml
Original file line number Diff line number Diff line change
Expand Up @@ -401,23 +401,16 @@ end

module C = struct
(** Type of c procedure names. *)
type t =
{ name: QualifiedCppName.t
; mangled: string option
; parameters: Parameter.clang_parameter list
; template_args: Typ.template_spec_info }
type t = {name: QualifiedCppName.t; mangled: string option; template_args: Typ.template_spec_info}
[@@deriving compare, equal, yojson_of, sexp, hash, normalize]

let c name ?mangled parameters template_args = {name; mangled; parameters; template_args}
let c name ?mangled template_args = {name; mangled; template_args}

let from_string name =
{ name= QualifiedCppName.of_qual_string name
; mangled= None
; parameters= []
; template_args= NoTemplate }
{name= QualifiedCppName.of_qual_string name; mangled= None; template_args= NoTemplate}


let pp verbosity fmt {name; mangled; parameters} =
let pp verbosity fmt {name; mangled} =
let plain = QualifiedCppName.to_qual_string name in
match verbosity with
| Simple ->
Expand All @@ -426,18 +419,14 @@ module C = struct
F.pp_print_string fmt plain
| Verbose ->
let pp_mangled fmt = function None -> () | Some s -> F.fprintf fmt "{%s}" s in
F.fprintf fmt "%s%a%a" plain Parameter.pp_parameters parameters pp_mangled mangled
F.fprintf fmt "%s%a" plain pp_mangled mangled


let pp_without_templates fmt {name} =
let plain = QualifiedCppName.to_qual_string name in
F.pp_print_string fmt (remove_templates plain)


let get_parameters c = c.parameters

let replace_parameters new_parameters c = {c with parameters= new_parameters}

(** NOTE: [std::_] is parsed as [C] proc name in Sil, rather than [ObjC_Cpp]. *)
let is_std_function ~prefix {name} =
match QualifiedCppName.to_rev_list name with
Expand Down Expand Up @@ -1355,8 +1344,8 @@ let rec get_parameters procname =
List.map ~f:(fun par -> Parameter.JavaParameter par) (Java.get_parameters j)
| CSharp cs ->
List.map ~f:(fun par -> Parameter.CSharpParameter par) (CSharp.get_parameters cs)
| C osig ->
clang_param_to_param (C.get_parameters osig)
| C _ ->
[]
| Erlang e ->
List.init e.arity ~f:(fun _ -> Parameter.ErlangParameter)
| Hack _ ->
Expand Down Expand Up @@ -1427,8 +1416,8 @@ let rec replace_parameters new_parameters procname =
Java (Java.replace_parameters (params_to_java_params new_parameters) j)
| CSharp cs ->
CSharp (CSharp.replace_parameters (params_to_csharp_params new_parameters) cs)
| C osig ->
C (C.replace_parameters (params_to_clang_params new_parameters) osig)
| C _ ->
procname
| Erlang e ->
Erlang (Erlang.set_arity (params_to_erlang_arity new_parameters) e)
| Hack _ ->
Expand Down Expand Up @@ -1542,10 +1531,9 @@ let to_short_unique_name pname =
in
let proc_id =
match pname with
| C {parameters; mangled} ->
| C {mangled} ->
let pp_mangled fmt = function None -> () | Some mangled -> F.fprintf fmt "#%s" mangled in
F.asprintf "%a%a%a" pp_rev_qualified pname Parameter.pp_parameters parameters pp_mangled
mangled
F.asprintf "%a%a" pp_rev_qualified pname pp_mangled mangled
| ObjC_Cpp objc_cpp ->
F.asprintf "%a%a#%a" pp_rev_qualified pname Parameter.pp_parameters objc_cpp.parameters
ObjC_Cpp.pp_verbose_kind objc_cpp.kind
Expand Down
12 changes: 2 additions & 10 deletions infer/src/IR/Procname.mli
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,9 @@ end
module C : sig
(** Type of c procedure names. *)
type t = private
{ name: QualifiedCppName.t
; mangled: string option
; parameters: Parameter.clang_parameter list
; template_args: Typ.template_spec_info }
{name: QualifiedCppName.t; mangled: string option; template_args: Typ.template_spec_info}

val c :
QualifiedCppName.t
-> ?mangled:string
-> Parameter.clang_parameter list
-> Typ.template_spec_info
-> t
val c : QualifiedCppName.t -> ?mangled:string -> Typ.template_spec_info -> t
(** Create a C procedure name from plain and mangled name. *)

val is_make_shared : t -> bool
Expand Down
2 changes: 1 addition & 1 deletion infer/src/IR/Pvar.ml
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ let get_initializer_pname {pv_name; pv_kind} =
SourceFile.to_string file |> Utils.string_crc_hex32 |> Option.return
else Some None
in
Procname.C (Procname.C.c qual_name ?mangled [] template_args)
Procname.C (Procname.C.c qual_name ?mangled template_args)
| _ ->
None

Expand Down
8 changes: 4 additions & 4 deletions infer/src/clang/CType_decl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ and get_template_info tenv (fdi : Clang_ast_t.function_decl_info) =
Typ.NoTemplate


and mk_c_function ?tenv name function_decl_info_opt parameters =
and mk_c_function ?tenv name function_decl_info_opt =
let file =
match function_decl_info_opt with
(* when we model static functions, we cannot take the file into account to
Expand Down Expand Up @@ -543,7 +543,7 @@ and mk_c_function ?tenv name function_decl_info_opt parameters =
in
let mangled = file ^ mangled_name in
if String.is_empty mangled then Procname.from_string_c_fun (QualifiedCppName.to_qual_string name)
else Procname.C (Procname.C.c name ~mangled parameters template_info)
else Procname.C (Procname.C.c name ~mangled template_info)


and mk_cpp_method ?tenv class_name method_name ?meth_decl mangled parameters =
Expand Down Expand Up @@ -617,7 +617,7 @@ and procname_from_decl ?tenv ?block_return_type ?outer_proc meth_decl =
match meth_decl with
| FunctionDecl (decl_info, name_info, _, fdi) ->
let name = CAst_utils.get_qualified_name name_info in
mk_c_function ?tenv name (Some (decl_info, fdi)) parameters
mk_c_function ?tenv name (Some (decl_info, fdi))
| CXXConstructorDecl (decl_info, {ni_name= ""; ni_qual_name= "" :: qual_names}, _, fdi, mdi) ->
(* For some constructors of non-class objects in C++, the clang frontend gives empty method
name, e.g. struct, lambda, and union. For better readability, we replace them to a
Expand Down Expand Up @@ -744,7 +744,7 @@ module CProcname = struct
module NoAstDecl = struct
let c_function_of_string tenv name =
let qual_name = QualifiedCppName.of_qual_string name in
mk_c_function ~tenv qual_name None []
mk_c_function ~tenv qual_name None


let cpp_method_of_string tenv class_name method_name =
Expand Down
94 changes: 47 additions & 47 deletions infer/tests/build_systems/disjunctive_domain/disjunctive.exp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ monotonically increases as the disjunct limit increases

N_disjuncts = 1

three_branch:
four_branch:
1 disjuncts:
#0: 0

Non-disj state: ⊥
CFG Metadata: dropped_disjuncts= 2; interrupted_loops= 0
CFG Metadata: dropped_disjuncts= 3; interrupted_loops= 0

two_branch:
1 disjuncts:
Expand All @@ -18,19 +18,12 @@ two_branch:
Non-disj state: ⊥
CFG Metadata: dropped_disjuncts= 1; interrupted_loops= 0

loop:
1 disjuncts:
#0: two_branch0.0

Non-disj state: ⊥
CFG Metadata: dropped_disjuncts= 3; interrupted_loops= 0

four_branch:
three_branch:
1 disjuncts:
#0: 0

Non-disj state: ⊥
CFG Metadata: dropped_disjuncts= 3; interrupted_loops= 0
CFG Metadata: dropped_disjuncts= 2; interrupted_loops= 0

sequence:
1 disjuncts:
Expand All @@ -39,17 +32,25 @@ sequence:
Non-disj state: ⊥
CFG Metadata: dropped_disjuncts= 0; interrupted_loops= 0

loop:
1 disjuncts:
#0: two_branch0.0

Non-disj state: ⊥
CFG Metadata: dropped_disjuncts= 3; interrupted_loops= 0


No issues found

----------------------------------------
N_disjuncts = 4

three_branch:
3 disjuncts:
four_branch:
4 disjuncts:
#0: 0
#1: 2
#2: 1
#3: 3

Non-disj state: ⊥
CFG Metadata: dropped_disjuncts= 0; interrupted_loops= 0
Expand All @@ -62,22 +63,11 @@ two_branch:
Non-disj state: ⊥
CFG Metadata: dropped_disjuncts= 0; interrupted_loops= 0

loop:
4 disjuncts:
#0: two_branch0.0
#1: two_branch0.1
#2: two_branch0.0.two_branch1.0
#3: two_branch0.0.two_branch1.1

Non-disj state: ⊥
CFG Metadata: dropped_disjuncts= 13; interrupted_loops= 0

four_branch:
4 disjuncts:
three_branch:
3 disjuncts:
#0: 0
#1: 2
#2: 1
#3: 3

Non-disj state: ⊥
CFG Metadata: dropped_disjuncts= 0; interrupted_loops= 0
Expand All @@ -92,17 +82,28 @@ sequence:
Non-disj state: ⊥
CFG Metadata: dropped_disjuncts= 5; interrupted_loops= 0

loop:
4 disjuncts:
#0: two_branch0.0
#1: two_branch0.1
#2: two_branch0.0.two_branch1.0
#3: two_branch0.0.two_branch1.1

Non-disj state: ⊥
CFG Metadata: dropped_disjuncts= 13; interrupted_loops= 0


No issues found

----------------------------------------
N_disjuncts = 10

three_branch:
3 disjuncts:
four_branch:
4 disjuncts:
#0: 0
#1: 2
#2: 1
#3: 3

Non-disj state: ⊥
CFG Metadata: dropped_disjuncts= 0; interrupted_loops= 0
Expand All @@ -115,28 +116,11 @@ two_branch:
Non-disj state: ⊥
CFG Metadata: dropped_disjuncts= 0; interrupted_loops= 0

loop:
10 disjuncts:
#0: two_branch0.0
#1: two_branch0.1
#2: two_branch0.0.two_branch1.0
#3: two_branch0.0.two_branch1.1
#4: two_branch0.1.two_branch2.0
#5: two_branch0.1.two_branch2.1
#6: two_branch0.0.two_branch1.0.two_branch3.0
#7: two_branch0.0.two_branch1.0.two_branch3.1
#8: two_branch0.0.two_branch1.1.two_branch4.0
#9: two_branch0.0.two_branch1.1.two_branch4.1

Non-disj state: ⊥
CFG Metadata: dropped_disjuncts= 19; interrupted_loops= 1

four_branch:
4 disjuncts:
three_branch:
3 disjuncts:
#0: 0
#1: 2
#2: 1
#3: 3

Non-disj state: ⊥
CFG Metadata: dropped_disjuncts= 0; interrupted_loops= 0
Expand All @@ -157,5 +141,21 @@ sequence:
Non-disj state: ⊥
CFG Metadata: dropped_disjuncts= 5; interrupted_loops= 0

loop:
10 disjuncts:
#0: two_branch0.0
#1: two_branch0.1
#2: two_branch0.0.two_branch1.0
#3: two_branch0.0.two_branch1.1
#4: two_branch0.1.two_branch2.0
#5: two_branch0.1.two_branch2.1
#6: two_branch0.0.two_branch1.0.two_branch3.0
#7: two_branch0.0.two_branch1.0.two_branch3.1
#8: two_branch0.0.two_branch1.1.two_branch4.0
#9: two_branch0.0.two_branch1.1.two_branch4.1

Non-disj state: ⊥
CFG Metadata: dropped_disjuncts= 19; interrupted_loops= 1


No issues found
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ digraph callgraph {
N5 [ label = "f\nflag=false" ];
N5 -> N4 ;

N0 [ label = "g\nflag=false" ];
N0 [ label = "b\nflag=false" ];
N0 -> N1 ;

N7 [ label = "main\nflag=false" ];
Expand All @@ -18,10 +18,10 @@ digraph callgraph {
N4 -> N6 ;
N4 -> N3 ;

N2 [ label = "b\nflag=false" ];
N2 [ label = "g\nflag=false" ];
N2 -> N1 ;

N3 [ label = "c\nflag=false" ];
N3 -> N2 ;
N3 -> N0 ;

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ digraph callgraph {
N5 [ label = "f\nflag=false" ];
N5 -> N4 ;

N0 [ label = "g\nflag=false" ];
N0 [ label = "b\nflag=false" ];
N0 -> N1 ;

N7 [ label = "main\nflag=false" ];
Expand All @@ -18,10 +18,10 @@ digraph callgraph {
N4 -> N6 ;
N4 -> N3 ;

N2 [ label = "b\nflag=false" ];
N2 [ label = "g\nflag=false" ];
N2 -> N1 ;

N3 [ label = "c\nflag=false" ];
N3 -> N2 ;
N3 -> N0 ;

}
2 changes: 1 addition & 1 deletion infer/tests/build_systems/replay_scheduler/schedule.exp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
schema_version=0
0|foo|1,2|
1|goo|3|0
2|goo|3|0
3|moo||
Loading

0 comments on commit 8a743a2

Please sign in to comment.