From ecd79a56d313a9ba70f82b8e8487c36bd668677f Mon Sep 17 00:00:00 2001 From: Dulma Churchill Date: Thu, 31 Aug 2017 09:46:19 -0700 Subject: [PATCH] [linters] Support transition Parameters also by ObjC method calls Reviewed By: jvillard Differential Revision: D5745582 fbshipit-source-id: 20b37f3 --- infer/src/clang/cTL.ml | 12 +++++++----- .../objcpp/linters-for-test-only/issues.exp | 2 ++ .../objcpp/linters-for-test-only/linters_example.al | 8 ++++++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/infer/src/clang/cTL.ml b/infer/src/clang/cTL.ml index 95b124216..70712dd33 100644 --- a/infer/src/clang/cTL.ml +++ b/infer/src/clang/cTL.ml @@ -697,11 +697,13 @@ let transition_stmt_to_decl_via_pointer stmt = | _ -> [] -let transition_decl_to_decl_via_parameters dec = +let transition_via_parameters an = let open Clang_ast_t in - match dec with - | ObjCMethodDecl (_, _, omdi) + match an with + | Decl ObjCMethodDecl (_, _, omdi) -> List.map ~f:(fun d -> Decl d) omdi.omdi_parameters + | Stmt ObjCMessageExpr (_, stmt_list, _, _) + -> List.map ~f:(fun stmt -> Stmt stmt) stmt_list | _ -> [] @@ -739,8 +741,8 @@ let next_state_via_transition an trans = match (an, trans) with | Decl d, Super -> transition_decl_to_decl_via_super d - | Decl d, Parameters - -> transition_decl_to_decl_via_parameters d + | _, Parameters + -> transition_via_parameters an | Decl d, InitExpr | Decl d, Body -> transition_decl_to_stmt d trans | Decl d, Protocol diff --git a/infer/tests/codetoanalyze/objcpp/linters-for-test-only/issues.exp b/infer/tests/codetoanalyze/objcpp/linters-for-test-only/issues.exp index b96659641..52205f36c 100644 --- a/infer/tests/codetoanalyze/objcpp/linters-for-test-only/issues.exp +++ b/infer/tests/codetoanalyze/objcpp/linters-for-test-only/issues.exp @@ -4,8 +4,10 @@ codetoanalyze/objcpp/linters-for-test-only/ReferenceTest.mm, ReferenceTest_newWi codetoanalyze/objcpp/linters-for-test-only/ReferenceTest.mm, ReferenceTest_newWithActionRef:, 40, TEST_REFERENCE, [] codetoanalyze/objcpp/linters-for-test-only/ReferenceTest.mm, ReferenceTest_newWithConstAction:, 21, TEST_REFERENCE, [] codetoanalyze/objcpp/linters-for-test-only/ReferenceTest.mm, ReferenceTest_newWithConstAction:, 36, TEST_REFERENCE, [] +codetoanalyze/objcpp/linters-for-test-only/TestParamterLabelsChecks.mm, anotherButtonComponent, 36, PARAMETER_TRANS_TYPE, [] codetoanalyze/objcpp/linters-for-test-only/TestParamterLabelsChecks.mm, anotherButtonComponent, 36, TEST_PARAMETER_LABEL, [] codetoanalyze/objcpp/linters-for-test-only/TestParamterLabelsChecks.mm, anotherButtonComponent, 36, TEST_PARAMETER_LABEL_REGEXP, [] +codetoanalyze/objcpp/linters-for-test-only/TestParamterLabelsChecks.mm, buttonComponent, 31, PARAMETER_TRANS_TYPE, [] codetoanalyze/objcpp/linters-for-test-only/TestParamterLabelsChecks.mm, buttonComponent, 31, TEST_PARAMETER_LABEL, [] codetoanalyze/objcpp/linters-for-test-only/TestParamterLabelsChecks.mm, buttonComponent, 31, TEST_PARAMETER_LABEL_EMPTY_MAP, [] codetoanalyze/objcpp/linters-for-test-only/TestParamterLabelsChecks.mm, buttonComponent, 31, TEST_PARAMETER_LABEL_EMPTY_STRUCT, [] diff --git a/infer/tests/codetoanalyze/objcpp/linters-for-test-only/linters_example.al b/infer/tests/codetoanalyze/objcpp/linters-for-test-only/linters_example.al index 216e29d0e..5ebf3c4b9 100644 --- a/infer/tests/codetoanalyze/objcpp/linters-for-test-only/linters_example.al +++ b/infer/tests/codetoanalyze/objcpp/linters-for-test-only/linters_example.al @@ -107,3 +107,11 @@ DEFINE-CHECKER DISCOURAGED_HASH_METHOD_INVOCATION = { SET report_when = call_method("hash"); SET message = "Don't use the hash method"; }; + +DEFINE-CHECKER PARAMETER_TRANS_TYPE = { + SET report_when = + WHEN + HOLDS-NEXT WITH-TRANSITION Parameters (has_type("int")) + HOLDS-IN-NODE ObjCMessageExpr; + SET message = "Found method called with an argument of type int"; +};