Skip to content

AArch64 inline asm does not explain why X19 is reserved #50098

@DavidSpickett

Description

@DavidSpickett
Bugzilla Link 50754
Version trunk
OS Linux
CC @Arnaud-de-Grandmaison-ARM,@smithp35

Extended Description

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.

https://godbolt.org/z/3r74Gq6c8

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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions