From fb7aed07c65a12f8aeb5594df926df2e9a592891 Mon Sep 17 00:00:00 2001 From: Jules Villard Date: Mon, 25 Jul 2016 03:07:34 -0700 Subject: [PATCH] typo and whitespace cleanup in cFrontend_config Summary: Minor stuff: - GCCAst -> GCCAsm - separate constants and mutable global state in cFrontend_config - alphabetical ordering in cFrontend_config Reviewed By: akotulski Differential Revision: D3593858 fbshipit-source-id: 6f4d9c3 --- infer/src/clang/cFrontend_config.ml | 174 ++++++----------- infer/src/clang/cFrontend_config.mli | 176 ++++++------------ infer/src/clang/cTrans.ml | 20 +- .../c/frontend/unusual_stmts/asm.c.dot | 4 +- 4 files changed, 127 insertions(+), 247 deletions(-) diff --git a/infer/src/clang/cFrontend_config.ml b/infer/src/clang/cFrontend_config.ml index bc97939ef..0c6255e91 100644 --- a/infer/src/clang/cFrontend_config.ml +++ b/infer/src/clang/cFrontend_config.ml @@ -9,136 +9,76 @@ open! Utils -(** Module that contains constants and variables used in the frontend *) +(** Module that contains constants and global state used in the frontend *) -let array_with_objects_count_m = "arrayWithObjects:count:" - -let object_at_indexed_subscript_m = "objectAtIndexedSubscript:" - -let string_with_utf8_m = "stringWithUTF8String:" - -let is_kind_of_class = "isKindOfClass:" - -let nsstring_cl = "NSString" - -let nsobject_cl = "NSObject" - -let next_object = "nextObject" - -let nsautorelease_pool_cl = "NSAutoreleasePool" - -let id_cl = "id" - -let self = "self" - -let this = "this" - -let return_param = "__return_param" +(** Constants *) let alloc = "alloc" - -let malloc = "malloc" - -let free = "free" - -let static = "static" - -let json = ref "" - -let pointer_decl_index = ref Clang_ast_main.PointerMap.empty - -let pointer_stmt_index = ref Clang_ast_main.PointerMap.empty - -let ivar_to_property_index = ref Clang_ast_main.PointerMap.empty - -let emtpy_name_category ="EMPTY_NAME_CATEGORY_FOR_" - -let objc_object = "objc_object" - -let objc_class = "objc_class" - -let class_type = "Class" - -let global_translation_unit_decls : Clang_ast_t.decl list ref = ref [] - -let retain = "retain" - -let release = "release" - -let drain = "drain" - +let array_with_objects_count_m = "arrayWithObjects:count:" +let assert_fail = "__assert_fail" +let assert_rtn = "__assert_rtn" +let atomic_att = "<\"Atomic\">" let autorelease = "autorelease" - -let copy = "copy" - -let mutableCopy = "mutableCopy" - -let new_str = "new" - -let init = "init" - -let invalid_pointer = 0 - -let void = "void" - -let class_method = "class" - -let cf_non_null_alloc ="__cf_non_null_alloc" - -let cf_alloc ="__cf_alloc" - -let cf_bridging_release = "CFBridgingRelease" - -let cf_bridging_retain = "CFBridgingRetain" - -let cf_autorelease = "CFAutorelease" - -let ns_make_collectable = "NSMakeCollectable" - +let block = "block" let builtin_expect = "__builtin_expect" - let builtin_memset_chk = "__builtin___memset_chk" - let builtin_object_size = "__builtin_object_size" - -let assert_fail = "__assert_fail" - -let assert_rtn = "__assert_rtn" - -let handleFailureInMethod = "handleFailureInMethod:object:file:lineNumber:description:" - -let handleFailureInFunction = "handleFailureInFunction:file:lineNumber:description:" - +let cf_alloc ="__cf_alloc" +let cf_autorelease = "CFAutorelease" +let cf_bridging_release = "CFBridgingRelease" +let cf_bridging_retain = "CFBridgingRetain" +let cf_non_null_alloc ="__cf_non_null_alloc" +let class_method = "class" +let class_type = "Class" +let copy = "copy" +let count = "count" +let drain = "drain" +let emtpy_name_category ="EMPTY_NAME_CATEGORY_FOR_" +let enumerateObjectsUsingBlock = "enumerateObjectsUsingBlock:" let fbAssertWithSignalAndLogFunctionHelper = "FBAssertWithSignalAndLogFunctionHelper" - +let free = "free" let google_LogMessageFatal = "google::LogMessageFatal_LogMessageFatal" - let google_MakeCheckOpString = "google::MakeCheckOpString" - +let handleFailureInFunction = "handleFailureInFunction:file:lineNumber:description:" +let handleFailureInMethod = "handleFailureInMethod:object:file:lineNumber:description:" +let id_cl = "id" +let infer = "infer" +let infer_skip_fun = "__infer_skip_function" +let infer_skip_gcc_asm_stmt = "__infer_skip_gcc_asm_stmt" +let init = "init" +let invalid_pointer = 0 +let is_kind_of_class = "isKindOfClass:" +let malloc = "malloc" +let mutableCopy = "mutableCopy" +let new_str = "new" +let next_object = "nextObject" +let ns_make_collectable = "NSMakeCollectable" +let nsarray_cl = "NSArray" +let nsautorelease_pool_cl = "NSAutoreleasePool" +let nsobject_cl = "NSObject" +let nsstring_cl = "NSString" +let objc_class = "objc_class" +let objc_object = "objc_object" +let object_at_indexed_subscript_m = "objectAtIndexedSubscript:" +let objects = "objects" let pseudo_object_type = "" +let release = "release" +let retain = "retain" +let return_param = "__return_param" +let self = "self" +let static = "static" +let string_with_utf8_m = "stringWithUTF8String:" +let this = "this" +let void = "void" -let count = "count" - -let objects = "objects" -let enumerateObjectsUsingBlock = "enumerateObjectsUsingBlock:" +(** Global state *) +let enum_map = ref Clang_ast_main.PointerMap.empty +let global_translation_unit_decls : Clang_ast_t.decl list ref = ref [] +let ivar_to_property_index = ref Clang_ast_main.PointerMap.empty +let json = ref "" +let pointer_decl_index = ref Clang_ast_main.PointerMap.empty +let pointer_stmt_index = ref Clang_ast_main.PointerMap.empty let pointer_type_index = ref Clang_ast_main.PointerMap.empty - -(* Map from type pointers or declaration pointers to sil types *) let sil_types_map = ref Clang_ast_types.TypePointerMap.empty - -(* Map from enum constants pointers to their predecesor and their sil value *) -let enum_map = ref Clang_ast_main.PointerMap.empty - -let nsarray_cl = "NSArray" - -let infer = "infer" - -let block = "block" - -let atomic_att = "<\"Atomic\">" - -let infer_skip_gcc_ast_stmt = "__infer_skip_gcc_ast_stmt" - -let infer_skip_fun = "__infer_skip_function" diff --git a/infer/src/clang/cFrontend_config.mli b/infer/src/clang/cFrontend_config.mli index 3faf53cb9..fd26b888c 100644 --- a/infer/src/clang/cFrontend_config.mli +++ b/infer/src/clang/cFrontend_config.mli @@ -9,141 +9,83 @@ open! Utils -(** Module that contains constants and variables used in the frontend *) +(** Module that contains constants and global state used in the frontend *) -val global_translation_unit_decls : Clang_ast_t.decl list ref - -(** constants *) - -val json : string ref - -val pointer_decl_index : Clang_ast_t.decl Clang_ast_main.PointerMap.t ref - -val pointer_stmt_index : Clang_ast_t.stmt Clang_ast_main.PointerMap.t ref - -val ivar_to_property_index : Clang_ast_t.decl Clang_ast_main.PointerMap.t ref - -val objc_object : string - -val id_cl : string - -val self : string - -val this : string - -val return_param : string - -val nsstring_cl : string - -val nsobject_cl : string - -val next_object : string - -val nsautorelease_pool_cl : string - -val string_with_utf8_m : string - -val is_kind_of_class : string +(** Constants *) val alloc : string - -val malloc : string - -val free : string - -val static : string - val array_with_objects_count_m : string - -val object_at_indexed_subscript_m : string - -val emtpy_name_category : string - -val objc_class : string - -val class_type : string - -val retain : string - -val release : string - -val drain : string - +val assert_fail : string +val assert_rtn : string +val atomic_att : string val autorelease : string - -val copy : string - -val mutableCopy : string - -val new_str : string - -val init : string - -val invalid_pointer : int - -val void : string - -val class_method : string - -val cf_non_null_alloc : string - -val cf_alloc : string - -val cf_bridging_release : string - -val cf_bridging_retain : string - -val cf_autorelease : string - -val ns_make_collectable : string - +val block : string val builtin_expect : string - val builtin_memset_chk : string - val builtin_object_size : string - +val cf_alloc : string +val cf_autorelease : string +val cf_bridging_release : string +val cf_bridging_retain : string +val cf_non_null_alloc : string +val class_method : string +val class_type : string +val copy : string +val count : string +val drain : string +val emtpy_name_category : string +val enumerateObjectsUsingBlock : string val fbAssertWithSignalAndLogFunctionHelper : string - -val assert_fail : string - -val assert_rtn : string - -val handleFailureInMethod : string - -val handleFailureInFunction : string - +val free : string val google_LogMessageFatal : string - val google_MakeCheckOpString : string - +val handleFailureInFunction : string +val handleFailureInMethod : string +val id_cl : string +val infer : string +val infer_skip_fun : string +val infer_skip_gcc_asm_stmt : string +val init : string +val invalid_pointer : int +val is_kind_of_class : string +val malloc : string +val mutableCopy : string +val new_str : string +val next_object : string +val ns_make_collectable : string +val nsarray_cl : string +val nsautorelease_pool_cl : string +val nsobject_cl : string +val nsstring_cl : string +val objc_class : string +val objc_object : string +val object_at_indexed_subscript_m : string +val objects : string val pseudo_object_type : string +val release : string +val retain : string +val return_param : string +val self : string +val static : string +val string_with_utf8_m : string +val this : string +val void : string -val count : string -val objects : string -val enumerateObjectsUsingBlock : string +(** Global state *) -(** Map from clang pointers to types produced by ast exporter. - Populated once on InferClang startup *) +(** Map from enum constants pointers to their predecesor and their sil value *) +val enum_map : (Clang_ast_t.pointer option * Sil.exp option) Clang_ast_main.PointerMap.t ref +val global_translation_unit_decls : Clang_ast_t.decl list ref +val ivar_to_property_index : Clang_ast_t.decl Clang_ast_main.PointerMap.t ref +val json : string ref +val pointer_decl_index : Clang_ast_t.decl Clang_ast_main.PointerMap.t ref +val pointer_stmt_index : Clang_ast_t.stmt Clang_ast_main.PointerMap.t ref +(** Map from clang pointers to types produced by ast exporter. Populated once on InferClang + startup *) val pointer_type_index : Clang_ast_t.c_type Clang_ast_main.PointerMap.t ref - (** Map from type pointers (clang pointers and types created later by frontend) to sil types Populated during frontend execution when new type is found *) val sil_types_map : (Typ.t Clang_ast_types.TypePointerMap.t) ref -(** Map from enum constants pointers to their predecesor and their sil value *) -val enum_map : (Clang_ast_t.pointer option * Sil.exp option) Clang_ast_main.PointerMap.t ref - -val nsarray_cl : string - -val infer : string - -val block : string - -val atomic_att : string - -val infer_skip_gcc_ast_stmt : string - -val infer_skip_fun : string diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index e26fbdfb7..844fb0482 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -202,13 +202,11 @@ struct f { trans_state with priority = Free } e) else f trans_state e - (* This is the standard way of dealing with self:Class or a call [a class]. - We translate it as sizeof() *) - (* The only time when we want to translate those expressions differently - is when they are the first argument of *) - (* method calls. In that case they are not translated as expressions, - but we take the type and create a static *) - (* method call from it. This is done in objcMessageExpr_trans. *) + (* This is the standard way of dealing with self:Class or a call [a class]. We translate it as + sizeof() The only time when we want to translate those expressions differently is + when they are the first argument of method calls. In that case they are not translated as + expressions, but we take the type and create a static method call from it. This is done in + objcMessageExpr_trans. *) let exec_with_self_exception f trans_state stmt = try f trans_state stmt @@ -2199,14 +2197,14 @@ struct | Some exp -> instruction trans_state exp | None -> assert false - and gccAstStmt_trans trans_state stmt_info stmts = + and gccAsmStmt_trans trans_state stmt_info stmts = let sil_loc = CLocation.get_sil_location stmt_info trans_state.context in let trans_state_pri = PriorityNode.try_claim_priority_node trans_state stmt_info in let trans_state_param = { trans_state_pri with succ_nodes = [] } in let res_trans_subexpr_list = IList.map (exec_with_glvalue_as_reference instruction trans_state_param) stmts in let params = collect_exprs res_trans_subexpr_list in - let fun_name = Procname.from_string_c_fun CFrontend_config.infer_skip_gcc_ast_stmt in + let fun_name = Procname.from_string_c_fun CFrontend_config.infer_skip_gcc_asm_stmt in let sil_fun = Sil.Const (Const.Cfun fun_name) in let call_instr = Sil.Call ([], sil_fun, params, sil_loc, CallFlags.default) in let res_trans_call = { empty_res_trans with @@ -2214,7 +2212,7 @@ struct exps = []; } in let all_res_trans = res_trans_subexpr_list @ [res_trans_call] in let res_trans_to_parent = PriorityNode.compute_results_to_parent trans_state_pri sil_loc - "GCCAstStmt" stmt_info all_res_trans in + "GCCAsmStmt" stmt_info all_res_trans in { res_trans_to_parent with exps = res_trans_call.exps } and cxxPseudoDestructorExpr_trans () = @@ -2570,7 +2568,7 @@ struct { empty_res_trans with exps = [(Sil.exp_get_undefined false, Typ.Tvoid)] } | GCCAsmStmt (stmt_info, stmts) -> - gccAstStmt_trans trans_state stmt_info stmts + gccAsmStmt_trans trans_state stmt_info stmts | CXXPseudoDestructorExpr _ -> cxxPseudoDestructorExpr_trans () diff --git a/infer/tests/codetoanalyze/c/frontend/unusual_stmts/asm.c.dot b/infer/tests/codetoanalyze/c/frontend/unusual_stmts/asm.c.dot index 23ada23fd..fd9fea03a 100644 --- a/infer/tests/codetoanalyze/c/frontend/unusual_stmts/asm.c.dot +++ b/infer/tests/codetoanalyze/c/frontend/unusual_stmts/asm.c.dot @@ -4,7 +4,7 @@ digraph iCFG { 9 -> 8 ; -8 [label="8: GCCAstStmt \n n$0=*&src:int [line 27]\n _fun___infer_skip_gcc_ast_stmt(&dst:int &,n$0:int ) [line 23]\n " shape="box"] +8 [label="8: GCCAsmStmt \n n$0=*&src:int [line 27]\n _fun___infer_skip_gcc_asm_stmt(&dst:int &,n$0:int ) [line 23]\n " shape="box"] 8 -> 7 ; @@ -19,7 +19,7 @@ digraph iCFG { 5 -> 9 ; -4 [label="4: GCCAstStmt \n _fun___infer_skip_gcc_ast_stmt(&x:int &,&y:int &,&z:int &,&h:int &,0:int ) [line 15]\n " shape="box"] +4 [label="4: GCCAsmStmt \n _fun___infer_skip_gcc_asm_stmt(&x:int &,&y:int &,&z:int &,&h:int &,0:int ) [line 15]\n " shape="box"] 4 -> 3 ;