<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </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 --- - clang-sa should warn when taking the address of __block storage?"
   href="http://llvm.org/bugs/show_bug.cgi?id=15649">15649</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>clang-sa should warn when taking the address of __block storage?
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>3.2
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Macintosh
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>MacOS X
          </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>kremenek@apple.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>jim.correia@pobox.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=10270" name="attach_10270" title="sample code">attachment 10270</a> <a href="attachment.cgi?id=10270&action=edit" title="sample code">[details]</a></span>
sample code

Build and run the attached sample code.

-performTest1 works correctly when built with MRR. (Ignoring the possibility
that it won't if the autorelease pool implementation details of
NSFileCoordinator change.)

It doesn't work correctly when built for ARC. The reason is that the code
that the compiler generates (-performTest2 is written similarly to the what
the method looks like with the compiler generated code) overwrites the value
of error set in the block.

-performTest3 doesn't work correctly (either for MRR or ARC) because we take
the address of __block storage, then copy the block, moving that value to the
heap. We writing to the stale value on the stack.

These are really two separate issues, but both avoidable if clang-sa issued a
warning that taking the address of __block storage is likely going to lead to
heartache.

xcrun clang NSFileCoordinatorErrorPattern.m -fobjc-arc -framework Foundation 

xcrun clang --version

    Apple LLVM version 4.2 (clang-425.0.27) (based on LLVM 3.2svn)
    Target: x86_64-apple-darwin12.3.0
    Thread model: posix</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>