[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
master
Dulma Churchill 7 years ago committed by Facebook Github Bot
parent abee644b91
commit 234d3627b6

@ -1 +1 @@
Subproject commit 7c96ec5ec404096af9c8ad941cb46b3f1fe7477f Subproject commit 4af7ff7ad4438a79a0dbc1bd9cd902224754a5e3

@ -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 compute_if_context (context: CLintersContext.context) stmt =
let selector = get_responds_to_selector stmt in let selector = get_responds_to_selector stmt in
let receiver_class_method_call = let receiver_class_method_call =
@ -153,6 +165,8 @@ let compute_if_context (context: CLintersContext.context) stmt =
-> [] -> []
in in
let os_version = get_current_os_version 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 = let within_responds_to_selector_block, within_available_class_block, ios_version_guard =
match context.if_context with match context.if_context with
| Some if_context | Some if_context

@ -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_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_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_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, 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, 28, 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, 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, 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, 53, 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, [] codetoanalyze/objc/ioslints/unavailable_property_ios.m, FNFPlayerLayer_initWithConfigs, 22, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, []

@ -23,11 +23,20 @@ NS_CLASS_AVAILABLE(10_12, 10_0)
@implementation Unavailable_api_in_supported_ios_sdk @implementation Unavailable_api_in_supported_ios_sdk
// bug
- (void)test:(int)n and:(NSData*)data { - (void)test:(int)n and:(NSData*)data {
NSDictionary* cacheData = NSDictionary* cacheData =
[NSKeyedUnarchiver unarchiveTopLevelObjectWithData:data error:nil]; [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 // bug
- (void)unsupported_class { - (void)unsupported_class {
AVPlayerLooper* looper = AVPlayerLooper* looper =

Loading…
Cancel
Save