diff options
author | Hans Wennborg <hans@hanshq.net> | 2014-09-04 22:16:33 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2014-09-04 22:16:33 +0000 |
commit | d71907dd077ba3385dbb5ebad479eeb7391cef91 (patch) | |
tree | 920c3ec59c50d6d80bcab90bee8f679e5c714dbe /clang/lib | |
parent | 8d082d187e573988ef9e3e5ecbbe2553bdeb5a70 (diff) | |
download | bcm5719-llvm-d71907dd077ba3385dbb5ebad479eeb7391cef91.tar.gz bcm5719-llvm-d71907dd077ba3385dbb5ebad479eeb7391cef91.zip |
Don't emit prologues or epilogues for naked functions (PR18791, PR20028)
For naked functions with parameters, Clang would still emit stores in the prologue
that would clobber the stack, because LLVM doesn't set up a stack frame. (This
shows up in -O0 compiles, because the stores are optimized away otherwise.)
For example:
__attribute__((naked)) int f(int x) {
asm("movl $42, %eax");
asm("retl");
}
Would result in:
_Z1fi:
movl 12(%esp), %eax
movl %eax, (%esp) <--- Oops.
movl $42, %eax
retl
Differential Revision: http://reviews.llvm.org/D5183
llvm-svn: 217198
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/CodeGen/CGCall.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index ce16d3bd64c..f0eeba06f9c 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -1462,6 +1462,10 @@ static bool shouldAddNonNullAttr(const Decl *FD, const ParmVarDecl *PVD) { void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI, llvm::Function *Fn, const FunctionArgList &Args) { + if (CurCodeDecl && CurCodeDecl->hasAttr<NakedAttr>()) + // Naked functions don't have prologues. + return; + // If this is an implicit-return-zero function, go ahead and // initialize the return value. TODO: it might be nice to have // a more general mechanism for this that didn't require synthesized @@ -1985,6 +1989,12 @@ static llvm::StoreInst *findDominatingStoreToReturnValue(CodeGenFunction &CGF) { void CodeGenFunction::EmitFunctionEpilog(const CGFunctionInfo &FI, bool EmitRetDbgLoc, SourceLocation EndLoc) { + if (CurCodeDecl && CurCodeDecl->hasAttr<NakedAttr>()) { + // Naked functions don't have epilogues. + Builder.CreateUnreachable(); + return; + } + // Functions with no result always return void. if (!ReturnValue) { Builder.CreateRetVoid(); |