[llvm-bugs] [Bug 42398] New: [static analyzer/ObjC] Static analyzer does not catch invoking a null block parameter

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jun 25 15:06:53 PDT 2019


https://bugs.llvm.org/show_bug.cgi?id=42398

            Bug ID: 42398
           Summary: [static analyzer/ObjC] Static analyzer does not catch
                    invoking a null block parameter
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Static Analyzer
          Assignee: dcoughlin at apple.com
          Reporter: bhamiltoncx at gmail.com
                CC: dcoughlin at apple.com, llvm-bugs at lists.llvm.org

Created attachment 22141
  --> https://bugs.llvm.org/attachment.cgi?id=22141&action=edit
Repro for static analyzer bug

The Clang static analyzer correctly catches invoking a null block when it's a
local variable, but fails to catch the same issue when it's a nullable block
parameter:

% cat test.m
static void DoStuff(void (^_Nullable block_param)()) {
  // This raises `core.CallAndMessage` as expected:
  // warning: Called function pointer is null (null dereference)
[clang-analyzer-core.CallAndMessage]
  void (^block)() = 0;
  block();

  // This should raise `nullability.NullableDereferenced` but does not
  block_param();

  // This raises neither `core.CallAndMessage` nor
`nullability.NullableDereferenced`
  block_param = 0;
  block_param();
}

% clang-tidy -checks=\* test.m -- -fblocks                                 
1 warning generated.
test.m:5:3: warning: Called function pointer is null (null dereference)
[clang-analyzer-core.CallAndMessage]
  block();
  ^
test.m:4:3: note: 'block' initialized to a null pointer value
  void (^block)() = 0;
  ^
test.m:5:3: note: Called function pointer is null (null dereference)
  block();
  ^

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190625/6a8f7eeb/attachment-0001.html>


More information about the llvm-bugs mailing list