r276925 - Don't crash when generating code for __attribute__((naked)) member functions.
Justin Lebar via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 27 15:04:25 PDT 2016
Author: jlebar
Date: Wed Jul 27 17:04:24 2016
New Revision: 276925
URL: http://llvm.org/viewvc/llvm-project?rev=276925&view=rev
Log:
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
Added:
cfe/trunk/test/CodeGenCXX/naked.cpp
Modified:
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=276925&r1=276924&r2=276925&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Wed Jul 27 17:04:24 2016
@@ -1390,6 +1390,10 @@ void ItaniumCXXABI::addImplicitStructorP
}
void ItaniumCXXABI::EmitInstanceFunctionProlog(CodeGenFunction &CGF) {
+ // Naked functions have no prolog.
+ if (CGF.CurFuncDecl && CGF.CurFuncDecl->hasAttr<NakedAttr>())
+ return;
+
/// Initialize the 'this' slot.
EmitThisParam(CGF);
Modified: cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp?rev=276925&r1=276924&r2=276925&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp Wed Jul 27 17:04:24 2016
@@ -1417,6 +1417,10 @@ llvm::Value *MicrosoftCXXABI::adjustThis
}
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
Added: cfe/trunk/test/CodeGenCXX/naked.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/naked.cpp?rev=276925&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/naked.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/naked.cpp Wed Jul 27 17:04:24 2016
@@ -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("");
+}
More information about the cfe-commits
mailing list