<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 --- - GNU "a?:b" ternary operator with blocks causes bus error"
   href="http://llvm.org/bugs/show_bug.cgi?id=15663">15663</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>GNU "a?:b" ternary operator with blocks causes bus error
          </td>
        </tr>

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

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

        <tr>
          <th>Hardware</th>
          <td>All
          </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>-New Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>arthur.j.odwyer@gmail.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=10283" name="attach_10283" title="Output of "clang test.c -v"">attachment 10283</a> <a href="attachment.cgi?id=10283&action=edit" title="Output of "clang test.c -v"">[details]</a></span>
Output of "clang test.c -v"

cat >test.c <<EOF
void (^b)() = ^{};
int main() {
    (b ?: ^{})();
}
EOF
clang test.c
./a.out

Bus error: 10

Notice that "void (^b)()" is the Apple Blocks extension, and "?:" is the GNU
ternary operator — "a ?: b" is equivalent to "a ? a : b" except that "a" is
evaluated only once.

This reproduces in Objective-C (test.m) as well as in C (test.c).

Replacing the offending expression with (^{} ?: ^{}) avoids the bus error.
Replacing it with (b ?: b) also avoids the bus error.

In my unreduced code, "b" was a complicated expression with side effects that
could in fact be NULL (hence my use of the GNU ternary operator), but it turns
out that this is not relevant to reproducing the bug.</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>