<html>
    <head>
      <base href="https://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 --- - should be able to apply attribute always_inline to ObjC blocks"
   href="https://llvm.org/bugs/show_bug.cgi?id=24513">24513</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>should be able to apply attribute always_inline to ObjC blocks
          </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>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>Frontend
          </td>
        </tr>

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

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

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Since an ObjC block is essentially a wrapper around a couple of functions, and
those functions can be inlined, I would like to apply the always_inline
attribute to a block expression to do the equivalent of marking (all) those
functions as such.  Currently, Clang does not support this:

warning: 'always_inline' attribute only applies to functions
[-Wignored-attributes]
    int (^x)() = ^() __attribute__((always_inline)) { return 5; } ;

Admittedly, since blocks are always called through the equivalent of function
pointers, it would be impossible to actually enforce inlining, even at -O0, the
way the attribute normally does.  However, when optimization is on and Clang
knows the target of a function pointer call, it does currently seem to honor
the attribute:

    // Without the attribute, clang -O3 on my system generates main with 5x
    // "callq _block_invoke", and _block_invoke with 15x "callq _foo".  With it
    // I get 75 calls to foo.
    int foo(int);
    //__attribute__((always_inline))
    int block_invoke(struct block *b) {
        return foo(1) + foo(2) + foo(3) + foo(4) + foo(5) +
               foo(1) + foo(2) + foo(3) + foo(4) + foo(5) +
               foo(1) + foo(2) + foo(3) + foo(4) + foo(5);
    }

    struct block { int (*invoke)(struct block *); int state; };
    int main() {
        struct block block = { block_invoke, 42 };
        return block.invoke(&block) +
               block.invoke(&block) +
               block.invoke(&block) +
               block.invoke(&block) +
               block.invoke(&block);
    }

It would make sense to allow this to be taken advantage of with real blocks.</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>