<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/195006>195006</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [AArch64] Assembly failure with -save-temps when a function name matches a register name
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          witbring
      </td>
    </tr>
</table>

<pre>
    I found an AArch64 assembly failure in Clang/LLVM when `-save-temps` is used
and a function name overlaps with an AArch64 register name.

This appears to be an ambiguity issue in the emitted assembly: the symbol name
is parsed as a register name by the assembler rather than as a function symbol.

Minimal reproducer:

```
#include <stdio.h>

void xzr(void) {
 printf("Hello world\n");
}

int main(void) {
    xzr();
    return 0;
}
```

Command line:

$ clang-22 --target=aarch64-linux-gnu xzr.c --save-temps

Actual result:

```
xzr.s:44:5: error: expected label or encodable integer pc offset
        bl      xzr
 ^
```

The emitted assembly contains:

    bl      xzr

Here, `xzr` is the intended function name, but the assembler appears to parse
`xzr` as a register name rather than as a branch target symbol. I observed a
similar failure when the `b` instruction is emitted, for example:

    b xzr

Expected result:
The program should compile successfully, and the emitted assembly should
unambiguously refer to the function symbol.

Possible fixes:
One possible fix would be to quote ambiguous symbol names in the emitted
assembly, for example:

    bl "xzr"

In my testing, emitting double quotes around such symbols resolves the
ambiguity. I tested this quoting-based approach across Clang versions 14
through 22 and did not observe compatibility issues.

Alternatively, the assembler/tokenizer could treat the operand of `bl` and
`b` as a symbol/branch target rather than as a register token in this context.

Additional observations:
- I observed this issue across Clang versions 14 through 22.
- The exact number of affected identifiers differs by version, but I found
  approximately 279 to 344 failing cases depending on the Clang version.
- The affected identifiers appear to correspond mostly or entirely to AArch64
  register names.
- This issue appears to be an assembly ambiguity issue caused by unquoted
  symbol names colliding with architecture-specific register names.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJ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