[clang] d8352ab - Diagnose use of _Noreturn on a struct/union field
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 29 10:18:51 PDT 2022
Author: Aaron Ballman
Date: 2022-07-29T13:18:44-04:00
New Revision: d8352abd3a4f411828dbe46c7dfd3e935ab4dd4a
URL: https://github.com/llvm/llvm-project/commit/d8352abd3a4f411828dbe46c7dfd3e935ab4dd4a
DIFF: https://github.com/llvm/llvm-project/commit/d8352abd3a4f411828dbe46c7dfd3e935ab4dd4a.diff
LOG: Diagnose use of _Noreturn on a struct/union field
C99 6.7.4p2 clarifies that a function specifier can only be used in the
declaration of a function. _Noreturn is a function specifier, so it is
a constraint violation to write it on a structure or union field, but
we missed that case.
Fixes #56800
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Parse/ParseDecl.cpp
clang/test/Parser/c11-noreturn.c
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 871c434d67ee3..3d72bf8f6521c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -52,7 +52,9 @@ Bug Fixes
- ``-Wtautological-compare`` missed warnings for tautological comparisons
involving a negative integer literal. This fixes
`Issue 42918 <https://github.com/llvm/llvm-project/issues/42918>`_.
-
+- Fixes an accepts-invalid bug in C when using a ``_Noreturn`` function
+ specifier on something other than a function declaration. This fixes
+ `Issue 56800 <https://github.com/llvm/llvm-project/issues/56800>`_.
Improvements to Clang's diagnostics
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index aef9909a7c971..fa19c6a0cbfa4 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -2599,6 +2599,8 @@ void Parser::ParseSpecifierQualifierList(DeclSpec &DS, AccessSpecifier AS,
Diag(DS.getVirtualSpecLoc(), diag::err_typename_invalid_functionspec);
if (DS.hasExplicitSpecifier())
Diag(DS.getExplicitSpecLoc(), diag::err_typename_invalid_functionspec);
+ if (DS.isNoreturnSpecified())
+ Diag(DS.getNoreturnSpecLoc(), diag::err_typename_invalid_functionspec);
DS.ClearFunctionSpecs();
}
diff --git a/clang/test/Parser/c11-noreturn.c b/clang/test/Parser/c11-noreturn.c
index 0ce883ea43e36..5562a9412b5a7 100644
--- a/clang/test/Parser/c11-noreturn.c
+++ b/clang/test/Parser/c11-noreturn.c
@@ -15,4 +15,15 @@ _Noreturn int; // expected-error {{'_Noreturn' can only appear on functions}} ex
_Noreturn struct S; // expected-error {{'_Noreturn' can only appear on functions}}
_Noreturn enum E { e }; // expected-error {{'_Noreturn' can only appear on functions}}
+struct GH56800 {
+ _Noreturn int f1; // expected-error {{type name does not allow function specifier to be specified}}
+};
+
+_Noreturn int AlsoBad; // expected-error {{'_Noreturn' can only appear on functions}}
+void func(_Noreturn int ThisToo) { // expected-error {{'_Noreturn' can only appear on functions}}
+ for (_Noreturn int i = 0; i < 10; ++i) // expected-error {{'_Noreturn' can only appear on functions}}
+ ;
+}
+
+
// CHECK-EXT: '_Noreturn' is a C11 extension
More information about the cfe-commits
mailing list