diff --git a/infer/src/base/Config.ml b/infer/src/base/Config.ml index 2c29b17c9..042fe9817 100644 --- a/infer/src/base/Config.ml +++ b/infer/src/base/Config.ml @@ -1128,6 +1128,13 @@ and iphoneos_target_sdk_version = ~in_help:CLOpt.[Capture, manual_clang_linters] "Specify the target SDK version to use for iphoneos" +and iphoneos_target_sdk_version_skip_path = + CLOpt.mk_string_list ~long:"iphoneos-target-sdk-version-skip-path" + ~in_help:CLOpt.[Capture, manual_clang_linters] + ~meta:"path prefix OCaml regex" + "To be used together with iphoneos-target-sdk-version, \ + to disable that flag in a particular path (can be specified multiple times)" + and issues_fields = CLOpt.mk_symbol_seq ~long:"issues-fields" ~in_help:CLOpt.[Report, manual_generic] @@ -1899,6 +1906,7 @@ and ignore_trivial_traces = !ignore_trivial_traces and immutable_cast = !immutable_cast and infer_cache = !infer_cache and iphoneos_target_sdk_version = !iphoneos_target_sdk_version +and iphoneos_target_sdk_version_skip_path = !iphoneos_target_sdk_version_skip_path and issues_fields = !issues_fields and iterations = !iterations and java_jar_compiler = !java_jar_compiler diff --git a/infer/src/base/Config.mli b/infer/src/base/Config.mli index d0e94c34e..6e66a5da9 100644 --- a/infer/src/base/Config.mli +++ b/infer/src/base/Config.mli @@ -251,6 +251,7 @@ val ignore_trivial_traces : bool val immutable_cast : bool val infer_cache : string option val iphoneos_target_sdk_version : string option +val iphoneos_target_sdk_version_skip_path : string list val issues_fields : [`Issue_field_bug_class | `Issue_field_kind | `Issue_field_bug_type diff --git a/infer/src/clang/cPredicates.ml b/infer/src/clang/cPredicates.ml index d167375f1..0163038aa 100644 --- a/infer/src/clang/cPredicates.ml +++ b/infer/src/clang/cPredicates.ml @@ -328,9 +328,19 @@ let is_class an re = declaration_has_name an re | _ -> false +let should_use_iphoneos_target_sdk_version (cxt : CLintersContext.context) = + let source_file = cxt.translation_unit_context.source_file in + not (List.exists + ~f:(fun path -> ALVar.str_match_regex (SourceFile.to_rel_path source_file) path) + Config.iphoneos_target_sdk_version_skip_path) + let decl_unavailable_in_supported_ios_sdk (cxt : CLintersContext.context) an = + let config_iphoneos_target_sdk_version = + if should_use_iphoneos_target_sdk_version cxt then + Config.iphoneos_target_sdk_version + else None in let allowed_os_versions = - match Config.iphoneos_target_sdk_version, + 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 diff --git a/infer/tests/codetoanalyze/objc/ioslints/Makefile b/infer/tests/codetoanalyze/objc/ioslints/Makefile index ef6cbfd44..60765f306 100644 --- a/infer/tests/codetoanalyze/objc/ioslints/Makefile +++ b/infer/tests/codetoanalyze/objc/ioslints/Makefile @@ -17,7 +17,9 @@ CLANG_OPTIONS = -x objective-c \ ANALYZER = linters INFER_OPTIONS = --no-filtering --debug-exceptions --project-root $(TESTS_DIR) \ ---iphoneos-target-sdk-version 8.0 --no-failures-allowed +--iphoneos-target-sdk-version 8.0 \ +--iphoneos-target-sdk-version-skip-path "codetoanalyze/objc/ioslints/filter_out_unavailable_api\.m" \ +--no-failures-allowed INFERPRINT_OPTIONS = --issues-tests SOURCES = \ diff --git a/infer/tests/codetoanalyze/objc/ioslints/filter_out_unavailable_api.m b/infer/tests/codetoanalyze/objc/ioslints/filter_out_unavailable_api.m new file mode 100644 index 000000000..369109340 --- /dev/null +++ b/infer/tests/codetoanalyze/objc/ioslints/filter_out_unavailable_api.m @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2017 - present Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ +#import + +@interface Filter_out_unavailable_api : NSObject + +- (void)n NS_AVAILABLE(10_12, 10_0); + +@end + +@implementation Filter_out_unavailable_api + +- (void)n { +} + +// no bug +- (void)with_responds_to_selector:(Filter_out_unavailable_api*)a { + [a n]; +} + +@end