Skip to content

Commit

Permalink
Don't crash when generating code for __attribute__((naked)) member fu…
Browse files Browse the repository at this point in the history
…nctions.

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
  • Loading branch information
Justin Lebar committed Jul 27, 2016
1 parent fc07e8b commit ed4f172
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions clang/lib/CodeGen/ItaniumCXXABI.cpp
Expand Up @@ -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);

Expand Down
4 changes: 4 additions & 0 deletions clang/lib/CodeGen/MicrosoftCXXABI.cpp
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions clang/test/CodeGenCXX/naked.cpp
@@ -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("");
}

0 comments on commit ed4f172

Please sign in to comment.