From 234d3627b6cb17a20becb9c7d740d88ce53d2c87 Mon Sep 17 00:00:00 2001 From: Dulma Churchill Date: Mon, 25 Sep 2017 07:37:17 -0700 Subject: [PATCH] [clang] Support the new @available expression in ObjC in the unavailable API check Summary: We take it into account to not report bugs inside the available block. This requires a plugin change. update-submodule: facebook-clang-plugins Reviewed By: jvillard Differential Revision: D5891511 fbshipit-source-id: 21a02ad --- facebook-clang-plugins | 2 +- infer/src/clang/cFrontend_checkers_main.ml | 14 ++++++++++++++ infer/tests/codetoanalyze/objc/ioslints/issues.exp | 8 ++++---- .../unavailable_api_in_supported_ios_sdk.m | 9 +++++++++ 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/facebook-clang-plugins b/facebook-clang-plugins index 7c96ec5ec..4af7ff7ad 160000 --- a/facebook-clang-plugins +++ b/facebook-clang-plugins @@ -1 +1 @@ -Subproject commit 7c96ec5ec404096af9c8ad941cb46b3f1fe7477f +Subproject commit 4af7ff7ad4438a79a0dbc1bd9cd902224754a5e3 diff --git a/infer/src/clang/cFrontend_checkers_main.ml b/infer/src/clang/cFrontend_checkers_main.ml index 5564f9108..5b083ce82 100644 --- a/infer/src/clang/cFrontend_checkers_main.ml +++ b/infer/src/clang/cFrontend_checkers_main.ml @@ -141,6 +141,18 @@ let rec get_current_os_version stmt = | _ -> [] +let rec get_ios_available_version stmt = + let open Clang_ast_t in + match stmt with + | ObjCAvailabilityCheckExpr (_, _, _, oacei) + -> oacei.oacei_version + | ImplicitCastExpr (_, [stmt], _, _) + | ParenExpr (_, [stmt], _) + | ExprWithCleanups (_, [stmt], _, _) + -> get_ios_available_version stmt + | _ + -> None + let compute_if_context (context: CLintersContext.context) stmt = let selector = get_responds_to_selector stmt in let receiver_class_method_call = @@ -153,6 +165,8 @@ let compute_if_context (context: CLintersContext.context) stmt = -> [] in let os_version = get_current_os_version stmt in + let ios_available_version_opt = Option.to_list (get_ios_available_version stmt) in + let os_version = List.append ios_available_version_opt os_version in let within_responds_to_selector_block, within_available_class_block, ios_version_guard = match context.if_context with | Some if_context diff --git a/infer/tests/codetoanalyze/objc/ioslints/issues.exp b/infer/tests/codetoanalyze/objc/ioslints/issues.exp index 3f0b5b00a..c51301e8c 100644 --- a/infer/tests/codetoanalyze/objc/ioslints/issues.exp +++ b/infer/tests/codetoanalyze/objc/ioslints/issues.exp @@ -4,8 +4,8 @@ codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_all codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases_with_responds_to_selector_in_else, 71, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, [] codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases_without_instances_responds_to_selector, 95, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, [] codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases_without_responds_to_selector, 64, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, [] -codetoanalyze/objc/ioslints/unavailable_api_in_supported_ios_sdk.m, OpenURLOptionsFromSourceApplication, 68, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, [] -codetoanalyze/objc/ioslints/unavailable_api_in_supported_ios_sdk.m, Unavailable_api_in_supported_ios_sdk_test, 28, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, [] -codetoanalyze/objc/ioslints/unavailable_api_in_supported_ios_sdk.m, Unavailable_api_in_supported_ios_sdk_unsupported_class, 34, UNAVAILABLE_CLASS_IN_SUPPORTED_IOS_SDK, [] -codetoanalyze/objc/ioslints/unavailable_api_in_supported_ios_sdk.m, Unavailable_api_in_supported_ios_sdk_unsupported_class_with_attributes, 53, UNAVAILABLE_CLASS_IN_SUPPORTED_IOS_SDK, [] +codetoanalyze/objc/ioslints/unavailable_api_in_supported_ios_sdk.m, OpenURLOptionsFromSourceApplication, 77, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, [] +codetoanalyze/objc/ioslints/unavailable_api_in_supported_ios_sdk.m, Unavailable_api_in_supported_ios_sdk_test, 29, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, [] +codetoanalyze/objc/ioslints/unavailable_api_in_supported_ios_sdk.m, Unavailable_api_in_supported_ios_sdk_unsupported_class, 43, UNAVAILABLE_CLASS_IN_SUPPORTED_IOS_SDK, [] +codetoanalyze/objc/ioslints/unavailable_api_in_supported_ios_sdk.m, Unavailable_api_in_supported_ios_sdk_unsupported_class_with_attributes, 62, UNAVAILABLE_CLASS_IN_SUPPORTED_IOS_SDK, [] codetoanalyze/objc/ioslints/unavailable_property_ios.m, FNFPlayerLayer_initWithConfigs, 22, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, [] diff --git a/infer/tests/codetoanalyze/objc/ioslints/unavailable_api_in_supported_ios_sdk.m b/infer/tests/codetoanalyze/objc/ioslints/unavailable_api_in_supported_ios_sdk.m index 794b85b41..ccf6ccc0c 100644 --- a/infer/tests/codetoanalyze/objc/ioslints/unavailable_api_in_supported_ios_sdk.m +++ b/infer/tests/codetoanalyze/objc/ioslints/unavailable_api_in_supported_ios_sdk.m @@ -23,11 +23,20 @@ NS_CLASS_AVAILABLE(10_12, 10_0) @implementation Unavailable_api_in_supported_ios_sdk +// bug - (void)test:(int)n and:(NSData*)data { NSDictionary* cacheData = [NSKeyedUnarchiver unarchiveTopLevelObjectWithData:data error:nil]; } +// no bug +- (void)test_no_bug:(int)n and:(NSData*)data { + if (@available(macOS 10.13, iOS 11.0, *)) { + NSDictionary* cacheData = + [NSKeyedUnarchiver unarchiveTopLevelObjectWithData:data error:nil]; + } +} + // bug - (void)unsupported_class { AVPlayerLooper* looper =