<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [static analyzer/ObjC] Static analyzer does not catch invoking a null block parameter"
   href="https://bugs.llvm.org/show_bug.cgi?id=42398">42398</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[static analyzer/ObjC] Static analyzer does not catch invoking a null block parameter
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Static Analyzer
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>dcoughlin@apple.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>bhamiltoncx@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dcoughlin@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=22141" name="attach_22141" title="Repro for static analyzer bug">attachment 22141</a> <a href="attachment.cgi?id=22141&action=edit" title="Repro for static analyzer bug">[details]</a></span>
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();
  ^</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>