[Clang] noinline stmt attribute - emit warnings rather than errors

Compatible behaviour with always_inline stmt attribute
This commit is contained in:
Dávid Bolvanský 2022-03-14 23:39:52 +01:00
parent 33f9fc77d1
commit 56e7d6bd44
5 changed files with 6 additions and 7 deletions

View File

@ -1770,7 +1770,7 @@ def NoInline : DeclOrStmtAttr {
let Accessors = [Accessor<"isClangNoInline", [CXX11<"clang", "noinline">,
C2x<"clang", "noinline">]>];
let Documentation = [NoInlineDocs];
let Subjects = SubjectList<[Function, Stmt], ErrorDiag,
let Subjects = SubjectList<[Function, Stmt], WarnDiag,
"functions and statements">;
let SimpleHandler = 1;
}

View File

@ -217,14 +217,13 @@ static Attr *handleNoMergeAttr(Sema &S, Stmt *St, const ParsedAttr &A,
static Attr *handleNoInlineAttr(Sema &S, Stmt *St, const ParsedAttr &A,
SourceRange Range) {
NoInlineAttr NIA(S.Context, A);
CallExprFinder CEF(S, St);
if (!NIA.isClangNoInline()) {
S.Diag(St->getBeginLoc(), diag::warn_function_attribute_ignored_in_stmt)
<< "[[clang::noinline]]";
return nullptr;
}
CallExprFinder CEF(S, St);
if (!CEF.foundCallExpr()) {
S.Diag(St->getBeginLoc(), diag::warn_attribute_ignored_no_calls_in_stmt)
<< A;

View File

@ -45,7 +45,7 @@ void foo(int i) {
}
__attribute__((fastcall)) goto there; // expected-error {{'fastcall' attribute cannot be applied to a statement}}
__attribute__((noinline)) there : // expected-error {{'noinline' attribute only applies to functions and statements}}
__attribute__((noinline)) there : // expected-warning {{'noinline' attribute only applies to functions and statements}}
__attribute__((weakref)) return; // expected-error {{'weakref' attribute only applies to variables and functions}}

View File

@ -1,6 +1,6 @@
// RUN: %clang_cc1 %s -verify -fsyntax-only
int a __attribute__((noinline)); // expected-error {{'noinline' attribute only applies to functions and statements}}
int a __attribute__((noinline)); // expected-warning {{'noinline' attribute only applies to functions and statements}}
void t1(void) __attribute__((noinline));

View File

@ -13,7 +13,7 @@ void foo() {
int x;
[[clang::noinline]] x = 0; // expected-warning {{'noinline' attribute is ignored because there exists no call expression inside the statement}}
[[clang::noinline]] { asm("nop"); } // expected-warning {{'noinline' attribute is ignored because there exists no call expression inside the statement}}
[[clang::noinline]] label: x = 1; // expected-error {{'noinline' attribute only applies to functions and statements}}
[[clang::noinline]] label: x = 1; // expected-warning {{'noinline' attribute only applies to functions and statements}}
[[clang::noinline]] always_inline_fn(); // expected-warning {{statement attribute 'noinline' has higher precedence than function attribute 'always_inline'}}
@ -24,4 +24,4 @@ void foo() {
__attribute__((noinline)) bar(); // expected-warning {{attribute is ignored on this statement as it only applies to functions; use '[[clang::noinline]]' on statements}}
}
[[clang::noinline]] static int i = bar(); // expected-error {{'noinline' attribute only applies to functions and statements}}
[[clang::noinline]] static int i = bar(); // expected-warning {{'noinline' attribute only applies to functions and statements}}