From d00d8b35978d3754c14598c178b4bf648a76acac Mon Sep 17 00:00:00 2001 From: Dulma Churchill Date: Wed, 4 Dec 2019 04:12:44 -0800 Subject: [PATCH] [AL] Allow to match typedefs and pointers. Differential Revision: D18779850 fbshipit-source-id: 9a0b09446 --- infer/src/al/ctl_parser_types.ml | 3 ++- .../linters-for-test-only/CFStringExample.m | 5 +++- .../al_definitions/linters_example.al | 24 +++++++++---------- .../objc/linters-for-test-only/issues.exp | 12 +++++----- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/infer/src/al/ctl_parser_types.ml b/infer/src/al/ctl_parser_types.ml index d913a9828..853591659 100644 --- a/infer/src/al/ctl_parser_types.ml +++ b/infer/src/al/ctl_parser_types.ml @@ -558,7 +558,8 @@ and c_type_equal c_type abs_ctype = | ElaboratedType ti, TypeName _ | AutoType ti, TypeName _ | TypedefType (ti, _), ObjCGenProt _ - | AttributedType (ti, _), Pointer _ -> ( + | AttributedType (ti, _), Pointer _ + | TypedefType (ti, _), Pointer _ -> ( match ti.ti_desugared_type with Some dt -> check_type_ptr dt abs_ctype | None -> false ) | AttributedType (ti, _), TypeName _ -> ( match ti.ti_desugared_type with Some dt -> check_type_ptr dt abs_ctype | None -> false ) diff --git a/infer/tests/codetoanalyze/objc/linters-for-test-only/CFStringExample.m b/infer/tests/codetoanalyze/objc/linters-for-test-only/CFStringExample.m index e07afb3a7..808f97121 100644 --- a/infer/tests/codetoanalyze/objc/linters-for-test-only/CFStringExample.m +++ b/infer/tests/codetoanalyze/objc/linters-for-test-only/CFStringExample.m @@ -9,6 +9,9 @@ static CFStringRef CreateFoo() { return CFStringCreateWithCString(NULL, "Hello", kCFStringEncodingUTF8); } +static _Nullable CFStringRef CreateNullableFoo() { + return CFStringCreateWithCString(NULL, "Hello", kCFStringEncodingUTF8); +} static void doSomething(CFStringRef s) { CFShow(s); } @@ -18,7 +21,7 @@ static void Foo() {} int main() { doSomething(CreateFoo()); - doSomethingElse(0, CreateFoo()); + doSomethingElse(0, CreateNullableFoo()); Foo(); return 0; } diff --git a/infer/tests/codetoanalyze/objc/linters-for-test-only/al_definitions/linters_example.al b/infer/tests/codetoanalyze/objc/linters-for-test-only/al_definitions/linters_example.al index d8bb58384..34bae466b 100644 --- a/infer/tests/codetoanalyze/objc/linters-for-test-only/al_definitions/linters_example.al +++ b/infer/tests/codetoanalyze/objc/linters-for-test-only/al_definitions/linters_example.al @@ -890,8 +890,8 @@ DEFINE-CHECKER IVAR_CAPTURED_IN_OBJC_BLOCK = { }; DEFINE-CHECKER CALLS_TO_FUNCTIONS_WITH_CREATE_FUNCTION_PARAMETERS = { -LET is_create_method_parameter = HOLDS-NEXT WITH-TRANSITION Parameters - (call_function(REGEXP(".*Create.*")) AND has_type("REGEXP('C.*Ref')")); +LET is_create_method_parameter = HOLDS-NEXT WITH-TRANSITION Parameters + (call_function(REGEXP(".*Create.*")) AND has_type("REGEXP('__C.+')*")); SET report_when = WHEN is_create_method_parameter @@ -915,7 +915,7 @@ DEFINE-CHECKER CLASS_AND_VAR = { DEFINE-CHECKER CAT_DECL_MACRO = { - LET is_linkable_var = + LET is_linkable_var = is_extern_var() AND declaration_has_name(REGEXP("Linkable_.*")) AND has_type("char"); @@ -924,12 +924,12 @@ DEFINE-CHECKER CAT_DECL_MACRO = { HOLDS-NEXT WITH-TRANSITION Sibling (is_node("VarDecl") AND is_linkable_var()); - SET report_when = - WHEN + SET report_when = + WHEN NOT ( - is_node("ObjCCategoryDecl") + is_node("ObjCCategoryDecl") AND-WITH-WITNESSES var_decls() : decl_name_is_contained_in_name_of_decl() - ) + ) HOLDS-IN-NODE ObjCCategoryDecl; SET message = "A category is defined without the corresponding macro"; @@ -937,7 +937,7 @@ DEFINE-CHECKER CAT_DECL_MACRO = { DEFINE-CHECKER CAT_IMPL_MACRO = { - LET is_linkable_var = + LET is_linkable_var = has_visibility_attribute("Default") AND declaration_has_name(REGEXP("Linkable_.*")) AND has_type("char"); @@ -946,12 +946,12 @@ DEFINE-CHECKER CAT_IMPL_MACRO = { HOLDS-NEXT WITH-TRANSITION Sibling (is_node("VarDecl") AND is_linkable_var()); - SET report_when = - WHEN + SET report_when = + WHEN NOT ( - is_node("ObjCCategoryImplDecl") + is_node("ObjCCategoryImplDecl") AND-WITH-WITNESSES var_decls() : decl_name_is_contained_in_name_of_decl() ) HOLDS-IN-NODE ObjCCategoryImplDecl; SET message = "A category is implemented without the corresponding macro"; -}; \ No newline at end of file +}; 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 207403be2..6ee148c62 100644 --- a/infer/tests/codetoanalyze/objc/linters-for-test-only/issues.exp +++ b/infer/tests/codetoanalyze/objc/linters-for-test-only/issues.exp @@ -1,9 +1,9 @@ -codetoanalyze/objc/linters-for-test-only/CFStringExample.m, main, 19, ALL_PATH_NO_FILTER_EXAMPLE, no_bucket, WARNING, [] -codetoanalyze/objc/linters-for-test-only/CFStringExample.m, main, 19, BLACKLIST_PATH_EXAMPLE, no_bucket, WARNING, [] -codetoanalyze/objc/linters-for-test-only/CFStringExample.m, main, 19, FILTER_BY_ALL_PATH_EXAMPLE, no_bucket, WARNING, [] -codetoanalyze/objc/linters-for-test-only/CFStringExample.m, main, 19, WHITE_BLACKLIST_PATH_EXAMPLE, no_bucket, WARNING, [] -codetoanalyze/objc/linters-for-test-only/CFStringExample.m, main, 20, CALLS_TO_FUNCTIONS_WITH_CREATE_FUNCTION_PARAMETERS, no_bucket, WARNING, [] -codetoanalyze/objc/linters-for-test-only/CFStringExample.m, main, 21, CALLS_TO_FUNCTIONS_WITH_CREATE_FUNCTION_PARAMETERS, no_bucket, WARNING, [] +codetoanalyze/objc/linters-for-test-only/CFStringExample.m, main, 22, ALL_PATH_NO_FILTER_EXAMPLE, no_bucket, WARNING, [] +codetoanalyze/objc/linters-for-test-only/CFStringExample.m, main, 22, BLACKLIST_PATH_EXAMPLE, no_bucket, WARNING, [] +codetoanalyze/objc/linters-for-test-only/CFStringExample.m, main, 22, FILTER_BY_ALL_PATH_EXAMPLE, no_bucket, WARNING, [] +codetoanalyze/objc/linters-for-test-only/CFStringExample.m, main, 22, WHITE_BLACKLIST_PATH_EXAMPLE, no_bucket, WARNING, [] +codetoanalyze/objc/linters-for-test-only/CFStringExample.m, main, 23, CALLS_TO_FUNCTIONS_WITH_CREATE_FUNCTION_PARAMETERS, no_bucket, WARNING, [] +codetoanalyze/objc/linters-for-test-only/CFStringExample.m, main, 24, CALLS_TO_FUNCTIONS_WITH_CREATE_FUNCTION_PARAMETERS, no_bucket, WARNING, [] codetoanalyze/objc/linters-for-test-only/CallingAMethodWithSelf.m, CallingAMethodWithSelf::methodThatShallBeOkaySuper, 35, TEST_IS_RECEIVER_SUPER, no_bucket, WARNING, [] codetoanalyze/objc/linters-for-test-only/CallingAMethodWithSelf.m, CallingAMethodWithSelf::methodThatShallComplain, 38, TEST_IS_METHOD_EXPOSED, no_bucket, WARNING, [] codetoanalyze/objc/linters-for-test-only/CallingAMethodWithSelf.m, CallingAMethodWithSelf::methodThatShallComplain, 39, TEST_IF_VIEW_METHOD_IS_NOT_CALLED_WITH_SUPER, no_bucket, WARNING, []