<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 - statement-expression and clang-block causes incorrect compilation error"
   href="https://bugs.llvm.org/show_bug.cgi?id=39040">39040</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>statement-expression and clang-block causes incorrect compilation error
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>7.0
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Linux
          </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>Frontend
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>remi@qumulo.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=20905" name="attach_20905" title="C program that causes the erroneous compilation error">attachment 20905</a> <a href="attachment.cgi?id=20905&action=edit" title="C program that causes the erroneous compilation error">[details]</a></span>
C program that causes the erroneous compilation error

In versions of clang before 7.0, it use to be the case that you could return a
clang-block from a gnu statement-expression just fine, but now in 7 it gives
this error for some reason:

block_statement_expression.c:4:42: error: returning block that lives on the
local stack
    __auto_type f = ({ const int c = 12; ^ { return c; }; });
                                         ^~~~~~~~~~~~~~~
1 error generated.

Statement-expressions as I understand them do not allocate their own stack, and
thus it should be fine to return a block from them. And indeed if we cast the
block to (void *) and back to the block type again, the error goes away and the
code works just fine.

I think this change in behavior was unintended and is breaking existing code
that is using clang-blocks.

I invoked clang like this: clang -fblocks block_statement_expression.c
I have included a c-code example and attached it to the issue.</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>