<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 - AArch64 inline asm does not explain why X19 is reserved"
   href="https://bugs.llvm.org/show_bug.cgi?id=50754">50754</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>AArch64 inline asm does not explain why X19 is reserved
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>trunk
          </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>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Backend: AArch64
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>david.spickett@linaro.org
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>arnaud.degrandmaison@arm.com, llvm-bugs@lists.llvm.org, smithp352@googlemail.com, Ties.Stuij@arm.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Compiling the following:
extern void fn1(char*);
extern void fn2(int*);

int a;
int main() {
  char b[a];
  fn1(b);
  __asm("nop" : : : "x19");
  int c[64];
  fn2(c);
  return 0;
}

With:
./bin/clang --target=aarch64-linux-gnu -c -O0 test.c

Gives the following warning:
warning: inline asm clobber list contains reserved registers: X19
[-Winline-asm]
  __asm("nop" : : : "x19");
        ^
note: Reserved registers on the clobber list may not be preserved across the
asm statement, and clobbering them may lead to undefined behaviour.
1 warning generated.

The warning is not present when compiling with GCC.

<a href="https://godbolt.org/z/3r74Gq6c8">https://godbolt.org/z/3r74Gq6c8</a>

This is because llvm uses X19 as the base pointer for the stack frame. Or at
least, it does when it needs to. So small changes to the code shown can mean
you get a warning or not. (which is correct, but confusing if you're trying to
understand what's going on)

For the frame pointer X29 you get "FP" instead which is more obvious. Even if
you just got "X29" you could look at the ABI docs.

inline asm clobber list contains reserved registers: X19, FP [-Winline-asm]

The base pointer register is not assigned by the ABI it's up to the compiler so
it'd be good to add some explanation to this message.

Perhaps:
note: llvm uses X19 as the stack frame base pointer register.</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>