<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><span class="vcard"><a class="email" href="mailto:rnk@google.com" title="Reid Kleckner <rnk@google.com>"> <span class="fn">Reid Kleckner</span></a>
</span> changed
          <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - clang constant-folds away runtime test of stack alignment"
   href="https://bugs.llvm.org/show_bug.cgi?id=45479">bug 45479</a>
          <br>
             <table border="1" cellspacing="0" cellpadding="8">
          <tr>
            <th>What</th>
            <th>Removed</th>
            <th>Added</th>
          </tr>

         <tr>
           <td style="text-align:right;">Resolution</td>
           <td>---
           </td>
           <td>INVALID
           </td>
         </tr>

         <tr>
           <td style="text-align:right;">CC</td>
           <td>
                
           </td>
           <td>rnk@google.com
           </td>
         </tr>

         <tr>
           <td style="text-align:right;">Status</td>
           <td>NEW
           </td>
           <td>RESOLVED
           </td>
         </tr></table>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - clang constant-folds away runtime test of stack alignment"
   href="https://bugs.llvm.org/show_bug.cgi?id=45479#c3">Comment # 3</a>
              on <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED INVALID - clang constant-folds away runtime test of stack alignment"
   href="https://bugs.llvm.org/show_bug.cgi?id=45479">bug 45479</a>
              from <span class="vcard"><a class="email" href="mailto:rnk@google.com" title="Reid Kleckner <rnk@google.com>"> <span class="fn">Reid Kleckner</span></a>
</span></b>
        <pre>The issue is the spin. Here's a similar example, no inline asm, just an opaque
call:

bool cond();
[[gnu::noinline, gnu::noreturn]] static void spin() {
  while (1)
    ;
}
[[gnu::noreturn]] void crash();
int stuff() {
  if (cond()) {
    crash();
  }
  spin();
}

C++ has some standardese about a forward progress guarantee. This sequence of
IR passes will remove the call to spin, propagate the unreachable backwards,
and eliminate the conditional branch:

opt -functionattrs -instcombine -simplifycfg -S

1. function attrs will deduce that spin is "readnone": it has no side effects,
does nothing
2. instcombine will delete the call because the function call produces no value
and it has no side effects
3. simplifycfg will eliminate the conditional branch to unreachable

To fix the problem, do something (anything) in the spin loop: empty asm,
volatile load, anything the C++ standard considers observable.

There is some bug about teaching LLVM not to assume that the source language
has this forward progress guarantee (for Rust etc), but as far as I know it has
not yet been implemented.

>From a C++ perspective, I believe this is working-as-intended: it is legal to
delete `while (1);`. Not that LLVM sets out to do that, it just happens as a
consequence of other desirable cleanup passes.</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>