diff --git a/facebook-clang-plugins b/facebook-clang-plugins index a20740984..10eb1ac9b 160000 --- a/facebook-clang-plugins +++ b/facebook-clang-plugins @@ -1 +1 @@ -Subproject commit a207409847b6d09e610776b113cd922621e96ed7 +Subproject commit 10eb1ac9bb9e94ae8332e84058f39699422a0e85 diff --git a/infer/src/IR/BuiltinDecl.ml b/infer/src/IR/BuiltinDecl.ml index 6456a809a..6fc2f8be8 100644 --- a/infer/src/IR/BuiltinDecl.ml +++ b/infer/src/IR/BuiltinDecl.ml @@ -84,10 +84,8 @@ let __objc_alloc_no_fail = create_procname "__objc_alloc_no_fail" let __objc_cast = create_procname "__objc_cast" -(* We don't need to add parameters to this one because it is used to translate dictionary literals -and the actual method doesn't appear in the AST, instead we create the corresponding AST bit in cTrans. *) let __objc_dictionary_literal = - create_objc_class_method "NSDictionary" "dictionaryWithObjects:forKeys:count:" [] + create_objc_class_method "NSDictionary" "dictionaryWithObjects:forKeys:count:" [None; None; None] let __placement_delete = create_procname "__placement_delete" @@ -141,9 +139,9 @@ let nsArray_arrayWithObjects = create_objc_class_method "NSArray" "arrayWithObjects:" [Some objc_object] -(* We don't need to add parameters to this one because it is used to translate array literals - and the actual method doesn't appear in the AST, instead we create the corresponding AST bit in cTrans. *) -let nsArray_arrayWithObjectsCount = create_objc_class_method "NSArray" "arrayWithObjects:count:" [] +let nsArray_arrayWithObjectsCount = + create_objc_class_method "NSArray" "arrayWithObjects:count:" [None; None] + let objc_cpp_throw = create_procname "__infer_objc_cpp_throw" diff --git a/infer/src/clang/cFrontend_config.ml b/infer/src/clang/cFrontend_config.ml index 46e312b84..1012f14c3 100644 --- a/infer/src/clang/cFrontend_config.ml +++ b/infer/src/clang/cFrontend_config.ml @@ -44,8 +44,6 @@ exception Invalid_declaration let alloc = "alloc" -let array_with_objects_count_m = "arrayWithObjects:count:" - let assert_fail = "__assert_fail" let assert_rtn = "__assert_rtn" diff --git a/infer/src/clang/cFrontend_config.mli b/infer/src/clang/cFrontend_config.mli index 6304209e6..d3967022a 100644 --- a/infer/src/clang/cFrontend_config.mli +++ b/infer/src/clang/cFrontend_config.mli @@ -45,8 +45,6 @@ exception Invalid_declaration val alloc : string -val array_with_objects_count_m : string - val assert_fail : string val assert_rtn : string diff --git a/infer/src/clang/cTrans.ml b/infer/src/clang/cTrans.ml index 0beac5901..59c248f80 100644 --- a/infer/src/clang/cTrans.ml +++ b/infer/src/clang/cTrans.ml @@ -2566,34 +2566,40 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s instruction trans_state message_stmt - and objCArrayLiteral_trans trans_state info stmt_info stmts = - let typ = - CType_decl.class_from_pointer_type trans_state.context.CContext.tenv - info.Clang_ast_t.ei_qual_type - in - let meth = CFrontend_config.array_with_objects_count_m in - let obj_c_mes_expr_info = Ast_expressions.make_obj_c_message_expr_info_class meth typ None in + and objCArrayDictLiteral_trans trans_state expr_info stmt_info stmts method_pointer = + let open Clang_ast_t in + match CAst_utils.get_decl_opt method_pointer with + | Some (ObjCMethodDecl (decl_info, named_decl_info, _)) -> + let typ = + CAst_utils.qual_type_of_decl_ptr (Option.value_exn decl_info.di_parent_pointer) + in + let obj_c_mes_expr_info = + { Clang_ast_t.omei_selector= named_decl_info.Clang_ast_t.ni_name + ; omei_receiver_kind= `Class typ + ; omei_is_definition_found= true + ; omei_decl_pointer= method_pointer } + in + let message_stmt = + Clang_ast_t.ObjCMessageExpr (stmt_info, stmts, expr_info, obj_c_mes_expr_info) + in + instruction trans_state message_stmt + | _ -> + Logging.die InternalError + "The method for translating array/dictionary literals is not available at %s" + (Clang_ast_j.string_of_stmt_info stmt_info) + + + and objCArrayLiteral_trans trans_state expr_info stmt_info stmts array_literal_info = + let method_pointer = array_literal_info.Clang_ast_t.oalei_array_method in let stmts = stmts @ [Ast_expressions.create_nil stmt_info] in - let message_stmt = Clang_ast_t.ObjCMessageExpr (stmt_info, stmts, info, obj_c_mes_expr_info) in - instruction trans_state message_stmt + objCArrayDictLiteral_trans trans_state expr_info stmt_info stmts method_pointer - and objCDictionaryLiteral_trans trans_state info stmt_info stmts = - let typ = - CType_decl.class_from_pointer_type trans_state.context.CContext.tenv - info.Clang_ast_t.ei_qual_type - in - let dictionary_literal_pname = BuiltinDecl.__objc_dictionary_literal in - let dictionary_literal_s = Typ.Procname.get_method dictionary_literal_pname in - let obj_c_message_expr_info = - Ast_expressions.make_obj_c_message_expr_info_class dictionary_literal_s typ None - in + and objCDictionaryLiteral_trans trans_state expr_info stmt_info stmts dict_literal_info = + let method_pointer = dict_literal_info.Clang_ast_t.odlei_dict_method in let stmts = CGeneral_utils.swap_elements_list stmts in let stmts = stmts @ [Ast_expressions.create_nil stmt_info] in - let message_stmt = - Clang_ast_t.ObjCMessageExpr (stmt_info, stmts, info, obj_c_message_expr_info) - in - instruction trans_state message_stmt + objCArrayDictLiteral_trans trans_state expr_info stmt_info stmts method_pointer and objCStringLiteral_trans trans_state stmt_info stmts info = @@ -3283,10 +3289,10 @@ module CTrans_funct (F : CModule_type.CFrontend) : CModule_type.CTranslation = s objCBoxedExpr_trans trans_state info sel stmt_info stmts | None -> assert false ) - | ObjCArrayLiteral (stmt_info, stmts, info) -> - objCArrayLiteral_trans trans_state info stmt_info stmts - | ObjCDictionaryLiteral (stmt_info, stmts, info) -> - objCDictionaryLiteral_trans trans_state info stmt_info stmts + | ObjCArrayLiteral (stmt_info, stmts, expr_info, array_literal_info) -> + objCArrayLiteral_trans trans_state expr_info stmt_info stmts array_literal_info + | ObjCDictionaryLiteral (stmt_info, stmts, expr_info, dict_literal_info) -> + objCDictionaryLiteral_trans trans_state expr_info stmt_info stmts dict_literal_info | ObjCStringLiteral (stmt_info, stmts, info) -> objCStringLiteral_trans trans_state stmt_info stmts info | BreakStmt (stmt_info, _) ->