[PATCH] D22715: Don't crash when generating code for __attribute__((naked)) member functions.

Justin Lebar via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 22 18:19:00 PDT 2016


jlebar created this revision.
jlebar added a reviewer: majnemer.
jlebar added a subscriber: llvm-commits.

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

https://reviews.llvm.org/D22715

Files:
  lib/CodeGen/ItaniumCXXABI.cpp
  test/CodeGenCXX/naked.cpp

Index: test/CodeGenCXX/naked.cpp
===================================================================
--- /dev/null
+++ test/CodeGenCXX/naked.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -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("");
+}
Index: lib/CodeGen/ItaniumCXXABI.cpp
===================================================================
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -1390,6 +1390,10 @@
 }
 
 void ItaniumCXXABI::EmitInstanceFunctionProlog(CodeGenFunction &CGF) {
+  // Naked functions have no prolog.
+  if (CGF.CurFuncDecl->hasAttr<NakedAttr>())
+    return;
+
   /// Initialize the 'this' slot.
   EmitThisParam(CGF);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22715.65203.patch
Type: text/x-patch
Size: 853 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160723/3aca16dc/attachment.bin>


More information about the llvm-commits mailing list