[clang] get rid of FallbackNode

Summary: Dummy names are bad for debugging.

Reviewed By: da319

Differential Revision: D24991563

fbshipit-source-id: 799d2b071
master
Jules Villard 4 years ago committed by Facebook GitHub Bot
parent 2efa22073c
commit 3d588b2751

@ -62,7 +62,9 @@ module Node = struct
| BinaryOperatorStmt of string | BinaryOperatorStmt of string
| Call of string | Call of string
| CallObjCNew | CallObjCNew
| CaseStmt
| ClassCastException | ClassCastException
| CompoundStmt
| ConditionalStmtBranch | ConditionalStmtBranch
| ConstructorInit | ConstructorInit
| CXXDynamicCast | CXXDynamicCast
@ -75,7 +77,6 @@ module Node = struct
| ExceptionHandler | ExceptionHandler
| ExceptionsSink | ExceptionsSink
| ExprWithCleanups | ExprWithCleanups
| FallbackNode
| FinallyBranch | FinallyBranch
| GCCAsmStmt | GCCAsmStmt
| GenericSelectionExpr | GenericSelectionExpr
@ -87,6 +88,7 @@ module Node = struct
| MonitorEnter | MonitorEnter
| MonitorExit | MonitorExit
| ObjCCPPThrow | ObjCCPPThrow
| ObjCIndirectCopyRestoreExpr
| OutOfBound | OutOfBound
| ReturnStmt | ReturnStmt
| Scope of string | Scope of string
@ -288,8 +290,12 @@ module Node = struct
F.fprintf fmt "Call %s" call F.fprintf fmt "Call %s" call
| CallObjCNew -> | CallObjCNew ->
F.pp_print_string fmt "Call objC new" F.pp_print_string fmt "Call objC new"
| CaseStmt ->
F.pp_print_string fmt "CaseStmt"
| ClassCastException -> | ClassCastException ->
F.pp_print_string fmt "Class cast exception" F.pp_print_string fmt "Class cast exception"
| CompoundStmt ->
F.pp_print_string fmt "Compound statement"
| ConditionalStmtBranch -> | ConditionalStmtBranch ->
F.pp_print_string fmt "ConditionalStmt Branch" F.pp_print_string fmt "ConditionalStmt Branch"
| ConstructorInit -> | ConstructorInit ->
@ -314,8 +320,6 @@ module Node = struct
F.pp_print_string fmt "exceptions sink" F.pp_print_string fmt "exceptions sink"
| ExprWithCleanups -> | ExprWithCleanups ->
F.pp_print_string fmt "ExprWithCleanups" F.pp_print_string fmt "ExprWithCleanups"
| FallbackNode ->
F.pp_print_string fmt "Fallback node"
| FinallyBranch -> | FinallyBranch ->
F.pp_print_string fmt "Finally branch" F.pp_print_string fmt "Finally branch"
| GCCAsmStmt -> | GCCAsmStmt ->
@ -338,6 +342,8 @@ module Node = struct
F.pp_print_string fmt "MonitorExit" F.pp_print_string fmt "MonitorExit"
| ObjCCPPThrow -> | ObjCCPPThrow ->
F.pp_print_string fmt "ObjCCPPThrow" F.pp_print_string fmt "ObjCCPPThrow"
| ObjCIndirectCopyRestoreExpr ->
F.pp_print_string fmt "ObjCIndirectCopyRestoreExpr"
| OutOfBound -> | OutOfBound ->
F.pp_print_string fmt "Out of bound" F.pp_print_string fmt "Out of bound"
| ReturnStmt -> | ReturnStmt ->

@ -43,7 +43,9 @@ module Node : sig
| BinaryOperatorStmt of string | BinaryOperatorStmt of string
| Call of string | Call of string
| CallObjCNew | CallObjCNew
| CaseStmt
| ClassCastException | ClassCastException
| CompoundStmt
| ConditionalStmtBranch | ConditionalStmtBranch
| ConstructorInit | ConstructorInit
| CXXDynamicCast | CXXDynamicCast
@ -56,7 +58,6 @@ module Node : sig
| ExceptionHandler | ExceptionHandler
| ExceptionsSink | ExceptionsSink
| ExprWithCleanups | ExprWithCleanups
| FallbackNode
| FinallyBranch | FinallyBranch
| GCCAsmStmt | GCCAsmStmt
| GenericSelectionExpr | GenericSelectionExpr
@ -68,6 +69,7 @@ module Node : sig
| MonitorEnter | MonitorEnter
| MonitorExit | MonitorExit
| ObjCCPPThrow | ObjCCPPThrow
| ObjCIndirectCopyRestoreExpr
| OutOfBound | OutOfBound
| ReturnStmt | ReturnStmt
| Scope of string | Scope of string

@ -124,7 +124,9 @@ let get_init_list_instrs method_decl =
| CXXConstructorDecl (_, _, _, _, mdi) | CXXConstructorDecl (_, _, _, _, mdi)
| CXXConversionDecl (_, _, _, _, mdi) | CXXConversionDecl (_, _, _, _, mdi)
| CXXDestructorDecl (_, _, _, _, mdi) -> | CXXDestructorDecl (_, _, _, _, mdi) ->
let create_custom_instr construct_instr = `CXXConstructorInit construct_instr in let create_custom_instr construct_instr =
CFrontend_config.CXXConstructorInit construct_instr
in
List.map ~f:create_custom_instr mdi.xmdi_cxx_ctor_initializers List.map ~f:create_custom_instr mdi.xmdi_cxx_ctor_initializers
| _ -> | _ ->
[] []

@ -23,8 +23,7 @@ val is_cpp_lambda_call_operator : Clang_ast_t.decl -> bool
val is_cpp_virtual : Clang_ast_t.decl -> bool val is_cpp_virtual : Clang_ast_t.decl -> bool
val get_init_list_instrs : val get_init_list_instrs : Clang_ast_t.decl -> CFrontend_config.instr_type list
Clang_ast_t.decl -> [> `CXXConstructorInit of Clang_ast_t.cxx_ctor_initializer] list
val get_pointer_to_property : Clang_ast_t.decl -> Clang_ast_t.pointer option val get_pointer_to_property : Clang_ast_t.decl -> Clang_ast_t.pointer option

@ -63,9 +63,7 @@ val method_signature_body_of_decl :
-> ?block_return_type:Clang_ast_t.qual_type -> ?block_return_type:Clang_ast_t.qual_type
-> ?passed_as_noescape_block_to:Procname.t option -> ?passed_as_noescape_block_to:Procname.t option
-> Procname.t -> Procname.t
-> CMethodSignature.t -> CMethodSignature.t * Clang_ast_t.stmt option * CFrontend_config.instr_type list
* Clang_ast_t.stmt option
* [> `CXXConstructorInit of Clang_ast_t.cxx_ctor_initializer] list
val should_add_return_param : Typ.t -> is_objc_method:bool -> bool val should_add_return_param : Typ.t -> is_objc_method:bool -> bool

@ -21,6 +21,10 @@ type translation_unit_context =
type decl_trans_context = [`DeclTraversal | `Translation | `CppLambdaExprTranslation] type decl_trans_context = [`DeclTraversal | `Translation | `CppLambdaExprTranslation]
type instr_type =
| ClangStmt of Procdesc.Node.stmt_nodekind * Clang_ast_t.stmt
| CXXConstructorInit of Clang_ast_t.cxx_ctor_initializer
(** Constants *) (** Constants *)
let alloc = "alloc" let alloc = "alloc"

@ -21,6 +21,10 @@ type translation_unit_context =
type decl_trans_context = [`DeclTraversal | `Translation | `CppLambdaExprTranslation] type decl_trans_context = [`DeclTraversal | `Translation | `CppLambdaExprTranslation]
type instr_type =
| ClangStmt of Procdesc.Node.stmt_nodekind * Clang_ast_t.stmt
| CXXConstructorInit of Clang_ast_t.cxx_ctor_initializer
(** Constants *) (** Constants *)
val alloc : string val alloc : string

@ -14,16 +14,13 @@ type block_data =
; procname: Procname.t ; procname: Procname.t
; return_type: Clang_ast_t.qual_type } ; return_type: Clang_ast_t.qual_type }
type instr_type =
[`ClangStmt of Clang_ast_t.stmt | `CXXConstructorInit of Clang_ast_t.cxx_ctor_initializer]
module type CTranslation = sig module type CTranslation = sig
(** Translates instructions: (statements and expressions) from the ast into sil *) (** Translates instructions: (statements and expressions) from the ast into sil *)
val instructions_trans : val instructions_trans :
CContext.t CContext.t
-> Clang_ast_t.stmt -> Clang_ast_t.stmt
-> instr_type list -> CFrontend_config.instr_type list
-> Procdesc.Node.t -> Procdesc.Node.t
-> is_destructor_wrapper:bool -> is_destructor_wrapper:bool
-> Procdesc.Node.t list -> Procdesc.Node.t list

@ -100,7 +100,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
else f trans_state e else f trans_state e
let exec_with_node_creation ~f trans_state stmt = let exec_with_node_creation node_name ~f trans_state stmt =
let res_trans = f trans_state stmt in let res_trans = f trans_state stmt in
if not (List.is_empty res_trans.control.instrs) then if not (List.is_empty res_trans.control.instrs) then
let stmt_info, _ = Clang_ast_proj.get_stmt_tuple stmt in let stmt_info, _ = Clang_ast_proj.get_stmt_tuple stmt in
@ -110,8 +110,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
CLocation.location_of_stmt_info trans_state.context.translation_unit_context.source_file CLocation.location_of_stmt_info trans_state.context.translation_unit_context.source_file
stmt_info' stmt_info'
in in
PriorityNode.compute_result_to_parent trans_state_pri sil_loc ~node_name:FallbackNode PriorityNode.compute_result_to_parent trans_state_pri sil_loc ~node_name stmt_info' res_trans
stmt_info' res_trans
else res_trans else res_trans
@ -1576,7 +1575,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
and compoundStmt_trans trans_state stmt_list = and compoundStmt_trans trans_state stmt_list =
let compound_control, returns = instructions trans_state stmt_list in let compound_control, returns = instructions Procdesc.Node.CompoundStmt trans_state stmt_list in
mk_trans_result (last_or_mk_fresh_void_exp_typ returns) compound_control mk_trans_result (last_or_mk_fresh_void_exp_typ returns) compound_control
@ -1939,7 +1938,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
assert false assert false
in in
L.debug Capture Verbose "translating a caseStmt@\n" ; L.debug Capture Verbose "translating a caseStmt@\n" ;
let body_trans_result = exec_with_node_creation ~f:instruction trans_state body in let body_trans_result = exec_with_node_creation CaseStmt ~f:instruction trans_state body in
L.debug Capture Verbose "result of translating a caseStmt: %a@\n" pp_control L.debug Capture Verbose "result of translating a caseStmt: %a@\n" pp_control
body_trans_result.control ; body_trans_result.control ;
SwitchCase.add SwitchCase.add
@ -2400,7 +2399,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
field_exps (List.length stmts) field_exps (List.length stmts)
(Pp.seq ~sep:"," (Pp.of_string ~f:Clang_ast_proj.get_stmt_kind_string)) (Pp.seq ~sep:"," (Pp.of_string ~f:Clang_ast_proj.get_stmt_kind_string))
stmts ; stmts ;
let control, _ = instructions trans_state stmts in let control, _ = instructions Procdesc.Node.InitListExp trans_state stmts in
[mk_trans_result (var_exp, var_typ) control] ) [mk_trans_result (var_exp, var_typ) control] )
@ -3438,7 +3437,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
in in
let trans_state_placement = {trans_state with succ_nodes= []; var_exp_typ= None} in let trans_state_placement = {trans_state with succ_nodes= []; var_exp_typ= None} in
let res_trans_placement_control, res_trans_placement_exps = let res_trans_placement_control, res_trans_placement_exps =
instructions trans_state_placement placement_args instructions Procdesc.Node.CXXNewExpr trans_state_placement placement_args
in in
let res_trans_new = let res_trans_new =
cpp_new_trans context.translation_unit_context.integer_type_widths sil_loc typ size_exp_opt cpp_new_trans context.translation_unit_context.integer_type_widths sil_loc typ size_exp_opt
@ -4096,7 +4095,9 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
| ObjCAtSynchronizedStmt (_, stmt_list) -> | ObjCAtSynchronizedStmt (_, stmt_list) ->
objCAtSynchronizedStmt_trans trans_state stmt_list objCAtSynchronizedStmt_trans trans_state stmt_list
| ObjCIndirectCopyRestoreExpr (_, stmt_list, _) -> | ObjCIndirectCopyRestoreExpr (_, stmt_list, _) ->
let control, returns = instructions trans_state stmt_list in let control, returns =
instructions Procdesc.Node.ObjCIndirectCopyRestoreExpr trans_state stmt_list
in
mk_trans_result (last_or_mk_fresh_void_exp_typ returns) control mk_trans_result (last_or_mk_fresh_void_exp_typ returns) control
| BlockExpr (stmt_info, _, expr_info, decl) -> | BlockExpr (stmt_info, _, expr_info, decl) ->
blockExpr_trans trans_state stmt_info expr_info decl blockExpr_trans trans_state stmt_info expr_info decl
@ -4369,21 +4370,21 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
, List.rev rev_returns ) , List.rev rev_returns )
and get_clang_stmt_trans stmt trans_state = and get_clang_stmt_trans node_name stmt trans_state =
exec_with_node_creation ~f:instruction trans_state stmt exec_with_node_creation ~f:instruction node_name trans_state stmt
and get_custom_stmt_trans stmt = and get_custom_stmt_trans stmt trans_state =
match stmt with match (stmt : CFrontend_config.instr_type) with
| `ClangStmt stmt -> | ClangStmt (node_name, stmt) ->
get_clang_stmt_trans stmt get_clang_stmt_trans node_name stmt trans_state
| `CXXConstructorInit instr -> | CXXConstructorInit instr ->
cxx_constructor_init_trans instr cxx_constructor_init_trans instr trans_state
(** Given a translation state, this function translates a list of clang statements. *) (** Given a translation state, this function translates a list of clang statements. *)
and instructions trans_state stmt_list = and instructions node_name trans_state stmt_list =
let stmt_trans_fun = List.map ~f:get_clang_stmt_trans stmt_list in let stmt_trans_fun = List.map ~f:(get_clang_stmt_trans node_name) stmt_list in
exec_trans_instrs trans_state stmt_trans_fun exec_trans_instrs trans_state stmt_trans_fun
@ -4424,7 +4425,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s
trans_state.succ_nodes trans_state.succ_nodes
in in
let trans_state' = {trans_state with succ_nodes} in let trans_state' = {trans_state with succ_nodes} in
let instrs = extra_instrs @ [`ClangStmt body] in let instrs = extra_instrs @ [CFrontend_config.ClangStmt (Procdesc.Node.DefineBody, body)] in
let instrs_trans = List.map ~f:get_custom_stmt_trans instrs in let instrs_trans = List.map ~f:get_custom_stmt_trans instrs in
let res_control, _ = exec_trans_instrs trans_state' instrs_trans in let res_control, _ = exec_trans_instrs trans_state' instrs_trans in
res_control.root_nodes res_control.root_nodes

@ -32,7 +32,7 @@ digraph cfg {
"dereference_ifthenelse.aa3447116ff03cffc729c06c91821cdc_8" -> "dereference_ifthenelse.aa3447116ff03cffc729c06c91821cdc_9" ; "dereference_ifthenelse.aa3447116ff03cffc729c06c91821cdc_8" -> "dereference_ifthenelse.aa3447116ff03cffc729c06c91821cdc_9" ;
"dereference_ifthenelse.aa3447116ff03cffc729c06c91821cdc_9" [label="9: Fallback node \n n$4=*n$3:int [line 14, column 3]\n " shape="box"] "dereference_ifthenelse.aa3447116ff03cffc729c06c91821cdc_9" [label="9: Compound statement \n n$4=*n$3:int [line 14, column 3]\n " shape="box"]
"dereference_ifthenelse.aa3447116ff03cffc729c06c91821cdc_9" -> "dereference_ifthenelse.aa3447116ff03cffc729c06c91821cdc_2" ; "dereference_ifthenelse.aa3447116ff03cffc729c06c91821cdc_9" -> "dereference_ifthenelse.aa3447116ff03cffc729c06c91821cdc_2" ;

@ -18,7 +18,7 @@ digraph cfg {
"init_variable_array.8cdc6857adcb1fd04fb6555d8ce3e4c1_2" [label="2: Exit init_variable_array \n " color=yellow style=filled] "init_variable_array.8cdc6857adcb1fd04fb6555d8ce3e4c1_2" [label="2: Exit init_variable_array \n " color=yellow style=filled]
"init_variable_array.8cdc6857adcb1fd04fb6555d8ce3e4c1_3" [label="3: Fallback node \n n$0=*&len:int [line 15, column 9]\n n$1=*&x:int [line 15, column 15]\n n$2=_fun___set_array_length(&a:int[_*4],((n$0 + n$1) + 1):int) [line 15, column 9]\n " shape="box"] "init_variable_array.8cdc6857adcb1fd04fb6555d8ce3e4c1_3" [label="3: Compound statement \n n$0=*&len:int [line 15, column 9]\n n$1=*&x:int [line 15, column 15]\n n$2=_fun___set_array_length(&a:int[_*4],((n$0 + n$1) + 1):int) [line 15, column 9]\n " shape="box"]
"init_variable_array.8cdc6857adcb1fd04fb6555d8ce3e4c1_3" -> "init_variable_array.8cdc6857adcb1fd04fb6555d8ce3e4c1_2" ; "init_variable_array.8cdc6857adcb1fd04fb6555d8ce3e4c1_3" -> "init_variable_array.8cdc6857adcb1fd04fb6555d8ce3e4c1_2" ;

@ -11,7 +11,7 @@ digraph cfg {
"main.fad58de7366495db4650cfefac2fcd61_3" -> "main.fad58de7366495db4650cfefac2fcd61_2" ; "main.fad58de7366495db4650cfefac2fcd61_3" -> "main.fad58de7366495db4650cfefac2fcd61_2" ;
"main.fad58de7366495db4650cfefac2fcd61_4" [label="4: Fallback node \n n$0=*&X:int [line 13, column 5]\n " shape="box"] "main.fad58de7366495db4650cfefac2fcd61_4" [label="4: Compound statement \n n$0=*&X:int [line 13, column 5]\n " shape="box"]
"main.fad58de7366495db4650cfefac2fcd61_4" -> "main.fad58de7366495db4650cfefac2fcd61_6" ; "main.fad58de7366495db4650cfefac2fcd61_4" -> "main.fad58de7366495db4650cfefac2fcd61_6" ;

@ -156,7 +156,7 @@ digraph cfg {
"dispatch_a_block_variable_from_macro#DispatchA#class.92567a38d5ab3cf637f72030b1097441_2" [label="2: Exit DispatchA.dispatch_a_block_variable_from_macro \n " color=yellow style=filled] "dispatch_a_block_variable_from_macro#DispatchA#class.92567a38d5ab3cf637f72030b1097441_2" [label="2: Exit DispatchA.dispatch_a_block_variable_from_macro \n " color=yellow style=filled]
"dispatch_a_block_variable_from_macro#DispatchA#class.92567a38d5ab3cf637f72030b1097441_3" [label="3: Fallback node \n n$22=*&#GB<codetoanalyze/objc/shared/block/dispatch.m>$DispatchA.dispatch_a_block_variable_from_macro.static_storage__:DispatchA* [line 70, column 5]\n " shape="box"] "dispatch_a_block_variable_from_macro#DispatchA#class.92567a38d5ab3cf637f72030b1097441_3" [label="3: Compound statement \n n$22=*&#GB<codetoanalyze/objc/shared/block/dispatch.m>$DispatchA.dispatch_a_block_variable_from_macro.static_storage__:DispatchA* [line 70, column 5]\n " shape="box"]
"dispatch_a_block_variable_from_macro#DispatchA#class.92567a38d5ab3cf637f72030b1097441_3" -> "dispatch_a_block_variable_from_macro#DispatchA#class.92567a38d5ab3cf637f72030b1097441_6" ; "dispatch_a_block_variable_from_macro#DispatchA#class.92567a38d5ab3cf637f72030b1097441_3" -> "dispatch_a_block_variable_from_macro#DispatchA#class.92567a38d5ab3cf637f72030b1097441_6" ;

@ -7,7 +7,7 @@ digraph cfg {
"DispatchInMacroTest.f5d56763274a479d06265a2f9562bef1_2" [label="2: Exit DispatchInMacroTest \n " color=yellow style=filled] "DispatchInMacroTest.f5d56763274a479d06265a2f9562bef1_2" [label="2: Exit DispatchInMacroTest \n " color=yellow style=filled]
"DispatchInMacroTest.f5d56763274a479d06265a2f9562bef1_3" [label="3: Fallback node \n n$0=*&#GB<codetoanalyze/objc/shared/block/dispatch_in_macro.m>$DispatchInMacroTest.static_storage:NSObject* [line 21, column 10]\n " shape="box"] "DispatchInMacroTest.f5d56763274a479d06265a2f9562bef1_3" [label="3: Compound statement \n n$0=*&#GB<codetoanalyze/objc/shared/block/dispatch_in_macro.m>$DispatchInMacroTest.static_storage:NSObject* [line 21, column 10]\n " shape="box"]
"DispatchInMacroTest.f5d56763274a479d06265a2f9562bef1_3" -> "DispatchInMacroTest.f5d56763274a479d06265a2f9562bef1_5" ; "DispatchInMacroTest.f5d56763274a479d06265a2f9562bef1_3" -> "DispatchInMacroTest.f5d56763274a479d06265a2f9562bef1_5" ;

Loading…
Cancel
Save