From 530e0b8dc6564b0a389283215387a291149e5a72 Mon Sep 17 00:00:00 2001 From: Dulma Churchill Date: Fri, 1 Nov 2024 10:08:47 -0700 Subject: [PATCH] [param-not-null] Do not report on parameters of blocks Summary: There are cases where reporting on parameters of blocks is not wanted, however those parameters are not always annotated with Nonnull. So we'll stop reporting for them. We can still report when block parameters captured from the parent methods are executed within a block. Reviewed By: geralt-encore Differential Revision: D65340747 fbshipit-source-id: 43e1c96aa41518f4db0cab8d4b292ae95d27855b --- infer/src/checkers/ParameterNotNullChecked.ml | 6 +++--- .../objc/parameter-not-null-checked/Blocks_as_parameters.m | 2 +- .../objc/parameter-not-null-checked/issues.exp | 2 -- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/infer/src/checkers/ParameterNotNullChecked.ml b/infer/src/checkers/ParameterNotNullChecked.ml index e7f7c0e6ac..cd133188cc 100644 --- a/infer/src/checkers/ParameterNotNullChecked.ml +++ b/infer/src/checkers/ParameterNotNullChecked.ml @@ -282,9 +282,9 @@ let init_block_params let checker ({IntraproceduralAnalysis.proc_desc} as analysis_data) = let attributes = Procdesc.get_attributes proc_desc in let captured_formals_attributes = get_captured_formals attributes in - let formals_attributes = - List.map ~f:(fun formal -> (formal, attributes, false)) attributes.ProcAttributes.formals - in + let procname = Procdesc.get_proc_name proc_desc in + let formals = if Procname.is_objc_block procname then [] else attributes.ProcAttributes.formals in + let formals_attributes = List.map ~f:(fun formal -> (formal, attributes, false)) formals in let initial_blockParams, initTraceInfo = init_block_params (List.append formals_attributes captured_formals_attributes) in diff --git a/infer/tests/codetoanalyze/objc/parameter-not-null-checked/Blocks_as_parameters.m b/infer/tests/codetoanalyze/objc/parameter-not-null-checked/Blocks_as_parameters.m index ab74fd2ca4..340a2c747a 100644 --- a/infer/tests/codetoanalyze/objc/parameter-not-null-checked/Blocks_as_parameters.m +++ b/infer/tests/codetoanalyze/objc/parameter-not-null-checked/Blocks_as_parameters.m @@ -12,7 +12,7 @@ typedef void (^NewAnnotateBlock1)(const char* _Nullable key, void MarkerAnnotateSync1(NS_NOESCAPE _Nullable NewAnnotateSyncBlock1 block) {} -void testAnnotateOk_FP(NSString* composerSessionID) { +void testAnnotateOk(NSString* composerSessionID) { MarkerAnnotateSync1(^(NewAnnotateBlock1 annotate) { annotate("composer_session_id", composerSessionID); }); 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 06eaf809d9..ad2c6cd455 100644 --- a/infer/tests/codetoanalyze/objc/parameter-not-null-checked/issues.exp +++ b/infer/tests/codetoanalyze/objc/parameter-not-null-checked/issues.exp @@ -1,4 +1,3 @@ -codetoanalyze/objc/parameter-not-null-checked/Blocks_as_parameters.m, objc_block_Blocks_as_parameters.m:16, 1, BLOCK_PARAMETER_NOT_NULL_CHECKED, no_bucket, WARNING, [Parameter `annotate` of objc_block_Blocks_as_parameters.m:16,Executing `annotate`], "annotate("=>"BLOCK_CALL_SAFE(annotate, "@17:5 codetoanalyze/objc/parameter-not-null-checked/Blocks_as_parameters.m, Blocks_as_parameters.blockNotCheckedBad:and:, 1, BLOCK_PARAMETER_NOT_NULL_CHECKED, no_bucket, WARNING, [Parameter `block` of Blocks_as_parameters.blockNotCheckedBad:and:,Executing `block`], "block("=>"BLOCK_CALL_SAFE(block"@32:3 codetoanalyze/objc/parameter-not-null-checked/Blocks_as_parameters.m, Blocks_as_parameters.blockNotCheckedBad1:and:, 1, BLOCK_PARAMETER_NOT_NULL_CHECKED, no_bucket, WARNING, [Parameter `block` of Blocks_as_parameters.blockNotCheckedBad1:and:,Executing `block`], "block("=>"BLOCK_CALL_SAFE(block, "@36:3 codetoanalyze/objc/parameter-not-null-checked/Blocks_as_parameters.m, Blocks_as_parameters.twoBlocksNotCheckedBad:and:and:, 2, BLOCK_PARAMETER_NOT_NULL_CHECKED, no_bucket, WARNING, [Parameter `block1` of Blocks_as_parameters.twoBlocksNotCheckedBad:and:and:,Executing `block1`], "block1("=>"BLOCK_CALL_SAFE(block1"@53:5 @@ -6,5 +5,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.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, objc_block_Blocks_as_parameters.m:213, 1, BLOCK_PARAMETER_NOT_NULL_CHECKED, no_bucket, WARNING, [Parameter `annotate` of objc_block_Blocks_as_parameters.m:213,Executing `annotate`], "annotate("=>"BLOCK_CALL_SAFE(annotate, "@214: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`]