From 47221ab2736136a09d4b6b63d7e26dcd896f65cd Mon Sep 17 00:00:00 2001 From: Dulma Churchill Date: Thu, 31 Aug 2017 09:51:15 -0700 Subject: [PATCH] [linters] Add support for Cxx structs when querying types Reviewed By: jvillard Differential Revision: D5745746 fbshipit-source-id: 90b7a36 --- infer/src/clang/ctl_parser_types.ml | 2 ++ .../objcpp/linters-for-test-only/issues.exp | 2 ++ .../linters-for-test-only/linters_example.al | 24 +++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/infer/src/clang/ctl_parser_types.ml b/infer/src/clang/ctl_parser_types.ml index 52f868f5a..f0818d1fe 100644 --- a/infer/src/clang/ctl_parser_types.ml +++ b/infer/src/clang/ctl_parser_types.ml @@ -320,6 +320,8 @@ and c_type_equal c_type abs_ctype = -> objc_object_type_equal c_type abs_ctype | ObjCInterfaceType (_, pointer), TypeName ae -> typename_equal pointer ae + | RecordType (_, pointer), TypeName ae + -> typename_equal pointer ae | TypedefType (_, tdi), TypeName ae -> typename_equal tdi.tti_decl_ptr ae | TypedefType (ti, _), ObjCGenProt _ -> ( 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 52205f36c..cbf1d313c 100644 --- a/infer/tests/codetoanalyze/objcpp/linters-for-test-only/issues.exp +++ b/infer/tests/codetoanalyze/objcpp/linters-for-test-only/issues.exp @@ -13,5 +13,7 @@ codetoanalyze/objcpp/linters-for-test-only/TestParamterLabelsChecks.mm, buttonCo codetoanalyze/objcpp/linters-for-test-only/TestParamterLabelsChecks.mm, buttonComponent, 31, TEST_PARAMETER_LABEL_EMPTY_STRUCT, [] codetoanalyze/objcpp/linters-for-test-only/TestParamterLabelsChecks.mm, buttonComponent, 31, TEST_PARAMETER_LABEL_REGEXP, [] codetoanalyze/objcpp/linters-for-test-only/TestParamterLabelsChecks.mm, foo, 54, TEST_PARAMETER_SELECTOR, [] +codetoanalyze/objcpp/linters-for-test-only/TestParamterLabelsChecks.mm, foo, 54, TEST_PARAMETER_SELECTOR_BY_TYPE, [] codetoanalyze/objcpp/linters-for-test-only/TestParamterLabelsChecks.mm, foo, 56, TEST_PARAMETER_SELECTOR, [] +codetoanalyze/objcpp/linters-for-test-only/TestParamterLabelsChecks.mm, foo, 56, TEST_PARAMETER_SELECTOR_BY_TYPE, [] codetoanalyze/objcpp/linters-for-test-only/hash_test.mm, std::hash_NSObject_*__operator(), 14, DISCOURAGED_HASH_METHOD_INVOCATION, [] 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 5ebf3c4b9..70aa89718 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 @@ -115,3 +115,27 @@ DEFINE-CHECKER PARAMETER_TRANS_TYPE = { HOLDS-IN-NODE ObjCMessageExpr; SET message = "Found method called with an argument of type int"; }; + +DEFINE-CHECKER TEST_PARAMETER_SELECTOR_BY_TYPE = { + + LET initialized_with_selector_expr = + WHEN (is_node("ObjCSelectorExpr") HOLDS-EVERYWHERE-NEXT) HOLDS-IN-NODE CXXConstructExpr; + + LET materialized_with_selector_expr = + WHEN (initialized_with_selector_expr HOLDS-EVENTUALLY) HOLDS-IN-NODE CXXConstructExpr; + + LET method_has_parameter_type = + WHEN + HOLDS-NEXT WITH-TRANSITION Parameters + (has_type("CKComponentAction") AND + (initialized_with_selector_expr OR + materialized_with_selector_expr)) + HOLDS-IN-NODE ObjCMessageExpr; + + SET report_when = + WHEN + method_has_parameter_type + AND call_method(REGEXP("^new.*:$")) + HOLDS-IN-NODE ObjCMessageExpr; + SET message = "Do not construct the Component action with a selector only...`"; +};