From 0809279b3b6d17c5852877ba1eb0d04284c09c96 Mon Sep 17 00:00:00 2001 From: Dino Distefano Date: Thu, 1 Jun 2017 00:03:17 -0700 Subject: [PATCH] Extending type parser to deal with typedefs Reviewed By: dulmarod Differential Revision: D5155322 fbshipit-source-id: 9af8d8b --- infer/src/clang/ctl_parser_types.ml | 17 +++++++++++------ .../objc/linters-for-test-only/issues.exp | 3 +++ .../linters-for-test-only/linters_example.al | 12 ++++++++++++ .../objc/linters-for-test-only/subclassing.m | 16 ++++++++++++++++ 4 files changed, 42 insertions(+), 6 deletions(-) diff --git a/infer/src/clang/ctl_parser_types.ml b/infer/src/clang/ctl_parser_types.ml index 97bf5b12c..0d7ec3ee0 100644 --- a/infer/src/clang/ctl_parser_types.ml +++ b/infer/src/clang/ctl_parser_types.ml @@ -172,6 +172,14 @@ let rec pointer_type_equal p ap = | _, _ -> display_equality_warning (); false +and typename_equal pointer typename = + match CAst_utils.get_decl pointer with + | Some decl -> + (match Clang_ast_proj.get_named_decl_tuple decl with + | Some (_, name_decl) -> ALVar.compare_str_with_alexp name_decl.ni_name typename + | None -> false) + | _ -> false + (* Temporary, partial equality function. Cover only what's covered by the types_parser. It needs to be replaced by a real @@ -190,12 +198,9 @@ and c_type_equal c_type abs_ctype = | ObjCObjectPointerType _, Pointer _ -> pointer_type_equal c_type abs_ctype | ObjCInterfaceType (_, pointer), TypeName ae -> - (match CAst_utils.get_decl pointer with - | Some decl -> - (match Clang_ast_proj.get_named_decl_tuple decl with - | Some (_, name_decl) -> ALVar.compare_str_with_alexp name_decl.ni_name ae - | None -> false) - | _ -> false) + typename_equal pointer ae + | TypedefType (_, tdi), TypeName ae -> + typename_equal tdi.tti_decl_ptr ae | _, _ -> display_equality_warning (); false diff --git a/infer/tests/codetoanalyze/objc/linters-for-test-only/issues.exp b/infer/tests/codetoanalyze/objc/linters-for-test-only/issues.exp index a5b17167e..98595817d 100644 --- a/infer/tests/codetoanalyze/objc/linters-for-test-only/issues.exp +++ b/infer/tests/codetoanalyze/objc/linters-for-test-only/issues.exp @@ -37,6 +37,9 @@ codetoanalyze/objc/linters-for-test-only/subclassing.m, Linters_dummy_method, 53 codetoanalyze/objc/linters-for-test-only/subclassing.m, Linters_dummy_method, 53, IMPORTED_MACRO_SUBCLASS, [] codetoanalyze/objc/linters-for-test-only/subclassing.m, Linters_dummy_method, 53, LOCAL_MACRO_SUBCLASS, [] codetoanalyze/objc/linters-for-test-only/subclassing.m, Linters_dummy_method, 53, SUBCLASSING_TEST_EXAMPLE, [] +codetoanalyze/objc/linters-for-test-only/subclassing.m, Linters_dummy_method, 111, TEST_TYPEDEF_CHECK, [] +codetoanalyze/objc/linters-for-test-only/subclassing.m, Linters_dummy_method, 119, TEST_TYPEDEF_CHECK, [] +codetoanalyze/objc/linters-for-test-only/subclassing.m, Linters_dummy_method, 123, TEST_TYPEDEF_CHECK, [] codetoanalyze/objc/linters-for-test-only/subclassing.m, TestType_m1, 73, TEST_BUILTIN_TYPE, [] codetoanalyze/objc/linters-for-test-only/subclassing.m, TestType_m10, 82, TEST_BUILTIN_TYPE, [] codetoanalyze/objc/linters-for-test-only/subclassing.m, TestType_m11, 83, TEST_BUILTIN_TYPE, [] diff --git a/infer/tests/codetoanalyze/objc/linters-for-test-only/linters_example.al b/infer/tests/codetoanalyze/objc/linters-for-test-only/linters_example.al index 26b5e7866..fedf5c87e 100644 --- a/infer/tests/codetoanalyze/objc/linters-for-test-only/linters_example.al +++ b/infer/tests/codetoanalyze/objc/linters-for-test-only/linters_example.al @@ -176,6 +176,18 @@ DEFINE-CHECKER TEST_VAR_TYPE_CHECK = { SET message = "Var has type int or long"; }; +DEFINE-CHECKER TEST_TYPEDEF_CHECK = { + + SET report_when = + WHEN + has_type("my_ulong") OR + has_type("my_pS") OR + has_type("my_listNode") + HOLDS-IN-NODE VarDecl; + + SET message = "Var has type...."; +}; + DEFINE-CHECKER TEST_PARAM_TYPE_CHECK = { SET report_when = diff --git a/infer/tests/codetoanalyze/objc/linters-for-test-only/subclassing.m b/infer/tests/codetoanalyze/objc/linters-for-test-only/subclassing.m index eb3f0220b..667c7c3da 100644 --- a/infer/tests/codetoanalyze/objc/linters-for-test-only/subclassing.m +++ b/infer/tests/codetoanalyze/objc/linters-for-test-only/subclassing.m @@ -105,3 +105,19 @@ pname3:(ThisIsAVeryLongName*)p3 pname4:(A*)p4; @end + +typedef unsigned long my_ulong; + +my_ulong l; + +typedef struct { + int a; + int b; + int c; +} S, *my_pS; + +my_pS p; + +typedef struct Node { struct my_listNode* next; } my_listNode; + +my_listNode ln;