diff --git a/infer/man/man1/infer-full.txt b/infer/man/man1/infer-full.txt index 615fd454fb..ce6ce9a810 100644 --- a/infer/man/man1/infer-full.txt +++ b/infer/man/man1/infer-full.txt @@ -2636,6 +2636,10 @@ INTERNAL OPTIONS --complete-capture-from-reset Cancel the effect of --complete-capture-from. + --compute-captured-context + Activates: Compute context information for captured variables in + Objective-C blocks (Conversely: --no-compute-captured-context) + --config-impact-config-field-patterns +regex Register known config fields that have a config value. The matched name contains class and field names, without package names and diff --git a/infer/src/base/Config.ml b/infer/src/base/Config.ml index acc5bcdedc..ebd582b7fc 100644 --- a/infer/src/base/Config.ml +++ b/infer/src/base/Config.ml @@ -1320,6 +1320,11 @@ and complete_capture_from = code will be equal to the number of rows added to the capture database." +and compute_captured_context = + CLOpt.mk_bool ~long:"compute-captured-context" ~default:false + "Compute context information for captured variables in Objective-C blocks" + + and config_impact_config_field_patterns = CLOpt.mk_string_list ~long:"config-impact-config-field-patterns" ~meta:"regex" "Register known config fields that have a config value. The matched name contains class and \ @@ -4058,6 +4063,8 @@ and compaction_minimum_interval_s = !compaction_minimum_interval_s and complete_capture_from = !complete_capture_from +and compute_captured_context = !compute_captured_context + and config_impact_config_field_patterns = RevList.rev_map !config_impact_config_field_patterns ~f:Str.regexp diff --git a/infer/src/base/Config.mli b/infer/src/base/Config.mli index 28a8f0f4f4..648b8b8532 100644 --- a/infer/src/base/Config.mli +++ b/infer/src/base/Config.mli @@ -285,6 +285,8 @@ val compaction_minimum_interval_s : int val complete_capture_from : string option +val compute_captured_context : bool + val config_impact_config_field_patterns : Str.regexp list val config_impact_config_function_patterns : Str.regexp list diff --git a/infer/src/clang/cFrontend.ml b/infer/src/clang/cFrontend.ml index 012dde6465..8ddac38a53 100644 --- a/infer/src/clang/cFrontend.ml +++ b/infer/src/clang/cFrontend.ml @@ -46,11 +46,13 @@ let do_objc_preanalyses cfg tenv = CAddImplicitGettersSetters.process cfg tenv ; CReplaceDynamicDispatch.process cfg ; CViewControllerLifecycle.process cfg tenv ; - if not Config.preanalysis_html then NodePrinter.print_html := false ; - Timer.time Preanalysis - ~f:(fun () -> ComputeCapturedInfo.process cfg) - ~on_timeout:(fun span -> - L.debug Capture Quiet "TIMEOUT in ComputeCapturedInfo.process after %fs of CPU time@\n" span ) + if Config.compute_captured_context then ( + if not Config.preanalysis_html then NodePrinter.print_html := false ; + Timer.time Preanalysis + ~f:(fun () -> ComputeCapturedInfo.process cfg) + ~on_timeout:(fun span -> + L.debug Capture Quiet "TIMEOUT in ComputeCapturedInfo.process after %fs of CPU time@\n" span ) + ) let do_cpp_preanalyses cfg = CppLambdaCalls.process cfg diff --git a/infer/tests/codetoanalyze/objc/parameter-not-null-checked/issues.exp b/infer/tests/codetoanalyze/objc/parameter-not-null-checked/issues.exp index ad2c6cd455..bcf80dec23 100644 --- a/infer/tests/codetoanalyze/objc/parameter-not-null-checked/issues.exp +++ b/infer/tests/codetoanalyze/objc/parameter-not-null-checked/issues.exp @@ -4,5 +4,4 @@ codetoanalyze/objc/parameter-not-null-checked/Blocks_as_parameters.m, Blocks_as_ codetoanalyze/objc/parameter-not-null-checked/Blocks_as_parameters.m, Blocks_as_parameters.twoBlocksNotCheckedBad:and:and:, 3, BLOCK_PARAMETER_NOT_NULL_CHECKED, no_bucket, WARNING, [Parameter `block2` of Blocks_as_parameters.twoBlocksNotCheckedBad:and:and:,Executing `block2`], "block2("=>"BLOCK_CALL_SAFE(block2"@54:5 codetoanalyze/objc/parameter-not-null-checked/Blocks_as_parameters.m, Blocks_as_parameters.nonnullBlockTwoBlocksBad:and:and:, 4, BLOCK_PARAMETER_NOT_NULL_CHECKED, no_bucket, WARNING, [Parameter `block2` of Blocks_as_parameters.nonnullBlockTwoBlocksBad:and:and:,Executing `block2`], "block2("=>"BLOCK_CALL_SAFE(block2"@82:3 codetoanalyze/objc/parameter-not-null-checked/Blocks_as_parameters.m, Blocks_as_parameters.blockCheckedAssignNULLBad:and:, 3, BLOCK_PARAMETER_NOT_NULL_CHECKED, no_bucket, WARNING, [Parameter `block` of Blocks_as_parameters.blockCheckedAssignNULLBad:and:,Checking `block` for nil,Assigned,Executing `block`], "block("=>"BLOCK_CALL_SAFE(block"@88:5 -codetoanalyze/objc/parameter-not-null-checked/Blocks_as_parameters.m, objc_block_Blocks_as_parameters.m:121, 1, BLOCK_PARAMETER_NOT_NULL_CHECKED, no_bucket, WARNING, [Parameter `completion` of Blocks_as_parameters.uploadTaskWithRequestBad:fromFile:delegate:delegateQueue:completion:,Executing `completion`], "completion("=>"BLOCK_CALL_SAFE(completion"@122:5 codetoanalyze/objc/parameter-not-null-checked/Blocks_as_parameters.m, blockNotCheckedBadNoAutofix, 0, BLOCK_PARAMETER_NOT_NULL_CHECKED, no_bucket, WARNING, [Parameter `block` of blockNotCheckedBadNoAutofix,Executing `block`] diff --git a/infer/tests/codetoanalyze/objc/self-in-block/issues.exp b/infer/tests/codetoanalyze/objc/self-in-block/issues.exp index 421f6d85ef..a6e9db3913 100644 --- a/infer/tests/codetoanalyze/objc/self-in-block/issues.exp +++ b/infer/tests/codetoanalyze/objc/self-in-block/issues.exp @@ -1,5 +1,3 @@ -codetoanalyze/objc/self-in-block/CStringUsingEncodingTest.m, objc_block_CStringUsingEncodingTest.m:18, 1, NSSTRING_INTERNAL_PTR_CAPTURED_IN_BLOCK, no_bucket, ERROR, [Captured variable &encoding defined here,Using captured &encoding] -codetoanalyze/objc/self-in-block/CStringUsingEncodingTest.m, objc_block_CStringUsingEncodingTest.m:34, 1, NSSTRING_INTERNAL_PTR_CAPTURED_IN_BLOCK, no_bucket, ERROR, [Captured variable &utf8string defined here,Using captured &utf8string] codetoanalyze/objc/self-in-block/NoescapeBlock.m, objc_block_NoescapeBlock.m:35, 1, MULTIPLE_WEAKSELF, no_bucket, ERROR, [Using &weakSelf,Using &weakSelf] codetoanalyze/objc/self-in-block/NoescapeBlock.m, objc_block_NoescapeBlock.m:35, 1, WEAK_SELF_IN_NO_ESCAPE_BLOCK, no_bucket, ERROR, [Using &weakSelf,Using &weakSelf] codetoanalyze/objc/self-in-block/NoescapeBlock.m, objc_block_NoescapeBlock.m:35, 2, WEAK_SELF_IN_NO_ESCAPE_BLOCK, no_bucket, ERROR, [Using &weakSelf,Using &weakSelf] diff --git a/infer/tests/codetoanalyze/objcpp/self-in-block/issues.exp b/infer/tests/codetoanalyze/objcpp/self-in-block/issues.exp index d5ee1a3630..b879e64682 100644 --- a/infer/tests/codetoanalyze/objcpp/self-in-block/issues.exp +++ b/infer/tests/codetoanalyze/objcpp/self-in-block/issues.exp @@ -2,4 +2,3 @@ codetoanalyze/objcpp/self-in-block/CxxRefInBlock.mm, objc_block_CxxRefInBlock.mm codetoanalyze/objcpp/self-in-block/CxxRefInBlock.mm, objc_block_CxxRefInBlock.mm:52, 1, CXX_REF_CAPTURED_IN_BLOCK, no_bucket, ERROR, [Captured variable &y defined here,Using captured &y] codetoanalyze/objcpp/self-in-block/CxxRefInBlock.mm, objc_block_CxxRefInBlock.mm:114, 1, CXX_REF_CAPTURED_IN_BLOCK, no_bucket, ERROR, [Captured variable &y defined here,Using captured &y] codetoanalyze/objcpp/self-in-block/CxxRefInBlock.mm, objc_block_CxxRefInBlock.mm:114, 2, CXX_REF_CAPTURED_IN_BLOCK, no_bucket, ERROR, [Captured variable &z defined here,Using captured &z] -codetoanalyze/objcpp/self-in-block/CxxStringInBlock.mm, objc_block_CxxStringInBlock.mm:27, 1, CXX_STRING_CAPTURED_IN_BLOCK, no_bucket, ERROR, [Captured variable &c defined here,Using captured &c]