diff --git a/infer/src/clang/cFrontend_config.ml b/infer/src/clang/cFrontend_config.ml index b8f1991e9..f04bcdfb7 100644 --- a/infer/src/clang/cFrontend_config.ml +++ b/infer/src/clang/cFrontend_config.ml @@ -136,16 +136,12 @@ let handleFailureInFunction = "handleFailureInFunction:file:lineNumber:descripti let fbAssertWithSignalAndLogFunctionHelper = "FBAssertWithSignalAndLogFunctionHelper" -let nonnull_attribute = "_Nonnull" - let pseudo_object_type = "" let count = "count" let objects = "objects" -let ns_array_ptr = "NSArray *" - let enumerateObjectsUsingBlock = "enumerateObjectsUsingBlock:" let generated_suffix = "*generated" @@ -155,14 +151,6 @@ 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_main.PointerMap.empty -let weak_attribute = "__weak" - -let strong_attribtue = "__strong" - -let unsafe_unretained_attribute = "__unsafe_unretained" - -let autoreleasing_atribute = "__autoreleasing" - let type_pointer_prefix = "internal_type" let nsarray_cl = "NSArray" diff --git a/infer/src/clang/cFrontend_config.mli b/infer/src/clang/cFrontend_config.mli index 090742417..741ee7a64 100644 --- a/infer/src/clang/cFrontend_config.mli +++ b/infer/src/clang/cFrontend_config.mli @@ -133,16 +133,12 @@ val handleFailureInMethod : string val handleFailureInFunction : string -val nonnull_attribute : string - val pseudo_object_type : string val count : string val objects : string -val ns_array_ptr : string - val enumerateObjectsUsingBlock : string val generated_suffix : string @@ -152,14 +148,6 @@ val pointer_type_index : Clang_ast_t.c_type Clang_ast_main.PointerMap.t ref (* Map from type pointers or declaration pointers to sil types *) val sil_types_map : (Sil.typ Clang_ast_main.PointerMap.t) ref -val weak_attribute : string - -val strong_attribtue : string - -val unsafe_unretained_attribute : string - -val autoreleasing_atribute : string - val type_pointer_prefix : string val nsarray_cl : string diff --git a/infer/src/clang/cFrontend_utils.ml b/infer/src/clang/cFrontend_utils.ml index 9eabc3905..bce272ba9 100644 --- a/infer/src/clang/cFrontend_utils.ml +++ b/infer/src/clang/cFrontend_utils.ml @@ -241,10 +241,6 @@ struct | `Setter setter -> name_opt_of_name_info_opt setter.Clang_ast_t.dr_name | _ -> (setter_attribute_opt rest) - (*TODO: take the attributes into account too. To be done after we get the attribute's arguments. *) - let is_type_nonnull qt attributes = - Utils.string_contains CFrontend_config.nonnull_attribute qt.Clang_ast_t.qt_raw - let pointer_counter = ref 0 let get_fresh_pointer () = @@ -299,6 +295,13 @@ struct | Clang_ast_t.RecordType (ti, decl_ptr) -> get_decl_or_fail decl_ptr | _ -> assert false + (*TODO take the attributes into account too. To be done after we get the attribute's arguments. *) + let is_type_nonnull qt attributes = + let open Clang_ast_t in + match get_type qt.qt_type_ptr with + | Some AttributedType (_, attr_info) -> attr_info.ati_attr_kind = `Nonnull + | _ -> false + end (* Global counter for anonymous block*) diff --git a/infer/src/clang/cType_to_sil_type.ml b/infer/src/clang/cType_to_sil_type.ml index 3bed05943..240f18506 100644 --- a/infer/src/clang/cType_to_sil_type.ml +++ b/infer/src/clang/cType_to_sil_type.ml @@ -66,11 +66,28 @@ let sil_type_of_builtin_type_kind builtin_type_kind = | `ObjCClass -> get_builtin_objc_type `ObjCClass | _ -> Sil.Tvoid +let pointer_attribute_of_objc_attribute attr_info = + match attr_info.Clang_ast_t.ati_lifetime with + | `OCL_None | `OCL_Strong -> Sil.Pk_pointer + | `OCL_ExplicitNone -> Sil.Pk_objc_unsafe_unretained + | `OCL_Weak -> Sil.Pk_objc_weak + | `OCL_Autoreleasing -> Sil.Pk_objc_autoreleasing + let rec build_array_type translate_decl tenv type_ptr n = let array_type = qual_type_ptr_to_sil_type translate_decl tenv type_ptr in let exp = Sil.exp_int (Sil.Int.of_int64 (Int64.of_int n)) in Sil.Tarray (array_type, exp) +and sil_type_of_attr_type translate_decl tenv type_info attr_info = + match type_info.Clang_ast_t.ti_desugared_type with + | Some type_ptr -> + (match Ast_utils.get_type type_ptr with + | Some Clang_ast_t.ObjCObjectPointerType (type_info', type_ptr') -> + let typ = qual_type_ptr_to_sil_type translate_decl tenv type_ptr' in + Sil.Tptr (typ, pointer_attribute_of_objc_attribute attr_info) + | _ -> qual_type_ptr_to_sil_type translate_decl tenv type_ptr) + | None -> Sil.Tvoid + and sil_type_of_c_type translate_decl tenv c_type = let open Clang_ast_t in match c_type with @@ -113,15 +130,8 @@ and sil_type_of_c_type translate_decl tenv c_type = | LValueReferenceType (type_info, type_ptr) -> let typ = qual_type_ptr_to_sil_type translate_decl tenv type_ptr in Sil.Tptr (typ, Sil.Pk_reference) - | AttributedType (type_info, _) -> - (match type_info.Clang_ast_t.ti_desugared_type with - | Some type_ptr -> - (match Ast_utils.get_type type_ptr with - | Some ObjCObjectPointerType (type_info', type_ptr') -> - let typ = qual_type_ptr_to_sil_type translate_decl tenv type_ptr' in - CTypes.sil_type_of_attr_pointer_type typ type_info.Clang_ast_t.ti_raw - | _ -> qual_type_ptr_to_sil_type translate_decl tenv type_ptr) - | None -> Sil.Tvoid) + | AttributedType (type_info, attr_info) -> + sil_type_of_attr_type translate_decl tenv type_info attr_info | _ -> (* TypedefType, etc *) let type_info = Clang_ast_proj.get_type_tuple c_type in match type_info.Clang_ast_t.ti_desugared_type with diff --git a/infer/src/clang/cTypes.ml b/infer/src/clang/cTypes.ml index 1c347ba83..1249cc3f7 100644 --- a/infer/src/clang/cTypes.ml +++ b/infer/src/clang/cTypes.ml @@ -183,19 +183,6 @@ let is_class typ = (Mangled.to_string name) = CFrontend_config.objc_class | _ -> false -let sil_type_of_attr_pointer_type typ raw_type = - let pointer_attribute_of_objc_attribute objc_attribute = - if Utils.string_is_suffix CFrontend_config.weak_attribute objc_attribute - then Sil.Pk_objc_weak - else if Utils.string_is_suffix CFrontend_config.strong_attribtue objc_attribute - then Sil.Pk_pointer - else if Utils.string_is_suffix CFrontend_config.unsafe_unretained_attribute objc_attribute - then Sil.Pk_objc_unsafe_unretained - else if Utils.string_is_suffix CFrontend_config.autoreleasing_atribute objc_attribute - then Sil.Pk_objc_autoreleasing - else Sil.Pk_pointer in - Sil.Tptr (typ, (pointer_attribute_of_objc_attribute raw_type)) - let rec return_type_of_function_type_ptr type_ptr = let open Clang_ast_t in match Ast_utils.get_type type_ptr with diff --git a/infer/src/clang/cTypes.mli b/infer/src/clang/cTypes.mli index 08cd0cc68..d2d8e92fc 100644 --- a/infer/src/clang/cTypes.mli +++ b/infer/src/clang/cTypes.mli @@ -35,8 +35,6 @@ val remove_pointer_to_typ : Sil.typ -> Sil.typ val is_class : Sil.typ -> bool -val sil_type_of_attr_pointer_type : Sil.typ -> string -> Sil.typ - val return_type_of_function_type : Clang_ast_t.qual_type -> Clang_ast_t.pointer val expand_structured_type : Sil.tenv -> Sil.typ -> Sil.typ