Author: Dávid Bolvanský Date: 2022-03-14T23:40:17+01:00 New Revision: 56e7d6bd444cef8d879adc35dcf461cb4d2ed6d5
URL: https://github.com/llvm/llvm-project/commit/56e7d6bd444cef8d879adc35dcf461cb4d2ed6d5 DIFF: https://github.com/llvm/llvm-project/commit/56e7d6bd444cef8d879adc35dcf461cb4d2ed6d5.diff LOG: [Clang] noinline stmt attribute - emit warnings rather than errors Compatible behaviour with always_inline stmt attribute Added: Modified: clang/include/clang/Basic/Attr.td clang/lib/Sema/SemaStmtAttr.cpp clang/test/Parser/stmt-attributes.c clang/test/Sema/attr-noinline.c clang/test/Sema/attr-noinline.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index e28044646080e..a35b2fcbc4fb5 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -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; } diff --git a/clang/lib/Sema/SemaStmtAttr.cpp b/clang/lib/Sema/SemaStmtAttr.cpp index ebb10da9ab6ea..02776278827c0 100644 --- a/clang/lib/Sema/SemaStmtAttr.cpp +++ b/clang/lib/Sema/SemaStmtAttr.cpp @@ -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; diff --git a/clang/test/Parser/stmt-attributes.c b/clang/test/Parser/stmt-attributes.c index 4a8c2c1d2a74d..ccd206e70a225 100644 --- a/clang/test/Parser/stmt-attributes.c +++ b/clang/test/Parser/stmt-attributes.c @@ -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}} diff --git a/clang/test/Sema/attr-noinline.c b/clang/test/Sema/attr-noinline.c index 065e8fad716aa..2a3532df4b34b 100644 --- a/clang/test/Sema/attr-noinline.c +++ b/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)); diff --git a/clang/test/Sema/attr-noinline.cpp b/clang/test/Sema/attr-noinline.cpp index 97c894a3f2f0c..d35782f11adbb 100644 --- a/clang/test/Sema/attr-noinline.cpp +++ b/clang/test/Sema/attr-noinline.cpp @@ -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}} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits