<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 - Shrink-wrap generates bad code in presence of stack save/restore"
   href="https://bugs.llvm.org/show_bug.cgi?id=37876">37876</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Shrink-wrap generates bad code in presence of stack save/restore
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>6.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>Common Code Generator Code
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>kenner@adacore.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=20447" name="attach_20447" title="Input LLVM IR file.">attachment 20447</a> <a href="attachment.cgi?id=20447&action=edit" title="Input LLVM IR file.">[details]</a></span>
Input LLVM IR file.

See attached file bug.ll and look at the function whose name ends with
"decompose".  Run "llc bug.ll" and look at the same function in bug.s.  The
shrink wrapper is setting up a prologue at %false4.  That pushes %rbp.  Then it
compiles the  "%3 = call i8* @llvm.stacksave()" into  "movq %rsp, %r8".  It
puts the epilogue at the end of block %end7, which is just "movq %rbp, %rsp;
popq %rbp".
But then it (eventually) branches to %if-next, which, at the end, has "call
void @llvm.stackrestore(i8* %3)", which restores the save above.  Then it
returns.  These two things are "movq %r8, %rsp; retq".  Unfortunately, %rsp was
saved *before* the push of %rbp, but restored after.  So %rsp is restore
incorrectly, no longer points to the return address,and the return goes to a
bogus place (the saved value of %rbp) and we get a SIGSEGV.  Running with
-enable-shrink-wrap=0 works around this.</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>