diff --git a/infer/src/IR/Procdesc.ml b/infer/src/IR/Procdesc.ml index 5464dbfe9..aa7bb792f 100644 --- a/infer/src/IR/Procdesc.ml +++ b/infer/src/IR/Procdesc.ml @@ -62,7 +62,9 @@ module Node = struct | BinaryOperatorStmt of string | Call of string | CallObjCNew + | CaseStmt | ClassCastException + | CompoundStmt | ConditionalStmtBranch | ConstructorInit | CXXDynamicCast @@ -75,7 +77,6 @@ module Node = struct | ExceptionHandler | ExceptionsSink | ExprWithCleanups - | FallbackNode | FinallyBranch | GCCAsmStmt | GenericSelectionExpr @@ -87,6 +88,7 @@ module Node = struct | MonitorEnter | MonitorExit | ObjCCPPThrow + | ObjCIndirectCopyRestoreExpr | OutOfBound | ReturnStmt | Scope of string @@ -288,8 +290,12 @@ module Node = struct F.fprintf fmt "Call %s" call | CallObjCNew -> F.pp_print_string fmt "Call objC new" + | CaseStmt -> + F.pp_print_string fmt "CaseStmt" | ClassCastException -> F.pp_print_string fmt "Class cast exception" + | CompoundStmt -> + F.pp_print_string fmt "Compound statement" | ConditionalStmtBranch -> F.pp_print_string fmt "ConditionalStmt Branch" | ConstructorInit -> @@ -314,8 +320,6 @@ module Node = struct F.pp_print_string fmt "exceptions sink" | ExprWithCleanups -> F.pp_print_string fmt "ExprWithCleanups" - | FallbackNode -> - F.pp_print_string fmt "Fallback node" | FinallyBranch -> F.pp_print_string fmt "Finally branch" | GCCAsmStmt -> @@ -338,6 +342,8 @@ module Node = struct F.pp_print_string fmt "MonitorExit" | ObjCCPPThrow -> F.pp_print_string fmt "ObjCCPPThrow" + | ObjCIndirectCopyRestoreExpr -> + F.pp_print_string fmt "ObjCIndirectCopyRestoreExpr" | OutOfBound -> F.pp_print_string fmt "Out of bound" | ReturnStmt -> diff --git a/infer/src/IR/Procdesc.mli b/infer/src/IR/Procdesc.mli index eae14467d..9ac4c66df 100644 --- a/infer/src/IR/Procdesc.mli +++ b/infer/src/IR/Procdesc.mli @@ -43,7 +43,9 @@ module Node : sig | BinaryOperatorStmt of string | Call of string | CallObjCNew + | CaseStmt | ClassCastException + | CompoundStmt | ConditionalStmtBranch | ConstructorInit | CXXDynamicCast @@ -56,7 +58,6 @@ module Node : sig | ExceptionHandler | ExceptionsSink | ExprWithCleanups - | FallbackNode | FinallyBranch | GCCAsmStmt | GenericSelectionExpr @@ -68,6 +69,7 @@ module Node : sig | MonitorEnter | MonitorExit | ObjCCPPThrow + | ObjCIndirectCopyRestoreExpr | OutOfBound | ReturnStmt | Scope of string diff --git a/infer/src/clang/CMethodProperties.ml b/infer/src/clang/CMethodProperties.ml index e6222cd75..6a793c63a 100644 --- a/infer/src/clang/CMethodProperties.ml +++ b/infer/src/clang/CMethodProperties.ml @@ -124,7 +124,9 @@ let get_init_list_instrs method_decl = | CXXConstructorDecl (_, _, _, _, mdi) | CXXConversionDecl (_, _, _, _, 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 | _ -> [] diff --git a/infer/src/clang/CMethodProperties.mli b/infer/src/clang/CMethodProperties.mli index cac774f27..a0b8b047e 100644 --- a/infer/src/clang/CMethodProperties.mli +++ b/infer/src/clang/CMethodProperties.mli @@ -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 get_init_list_instrs : - Clang_ast_t.decl -> [> `CXXConstructorInit of Clang_ast_t.cxx_ctor_initializer] list +val get_init_list_instrs : Clang_ast_t.decl -> CFrontend_config.instr_type list val get_pointer_to_property : Clang_ast_t.decl -> Clang_ast_t.pointer option diff --git a/infer/src/clang/CType_decl.mli b/infer/src/clang/CType_decl.mli index 90d548448..380c16081 100644 --- a/infer/src/clang/CType_decl.mli +++ b/infer/src/clang/CType_decl.mli @@ -63,9 +63,7 @@ val method_signature_body_of_decl : -> ?block_return_type:Clang_ast_t.qual_type -> ?passed_as_noescape_block_to:Procname.t option -> Procname.t - -> CMethodSignature.t - * Clang_ast_t.stmt option - * [> `CXXConstructorInit of Clang_ast_t.cxx_ctor_initializer] list + -> CMethodSignature.t * Clang_ast_t.stmt option * CFrontend_config.instr_type list val should_add_return_param : Typ.t -> is_objc_method:bool -> bool diff --git a/infer/src/clang/cFrontend_config.ml b/infer/src/clang/cFrontend_config.ml index 8b5823d8d..591aa5f38 100644 --- a/infer/src/clang/cFrontend_config.ml +++ b/infer/src/clang/cFrontend_config.ml @@ -21,6 +21,10 @@ type translation_unit_context = 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 *) let alloc = "alloc" diff --git a/infer/src/clang/cFrontend_config.mli b/infer/src/clang/cFrontend_config.mli index b6b95e021..7d8c41c31 100644 --- a/infer/src/clang/cFrontend_config.mli +++ b/infer/src/clang/cFrontend_config.mli @@ -21,6 +21,10 @@ type translation_unit_context = 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 *) val alloc : string diff --git a/infer/src/clang/cModule_type.ml b/infer/src/clang/cModule_type.ml index 39e974264..02f17f95d 100644 --- a/infer/src/clang/cModule_type.ml +++ b/infer/src/clang/cModule_type.ml @@ -14,16 +14,13 @@ type block_data = ; procname: Procname.t ; 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 (** Translates instructions: (statements and expressions) from the ast into sil *) val instructions_trans : CContext.t -> Clang_ast_t.stmt - -> instr_type list + -> CFrontend_config.instr_type list -> Procdesc.Node.t -> is_destructor_wrapper:bool -> Procdesc.Node.t list diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index e6ddbeb00..42cadd3fd 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -100,7 +100,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s 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 if not (List.is_empty res_trans.control.instrs) then 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 stmt_info' in - PriorityNode.compute_result_to_parent trans_state_pri sil_loc ~node_name:FallbackNode - stmt_info' res_trans + PriorityNode.compute_result_to_parent trans_state_pri sil_loc ~node_name stmt_info' 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 = - 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 @@ -1939,7 +1938,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s assert false in 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 body_trans_result.control ; SwitchCase.add @@ -2400,7 +2399,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s field_exps (List.length stmts) (Pp.seq ~sep:"," (Pp.of_string ~f:Clang_ast_proj.get_stmt_kind_string)) 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] ) @@ -3438,7 +3437,7 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s in let trans_state_placement = {trans_state with succ_nodes= []; var_exp_typ= None} in 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 let res_trans_new = 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_trans trans_state 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 | BlockExpr (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 ) - and get_clang_stmt_trans stmt trans_state = - exec_with_node_creation ~f:instruction trans_state stmt + and get_clang_stmt_trans node_name stmt trans_state = + exec_with_node_creation ~f:instruction node_name trans_state stmt - and get_custom_stmt_trans stmt = - match stmt with - | `ClangStmt stmt -> - get_clang_stmt_trans stmt - | `CXXConstructorInit instr -> - cxx_constructor_init_trans instr + and get_custom_stmt_trans stmt trans_state = + match (stmt : CFrontend_config.instr_type) with + | ClangStmt (node_name, stmt) -> + get_clang_stmt_trans node_name stmt trans_state + | CXXConstructorInit instr -> + cxx_constructor_init_trans instr trans_state (** Given a translation state, this function translates a list of clang statements. *) - and instructions trans_state stmt_list = - let stmt_trans_fun = List.map ~f:get_clang_stmt_trans stmt_list in + and instructions node_name trans_state stmt_list = + let stmt_trans_fun = List.map ~f:(get_clang_stmt_trans node_name) stmt_list in 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 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 res_control, _ = exec_trans_instrs trans_state' instrs_trans in res_control.root_nodes diff --git a/infer/tests/codetoanalyze/c/frontend/conditional_operator/unary_operator.c.dot b/infer/tests/codetoanalyze/c/frontend/conditional_operator/unary_operator.c.dot index 1d01237f2..4b17fa5bb 100644 --- a/infer/tests/codetoanalyze/c/frontend/conditional_operator/unary_operator.c.dot +++ b/infer/tests/codetoanalyze/c/frontend/conditional_operator/unary_operator.c.dot @@ -32,7 +32,7 @@ digraph cfg { "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" ; diff --git a/infer/tests/codetoanalyze/c/frontend/initialization/array_initlistexpr.c.dot b/infer/tests/codetoanalyze/c/frontend/initialization/array_initlistexpr.c.dot index ea3769dcc..87b88b5e4 100644 --- a/infer/tests/codetoanalyze/c/frontend/initialization/array_initlistexpr.c.dot +++ b/infer/tests/codetoanalyze/c/frontend/initialization/array_initlistexpr.c.dot @@ -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_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" ; diff --git a/infer/tests/codetoanalyze/c/frontend/nestedoperators/gnuexpr.c.dot b/infer/tests/codetoanalyze/c/frontend/nestedoperators/gnuexpr.c.dot index 8bcad0f7d..ee316f670 100644 --- a/infer/tests/codetoanalyze/c/frontend/nestedoperators/gnuexpr.c.dot +++ b/infer/tests/codetoanalyze/c/frontend/nestedoperators/gnuexpr.c.dot @@ -11,7 +11,7 @@ digraph cfg { "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" ; diff --git a/infer/tests/codetoanalyze/objc/shared/block/dispatch.m.dot b/infer/tests/codetoanalyze/objc/shared/block/dispatch.m.dot index 77023c196..1c6daecfb 100644 --- a/infer/tests/codetoanalyze/objc/shared/block/dispatch.m.dot +++ b/infer/tests/codetoanalyze/objc/shared/block/dispatch.m.dot @@ -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_3" [label="3: Fallback node \n n$22=*&#GB$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$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" ; diff --git a/infer/tests/codetoanalyze/objc/shared/block/dispatch_in_macro.m.dot b/infer/tests/codetoanalyze/objc/shared/block/dispatch_in_macro.m.dot index 00ba26638..4348ff01d 100644 --- a/infer/tests/codetoanalyze/objc/shared/block/dispatch_in_macro.m.dot +++ b/infer/tests/codetoanalyze/objc/shared/block/dispatch_in_macro.m.dot @@ -7,7 +7,7 @@ digraph cfg { "DispatchInMacroTest.f5d56763274a479d06265a2f9562bef1_2" [label="2: Exit DispatchInMacroTest \n " color=yellow style=filled] -"DispatchInMacroTest.f5d56763274a479d06265a2f9562bef1_3" [label="3: Fallback node \n n$0=*&#GB$DispatchInMacroTest.static_storage:NSObject* [line 21, column 10]\n " shape="box"] +"DispatchInMacroTest.f5d56763274a479d06265a2f9562bef1_3" [label="3: Compound statement \n n$0=*&#GB$DispatchInMacroTest.static_storage:NSObject* [line 21, column 10]\n " shape="box"] "DispatchInMacroTest.f5d56763274a479d06265a2f9562bef1_3" -> "DispatchInMacroTest.f5d56763274a479d06265a2f9562bef1_5" ;