Skip to content

Commit

Permalink
[Clang] noinline stmt attribute - emit warnings rather than errors
Browse files Browse the repository at this point in the history
Compatible behaviour with always_inline stmt attribute
  • Loading branch information
davidbolvansky committed Mar 14, 2022
1 parent 33f9fc7 commit 56e7d6b
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion clang/include/clang/Basic/Attr.td
Expand Up @@ -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;
}
Expand Down
3 changes: 1 addition & 2 deletions clang/lib/Sema/SemaStmtAttr.cpp
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Parser/stmt-attributes.c
Expand Up @@ -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}}

Expand Down
2 changes: 1 addition & 1 deletion clang/test/Sema/attr-noinline.c
@@ -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));

Expand Down
4 changes: 2 additions & 2 deletions clang/test/Sema/attr-noinline.cpp
Expand Up @@ -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'}}
Expand All @@ -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}}

0 comments on commit 56e7d6b

Please sign in to comment.