Currently, clang will assert for non-static class member func with naked 
attribute because clang won't emit any prologues for such functions, so it 
would assert trying to codegen 'this' pointer

This patch fixes bug http://llvm.org/bugs/show_bug.cgi?id=22429

http://reviews.llvm.org/D7329

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaStmtAsm.cpp
  test/Sema/attr-naked.cpp

Index: include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -7174,6 +7174,8 @@
 
 def err_non_asm_stmt_in_naked_function : Error<
   "non-ASM statement in naked function is not supported">;
+def err_non_static_naked_member_function : Error<
+  "non-static naked class member function is not supported">;
 def err_asm_naked_parm_ref : Error<
   "parameter references not allowed in naked functions">;
 
Index: lib/Sema/SemaStmtAsm.cpp
===================================================================
--- lib/Sema/SemaStmtAsm.cpp
+++ lib/Sema/SemaStmtAsm.cpp
@@ -81,7 +81,11 @@
     return false;
   if (!Func->hasAttr<NakedAttr>())
     return false;
-
+  if (isa<CXXMethodDecl>(Func) && cast<CXXMethodDecl>(Func)->isInstance()) {
+    S.Diag(Func->getLocStart(), diag::err_non_static_naked_member_function);
+    S.Diag(Func->getAttr<NakedAttr>()->getLocation(), diag::note_attribute);
+    return true;
+  }
   SmallVector<Expr*, 4> WorkList;
   WorkList.push_back(E);
   while (WorkList.size()) {
Index: test/Sema/attr-naked.cpp
===================================================================
--- /dev/null
+++ test/Sema/attr-naked.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only -triple arm-none-linux
+class Foo {
+  unsigned reg;
+  void bar();
+  static void bar2();
+};
+
+unsigned x;
+
+void __attribute__((naked)) Foo::bar() { // expected-error{{non-static naked 
class member function is not supported}} expected-note{{attribute is here}}
+  asm("mov r2, %0" : : "r"(reg));
+}
+
+void __attribute__((naked)) Foo::bar2() { // static  function is OK
+  asm("mov r2, %0" : : "r"(x));
+}
+
+

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
Index: include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -7174,6 +7174,8 @@
 
 def err_non_asm_stmt_in_naked_function : Error<
   "non-ASM statement in naked function is not supported">;
+def err_non_static_naked_member_function : Error<
+  "non-static naked class member function is not supported">;
 def err_asm_naked_parm_ref : Error<
   "parameter references not allowed in naked functions">;
 
Index: lib/Sema/SemaStmtAsm.cpp
===================================================================
--- lib/Sema/SemaStmtAsm.cpp
+++ lib/Sema/SemaStmtAsm.cpp
@@ -81,7 +81,11 @@
     return false;
   if (!Func->hasAttr<NakedAttr>())
     return false;
-
+  if (isa<CXXMethodDecl>(Func) && cast<CXXMethodDecl>(Func)->isInstance()) {
+    S.Diag(Func->getLocStart(), diag::err_non_static_naked_member_function);
+    S.Diag(Func->getAttr<NakedAttr>()->getLocation(), diag::note_attribute);
+    return true;
+  }
   SmallVector<Expr*, 4> WorkList;
   WorkList.push_back(E);
   while (WorkList.size()) {
Index: test/Sema/attr-naked.cpp
===================================================================
--- /dev/null
+++ test/Sema/attr-naked.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 %s -verify -fsyntax-only -triple arm-none-linux
+class Foo {
+  unsigned reg;
+  void bar();
+  static void bar2();
+};
+
+unsigned x;
+
+void __attribute__((naked)) Foo::bar() { // expected-error{{non-static naked class member function is not supported}} expected-note{{attribute is here}}
+  asm("mov r2, %0" : : "r"(reg));
+}
+
+void __attribute__((naked)) Foo::bar2() { // static  function is OK
+  asm("mov r2, %0" : : "r"(x));
+}
+
+
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to