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()) return false; - + if (isa(Func) && cast(Func)->isInstance()) { + S.Diag(Func->getLocStart(), diag::err_non_static_naked_member_function); + S.Diag(Func->getAttr()->getLocation(), diag::note_attribute); + return true; + } SmallVector 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)); +} + +