From 4c726692a9678672d9c148c1d4cb2c37de062c6e Mon Sep 17 00:00:00 2001 From: Dulma Churchill Date: Thu, 21 Jun 2018 07:25:22 -0700 Subject: [PATCH] [clang] Do not raise an exception when type pointer not found Reviewed By: da319 Differential Revision: D8567239 fbshipit-source-id: 6eed973 --- infer/src/clang/cAst_utils.ml | 14 +++++--------- infer/src/clang/cAst_utils.mli | 6 ++---- infer/src/clang/cPredicates.ml | 6 +----- 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/infer/src/clang/cAst_utils.ml b/infer/src/clang/cAst_utils.ml index 8774d77bc..e3c6cec2a 100644 --- a/infer/src/clang/cAst_utils.ml +++ b/infer/src/clang/cAst_utils.ml @@ -126,25 +126,21 @@ let get_enum_constant_exp enum_constant_pointer = ClangPointers.Map.find_exn !CFrontend_config.enum_map enum_constant_pointer -let get_type ?source_range type_ptr = - let source_range = match source_range with Some sr -> sr | None -> dummy_source_range () in +let get_type type_ptr = match type_ptr with (* There is chance for success only if type_ptr is in fact clang pointer *) | Clang_ast_types.TypePtr.Ptr raw_ptr -> - let typ = Int.Table.find ClangPointers.pointer_type_table raw_ptr in - if Option.is_none typ then - CFrontend_config.incorrect_assumption __POS__ source_range - "type with pointer %d not found@\n" raw_ptr ; - typ + Int.Table.find ClangPointers.pointer_type_table raw_ptr | _ -> + (* TODO(T30739447): investigate why this happens *) (* otherwise, function fails *) let type_str = Clang_ast_extend.type_ptr_to_string type_ptr in L.(debug Capture Medium) "type %s is not clang pointer@\n" type_str ; None -let get_desugared_type ?source_range type_ptr = - let typ_opt = get_type ?source_range type_ptr in +let get_desugared_type type_ptr = + let typ_opt = get_type type_ptr in match typ_opt with | Some typ -> ( diff --git a/infer/src/clang/cAst_utils.mli b/infer/src/clang/cAst_utils.mli index 733a58934..ab3abefed 100644 --- a/infer/src/clang/cAst_utils.mli +++ b/infer/src/clang/cAst_utils.mli @@ -45,12 +45,10 @@ val get_unqualified_name : Clang_ast_t.named_decl_info -> string val get_class_name_from_member : Clang_ast_t.named_decl_info -> QualifiedCppName.t (** returns qualified class name given member name info *) -val get_type : - ?source_range:Clang_ast_t.source_range -> Clang_ast_t.type_ptr -> Clang_ast_t.c_type option +val get_type : Clang_ast_t.type_ptr -> Clang_ast_t.c_type option (** looks up clang pointer to type and returns c_type. It requires type_ptr to be `TPtr. *) -val get_desugared_type : - ?source_range:Clang_ast_t.source_range -> Clang_ast_t.type_ptr -> Clang_ast_t.c_type option +val get_desugared_type : Clang_ast_t.type_ptr -> Clang_ast_t.c_type option (** looks up clang pointer to type and resolves any sugar around it. See get_type for more info and restrictions *) diff --git a/infer/src/clang/cPredicates.ml b/infer/src/clang/cPredicates.ml index 7d93695cb..fdc504255 100644 --- a/infer/src/clang/cPredicates.ml +++ b/infer/src/clang/cPredicates.ml @@ -1074,11 +1074,7 @@ let has_type_const_ptr_to_objc_class node = let open Clang_ast_t in match get_ast_node_type_ptr node with | Some type_ptr -> ( - match - CAst_utils.get_desugared_type - ~source_range:(Ctl_parser_types.ast_node_source_range node) - type_ptr - with + match CAst_utils.get_desugared_type type_ptr with | Some (ObjCObjectPointerType (_, qt)) -> qt.qt_is_const | _ ->