For naked functions with parameters, Clang would emit prologues that end up clobbering the stack because LLVM doesn't set up a stack frame. For example, this function on X86:
attribute((naked)) int f(int x) {
asm("movl $42, %eax"); asm("retl");
}
Results in:
_Z1fi:
movl 12(%esp), %eax movl %eax, (%esp) <--- Oops. movl $42, %eax retl
(This was already reported as PR18791, and PR20028 for the epilogue.)
My patch does three things, which can be committed separately, but I figured it's easier to review them together:
- Don't emit prologues/epilogues for naked functions
- Don't allow non-asm statements in naked functions
- Don't allow asm statements to refer to parameters in naked functions.
Please take a look.