[PATCH] Don't emit prologues/epilogues for naked functions (PR18791, PR20028)

Hans Wennborg hans at chromium.org
Wed Sep 3 19:17:27 PDT 2014


Hi rnk,

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.

http://reviews.llvm.org/D5183

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/CodeGen/CGCall.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaStmtAsm.cpp
  test/CodeGen/attr-naked.c
  test/Sema/attr-naked.c
  test/Sema/ms-inline-asm.c
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D5183.13237.patch
Type: text/x-patch
Size: 5703 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140904/fd4468a3/attachment.bin>


More information about the cfe-commits mailing list