<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 --- - x86/x64 clang appears not to respect __attribute__((noinline)) with -O1"
   href="https://llvm.org/bugs/show_bug.cgi?id=26545">26545</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>x86/x64 clang appears not to respect __attribute__((noinline)) with -O1
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>3.7
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </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>llvmbugs@tomseddon.plus.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>Created <span class=""><a href="attachment.cgi?id=15863" name="attach_15863" title="code">attachment 15863</a> <a href="attachment.cgi?id=15863&action=edit" title="code">[details]</a></span>
code

Repro steps:

Compile the attached code with -O1 and generate assembly language.

- From shell: clang -O1 -S main.c (I tested this with Xcode's clang - "Apple
LLVM version 7.0.2 (clang-700.1.81); Target: x86_64-apple-darwin14.5.0; Thread
model: posix")

- See it on gcc explorer: <a href="http://goo.gl/Im4c95">http://goo.gl/Im4c95</a> (link uses x86 clang 3.7.1)

Expected result:

Generated code contains a call to the Test function somewhere, since Test has
the noinline attribute. (This even though -O1 was specified, and the Test
function is an ideal candidate for inlining.)

Actual result:

The compiler appears to have inlined the Test function (or otherwise determined
somehow that the result of the call would be -55).

Notes:

- I couldn't find any clang documentation for noinline so I'm just making
assumptions about what it does (sorry)

- The gcc documentation for noinline suggests this sort of problem is a
possibility - see
<a href="https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-g_t_0040code_007bnoinline_007d-function-attribute-3218">https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-g_t_0040code_007bnoinline_007d-function-attribute-3218</a>
- but the workaround it mentions has no effect in clang

- If you force the compiler to generate the Test function (e.g., by adding
something like ``printf("%p\n",(void *)&Test);''), the call still isn't
generated</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>