<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 --- - __attribute__((force_align_arg_pointer)) with __asm__ causes segfault"
   href="https://llvm.org/bugs/show_bug.cgi?id=27183">27183</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>__attribute__((force_align_arg_pointer)) with __asm__ causes segfault
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>3.8
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </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>LLVM Codegen
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>cjhopman@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>Created <span class=""><a href="attachment.cgi?id=16149" name="attach_16149" title="Repro code.">attachment 16149</a> <a href="attachment.cgi?id=16149&action=edit" title="Repro code.">[details]</a></span>
Repro code.

This code:

__attribute__((noinline)) int use_sa(int* sa) {
  return *sa;                                                                  
                                                                               
                                                                               
                                       }
                                                                               
                                                                               
                                                                               
                                       __attribute__((force_align_arg_pointer))
int doit() {                                                                   
                                                                               
                                                                               
                                         int sa;
  long res;
  __asm__ __volatile__(                                                        
                                                                               
                                                                               
                                             "nop"
      : "=a" (res)
      : "S" (sizeof(sa))
      : "esp");

  sa = 1;
  return use_sa(&sa);
}

int main() {
  return doit();                                                               
                                                                               
                                                                               
                                       }

compiled with 'clang++ -m32 -O3' generates incorrect code that will segfault.
The offending machine code looks something like:

00000010 <doit()>:
  10: 55                    push   %ebp
  11: 89 e5                 mov    %esp,%ebp
  13: 56                    push   %esi
  14: 83 e4 f0              and    $0xfffffff0,%esp
  17: 83 ec 20              sub    $0x20,%esp
  1a: 89 e6                 mov    %esp,%esi
  1c: be 04 00 00 00        mov    $0x4,%esi                                   
                                                                               
                                                                               
                                         21: 90                    nop
  22: c7 46 10 01 00 00 00  movl   $0x1,0x10(%esi)
  29: 8d 46 10              lea    0x10(%esi),%eax
  2c: 89 04 24              mov    %eax,(%esp)                                 
                                                                               
                                                                               
                                         2f: e8 cc ff ff ff        call   0
<use_sa(int*)>
  34: 8d 65 fc              lea    -0x4(%ebp),%esp
  37: 5e                    pop    %esi
  38: 5d                    pop    %ebp                                        
                                                                               
                                                                               
                                         39: c3                    ret         
                                                                               
                                                                               
                                                                               
3a: 66 0f 1f 44 00 00     nopw   0x0(%eax,%eax,1)

Note the write to %esi @ 1c and then the dereference @ 29.</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>