Don't crash when generating code for __attribute__((naked)) member functions.

Summary:
Previously this crashed inside EmitThisParam().  There should be no
prelude for naked functions, so just skip the whole thing.

Reviewers: majnemer

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D22715

llvm-svn: 276925
This commit is contained in:
Justin Lebar
2016-07-27 22:04:24 +00:00
parent fc07e8b428
commit ed4f172c00
3 changed files with 21 additions and 0 deletions

View File

@@ -1390,6 +1390,10 @@ void ItaniumCXXABI::addImplicitStructorParams(CodeGenFunction &CGF,
}
void ItaniumCXXABI::EmitInstanceFunctionProlog(CodeGenFunction &CGF) {
// Naked functions have no prolog.
if (CGF.CurFuncDecl && CGF.CurFuncDecl->hasAttr<NakedAttr>())
return;
/// Initialize the 'this' slot.
EmitThisParam(CGF);

View File

@@ -1417,6 +1417,10 @@ llvm::Value *MicrosoftCXXABI::adjustThisParameterInVirtualFunctionPrologue(
}
void MicrosoftCXXABI::EmitInstanceFunctionProlog(CodeGenFunction &CGF) {
// Naked functions have no prolog.
if (CGF.CurFuncDecl && CGF.CurFuncDecl->hasAttr<NakedAttr>())
return;
EmitThisParam(CGF);
/// If this is a function that the ABI specifies returns 'this', initialize

View File

@@ -0,0 +1,13 @@
// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s
// RUN: %clang_cc1 -triple x86_64-windows -emit-llvm %s -o - | FileCheck %s
class TestNaked {
public:
void NakedFunction();
};
__attribute__((naked)) void TestNaked::NakedFunction() {
// CHECK-LABEL: define void @
// CHECK: call void asm sideeffect
asm("");
}