From 6cfbd383553761fb025aa2d26e476d7a660e8ca3 Mon Sep 17 00:00:00 2001 From: Dulma Churchill Date: Tue, 8 Oct 2019 07:39:58 -0700 Subject: [PATCH] [AL] Take API_AVAILABLE into account in the Unavailable_Api check Reviewed By: ngorogiannis Differential Revision: D17788412 fbshipit-source-id: ef6fd2e1b --- infer/src/al/cPredicates.ml | 26 +++++++++++-------- .../codetoanalyze/objc/ioslints/issues.exp | 10 +++---- .../ioslints/unavailable_api_allowed_cases.m | 8 ++++++ 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/infer/src/al/cPredicates.ml b/infer/src/al/cPredicates.ml index f4782c24b..fa9dffa88 100644 --- a/infer/src/al/cPredicates.ml +++ b/infer/src/al/cPredicates.ml @@ -1145,20 +1145,24 @@ let iphoneos_target_sdk_version_greater_or_equal (cxt : CLintersContext.context) let decl_unavailable_in_supported_ios_sdk (cxt : CLintersContext.context) an = let config_iphoneos_target_sdk_version = iphoneos_target_sdk_version_by_path cxt in + let available_attr_ios_sdk_current_method = + match cxt.current_method with + | Some decl -> + get_available_attr_ios_sdk (Decl decl) + | None -> + None + in + let ios_version_guard = + match cxt.if_context with Some if_context -> if_context.ios_version_guard | None -> [] + in let allowed_os_versions = - match - (config_iphoneos_target_sdk_version, (cxt.if_context : CLintersContext.if_context option)) - with - | Some iphoneos_target_sdk_version, Some if_context -> - iphoneos_target_sdk_version :: if_context.ios_version_guard - | Some iphoneos_target_sdk_version, None -> - [iphoneos_target_sdk_version] - | _ -> - [] + Option.to_list config_iphoneos_target_sdk_version + @ ios_version_guard + @ Option.to_list available_attr_ios_sdk_current_method in - let max_allowed_version_opt = List.max_elt allowed_os_versions ~compare:Utils.compare_versions in + let max_allowed_version = List.max_elt allowed_os_versions ~compare:Utils.compare_versions in let available_attr_ios_sdk = get_available_attr_ios_sdk an in - match (available_attr_ios_sdk, max_allowed_version_opt) with + match (available_attr_ios_sdk, max_allowed_version) with | Some available_attr_ios_sdk, Some max_allowed_version -> Utils.compare_versions available_attr_ios_sdk max_allowed_version > 0 | _ -> diff --git a/infer/tests/codetoanalyze/objc/ioslints/issues.exp b/infer/tests/codetoanalyze/objc/ioslints/issues.exp index 8053fe2f2..630168f3d 100644 --- a/infer/tests/codetoanalyze/objc/ioslints/issues.exp +++ b/infer/tests/codetoanalyze/objc/ioslints/issues.exp @@ -1,8 +1,8 @@ -codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases::m2, 136, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, no_bucket, ERROR, [] -codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases::m3, 144, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, no_bucket, ERROR, [] -codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases::uifont_without_respondstoselector, 119, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, no_bucket, ERROR, [] -codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases::with_responds_to_selector_in_else, 72, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, no_bucket, ERROR, [] -codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases::without_instances_responds_to_selector, 96, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, no_bucket, ERROR, [] +codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases::m2, 144, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, no_bucket, ERROR, [] +codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases::m3, 152, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, no_bucket, ERROR, [] +codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases::uifont_without_respondstoselector, 127, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, no_bucket, ERROR, [] +codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases::with_responds_to_selector_in_else, 80, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, no_bucket, ERROR, [] +codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases::without_instances_responds_to_selector, 104, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, no_bucket, ERROR, [] codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases::without_responds_to_selector, 65, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, no_bucket, ERROR, [] codetoanalyze/objc/ioslints/unavailable_api_in_supported_ios_sdk.m, OpenURLOptionsFromSourceApplication, 69, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, no_bucket, ERROR, [] codetoanalyze/objc/ioslints/unavailable_api_in_supported_ios_sdk.m, Unavailable_api_in_supported_ios_sdk::unsupported_class, 35, UNAVAILABLE_CLASS_IN_SUPPORTED_IOS_SDK, no_bucket, ERROR, [] diff --git a/infer/tests/codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m b/infer/tests/codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m index ac83f45ff..4bacb0c85 100644 --- a/infer/tests/codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m +++ b/infer/tests/codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m @@ -65,6 +65,14 @@ [a m]; } +// no bug +- (void)call_m:(Unavailable_api_allowed_cases*)a + API_AVAILABLE(ios(10), macosx(10.13)) { + int x = 1; + [a m]; + x = 3; +} + // bug - (void)with_responds_to_selector_in_else:(Unavailable_api_allowed_cases*)a { if ([a respondsToSelector:@selector(m)]) {