Diagnose use of a naked attribute on a member function in ms-mode

This matches the behavior of cl.exe.
This commit is contained in:
Aaron Ballman 2022-03-24 11:51:31 -04:00
parent 0c86198b27
commit 5b164a3a9b
3 changed files with 22 additions and 0 deletions

View File

@ -131,6 +131,9 @@ Attribute Changes in Clang
- ``#pragma clang attribute push`` now supports multiple attributes within a single directive.
- The ``__declspec(naked)`` attribute can no longer be written on a member
function in Microsoft compatibility mode, matching the behavior of cl.exe.
Windows Support
---------------

View File

@ -2158,6 +2158,14 @@ static void handleNakedAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
<< AL << Triple.getArchName();
return;
}
// This form is not allowed to be written on a member function (static or
// nonstatic) when in Microsoft compatibility mode.
if (S.getLangOpts().MSVCCompat && isa<CXXMethodDecl>(D)) {
S.Diag(AL.getLoc(), diag::err_attribute_wrong_decl_type_str)
<< AL << "non-member functions";
return;
}
}
D->addAttr(::new (S.Context) NakedAttr(S.Context, AL));

View File

@ -1,4 +1,6 @@
// RUN: %clang_cc1 %s -verify -fsyntax-only -triple arm-none-linux
// RUN: %clang_cc1 %s -verify -fsyntax-only -fms-compatibility -DDECLSPEC -triple i686-pc-win32
class Foo {
void bar();
static void bar2();
@ -13,3 +15,12 @@ void __attribute__((naked)) Foo::bar() { // expected-note{{attribute is here}}
void __attribute__((naked)) Foo::bar2() {
asm("mov r2, %0" : : "r"(s)); // static member reference is OK
}
struct Bar {
#ifdef DECLSPEC
__declspec(naked) void func1(); // expected-error {{'naked' attribute only applies to non-member functions}}
__declspec(naked) static void func2(); // expected-error {{'naked' attribute only applies to non-member functions}}
#endif
__attribute__((naked)) void func3(); // OK
__attribute__((naked)) static void func4(); // OK
};