[AArch64] Assembly failure with -save-temps when a function name matches a register name
Nobody has claimed this yet.
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure with the provided xzr.c example and clang-22 --target=aarch64-linux-gnu xzr.c --save-temps, then inspect the emitted bl xzr and b xzr operands. Trace the AArch64 assembly emission and assembler parsing involved; done means the program compiles successfully and branch targets that match register names are unambiguous.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100