Deal with empty parameter names

Summary:
public
C++ allows for parameters with empty names (unused/default copy constructors). Make backend happy by assigning a non-empty
name to these variables

Reviewed By: jvillard

Differential Revision: D2895550

fb-gh-sync-id: b466397
master
Andrzej Kotulski 9 years ago committed by facebook-github-bot-1
parent 70dbe8db74
commit 36fb1f202c

@ -1 +1 @@
Subproject commit df8dc4e093b0f8147e5d8dc06e3e5316ceac865a
Subproject commit d07910830a3ccf56c10a4eaf9c8dcad23ecb4d9b

@ -54,6 +54,7 @@ let empty_var_decl_info = {
vdi_is_module_private = false;
vdi_is_nrvo_variable = false;
vdi_init_expr = None;
vdi_parm_index_in_function = None;
}
let stmt_info_with_fresh_pointer stmt_info = {

@ -573,11 +573,19 @@ struct
let type_name_crc = Some (CRC.crc16 type_name) in
Procname.mangled_c_method class_name method_name type_name_crc
let get_var_name_string name_info var_decl_info =
let clang_name = Ast_utils.get_qualified_name name_info in
match clang_name, var_decl_info.Clang_ast_t.vdi_parm_index_in_function with
| "", Some index -> "__param_" ^ string_of_int index
| "", None -> assert false
| _ -> clang_name
let mk_sil_var name decl_info_type_ptr_opt procname outer_procname =
let name_string = Ast_utils.get_qualified_name name in
let simple_name = Mangled.from_string name_string in
match decl_info_type_ptr_opt with
| Some (decl_info, type_ptr, var_decl_info, should_be_mangled) ->
let name_string = get_var_name_string name var_decl_info in
let simple_name = Mangled.from_string name_string in
if var_decl_info.Clang_ast_t.vdi_is_global then
let global_mangled_name =
if var_decl_info.Clang_ast_t.vdi_is_static_local then
@ -593,7 +601,7 @@ struct
let mangled = CRC.crc16 (type_name ^ line_str) in
let mangled_name = Mangled.mangled name_string mangled in
Sil.mk_pvar mangled_name procname
| None -> Sil.mk_pvar simple_name procname
| None -> Sil.mk_pvar (Mangled.from_string name_string) procname
let is_cpp_translation language =
language = CFrontend_config.CPP || language = CFrontend_config.OBJCPP

@ -179,6 +179,8 @@ sig
val mk_class_field_name : Clang_ast_t.named_decl_info -> Ident.fieldname
val get_var_name_string : Clang_ast_t.named_decl_info -> Clang_ast_t.var_decl_info -> string
val mk_sil_var : Clang_ast_t.named_decl_info -> var_info option -> Procname.t -> Procname.t ->
Sil.pvar

@ -103,7 +103,7 @@ let get_parameters tenv function_method_decl_info =
let par_to_ms_par par =
match par with
| Clang_ast_t.ParmVarDecl (decl_info, name_info, type_ptr, var_decl_info) ->
let name = name_info.Clang_ast_t.ni_name in
let name = General_utils.get_var_name_string name_info var_decl_info in
(name, type_ptr)
| _ -> assert false in
let pars = IList.map par_to_ms_par (get_param_decls function_method_decl_info) in

@ -32,7 +32,7 @@ digraph iCFG {
4 [label="4: Exit X_X \n " color=yellow style=filled]
3 [label="3: Start X_X\nFormals: this:class X * :void \nLocals: \n DECLARE_LOCALS(&return); [line 10]\n NULLIFY(&,false); [line 10]\n NULLIFY(&this,false); [line 10]\n " color=yellow style=filled]
3 [label="3: Start X_X\nFormals: this:class X * __param_0:void \nLocals: \n DECLARE_LOCALS(&return); [line 10]\n NULLIFY(&__param_0,false); [line 10]\n NULLIFY(&this,false); [line 10]\n " color=yellow style=filled]
3 -> 4 ;

@ -17,6 +17,10 @@ int fun_default_decl(int a, int b) {
return a + b;
}
int fun_ignore_param(int a, int, int) {
return a;
}
void test() {
fun_default(1, 2);
fun_default(1);
@ -25,3 +29,7 @@ void test() {
fun_default_decl(6);
fun_default_decl(6,6);
}
void test2() {
fun_ignore_param(1, 1, 1);
}

@ -1,31 +1,53 @@
digraph iCFG {
13 [label="13: Call _fun_fun_default \n n$4=_fun_fun_default(1:int ,2:int ) [line 21]\n REMOVE_TEMPS(n$4); [line 21]\n " shape="box"]
19 [label="19: Call _fun_fun_ignore_param \n n$0=_fun_fun_ignore_param(1:int ,1:int ,1:int ) [line 34]\n REMOVE_TEMPS(n$0); [line 34]\n APPLY_ABSTRACTION; [line 34]\n " shape="box"]
19 -> 18 ;
18 [label="18: Exit test2 \n " color=yellow style=filled]
17 [label="17: Start test2\nFormals: \nLocals: \n DECLARE_LOCALS(&return); [line 33]\n " color=yellow style=filled]
17 -> 19 ;
16 [label="16: Call _fun_fun_default \n n$4=_fun_fun_default(1:int ,2:int ) [line 25]\n REMOVE_TEMPS(n$4); [line 25]\n " shape="box"]
16 -> 15 ;
15 [label="15: Call _fun_fun_default \n n$3=_fun_fun_default(1:int ,5:int ) [line 26]\n REMOVE_TEMPS(n$3); [line 26]\n " shape="box"]
15 -> 14 ;
14 [label="14: Call _fun_fun_default \n n$2=_fun_fun_default(3:int ,5:int ) [line 27]\n REMOVE_TEMPS(n$2); [line 27]\n " shape="box"]
14 -> 13 ;
13 [label="13: Call _fun_fun_default_decl \n n$1=_fun_fun_default_decl(6:int ,5:int ) [line 29]\n REMOVE_TEMPS(n$1); [line 29]\n " shape="box"]
13 -> 12 ;
12 [label="12: Call _fun_fun_default \n n$3=_fun_fun_default(1:int ,5:int ) [line 22]\n REMOVE_TEMPS(n$3); [line 22]\n " shape="box"]
12 [label="12: Call _fun_fun_default_decl \n n$0=_fun_fun_default_decl(6:int ,6:int ) [line 30]\n REMOVE_TEMPS(n$0); [line 30]\n APPLY_ABSTRACTION; [line 30]\n " shape="box"]
12 -> 11 ;
11 [label="11: Call _fun_fun_default \n n$2=_fun_fun_default(3:int ,5:int ) [line 23]\n REMOVE_TEMPS(n$2); [line 23]\n " shape="box"]
11 [label="11: Exit test \n " color=yellow style=filled]
11 -> 10 ;
10 [label="10: Call _fun_fun_default_decl \n n$1=_fun_fun_default_decl(6:int ,5:int ) [line 25]\n REMOVE_TEMPS(n$1); [line 25]\n " shape="box"]
10 [label="10: Start test\nFormals: \nLocals: \n DECLARE_LOCALS(&return); [line 24]\n " color=yellow style=filled]
10 -> 9 ;
9 [label="9: Call _fun_fun_default_decl \n n$0=_fun_fun_default_decl(6:int ,6:int ) [line 26]\n REMOVE_TEMPS(n$0); [line 26]\n APPLY_ABSTRACTION; [line 26]\n " shape="box"]
10 -> 16 ;
9 [label="9: Return Stmt \n n$0=*&a:int [line 21]\n *&return:int =n$0 [line 21]\n REMOVE_TEMPS(n$0); [line 21]\n NULLIFY(&a,false); [line 21]\n APPLY_ABSTRACTION; [line 21]\n " shape="box"]
9 -> 8 ;
8 [label="8: Exit test \n " color=yellow style=filled]
8 [label="8: Exit fun_ignore_param \n " color=yellow style=filled]
7 [label="7: Start test\nFormals: \nLocals: \n DECLARE_LOCALS(&return); [line 20]\n " color=yellow style=filled]
7 [label="7: Start fun_ignore_param\nFormals: a:int __param_1:int __param_2:int \nLocals: \n DECLARE_LOCALS(&return); [line 20]\n NULLIFY(&__param_1,false); [line 20]\n NULLIFY(&__param_2,false); [line 20]\n " color=yellow style=filled]
7 -> 13 ;
7 -> 9 ;
6 [label="6: Return Stmt \n n$0=*&a:int [line 17]\n n$1=*&b:int [line 17]\n *&return:int =(n$0 + n$1) [line 17]\n REMOVE_TEMPS(n$0,n$1); [line 17]\n NULLIFY(&a,false); [line 17]\n NULLIFY(&b,false); [line 17]\n APPLY_ABSTRACTION; [line 17]\n " shape="box"]

Loading…
Cancel
Save