summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorJustin Lebar <jlebar@google.com>2016-07-27 22:04:24 +0000
committerJustin Lebar <jlebar@google.com>2016-07-27 22:04:24 +0000
commited4f172c00baee0127c14df55364ae8a80b05a8e (patch)
tree04ef2d6825dddc5ed213fae556fab117cf64b00f /clang
parentfc07e8b428b08235eb44cc2c418436b388ffc51e (diff)
downloadbcm5719-llvm-ed4f172c00baee0127c14df55364ae8a80b05a8e.tar.gz
bcm5719-llvm-ed4f172c00baee0127c14df55364ae8a80b05a8e.zip
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
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/CodeGen/ItaniumCXXABI.cpp4
-rw-r--r--clang/lib/CodeGen/MicrosoftCXXABI.cpp4
-rw-r--r--clang/test/CodeGenCXX/naked.cpp13
3 files changed, 21 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index 6051594fb00..36eb40ef09c 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -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);
diff --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index 6b919d16881..28312fce774 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -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
diff --git a/clang/test/CodeGenCXX/naked.cpp b/clang/test/CodeGenCXX/naked.cpp
new file mode 100644
index 00000000000..7032823e44b
--- /dev/null
+++ b/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("");
+}
OpenPOWER on IntegriCloud