[clang] [C11] Diagnose C11 keywords as being incompatible w/earlier standards (PR #82015)
https://github.com/AaronBallman closed https://github.com/llvm/llvm-project/pull/82015 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C11] Diagnose C11 keywords as being incompatible w/earlier standards (PR #82015)
https://github.com/erichkeane approved this pull request. https://github.com/llvm/llvm-project/pull/82015 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C11] Diagnose C11 keywords as being incompatible w/earlier standards (PR #82015)
@@ -2742,6 +2742,19 @@ bool Parser::parseMisplacedModuleImport() { return false; } +void Parser::diagnoseUseOfC11Keyword(const Token& Tok) { + // Warn that this is a C11 extension if in an older mode or if in C++. + // Otherwise, warn that it is incompatible with standards before C11 if in + // C11 or later. + unsigned DiagId; + if (!getLangOpts().C11) { +DiagId = diag::ext_c11_feature; + } else { +DiagId = diag::warn_c11_compat_keyword; + } + Diag(Tok, DiagId) << Tok.getName(); AaronBallman wrote: Done https://github.com/llvm/llvm-project/pull/82015 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C11] Diagnose C11 keywords as being incompatible w/earlier standards (PR #82015)
https://github.com/AaronBallman edited https://github.com/llvm/llvm-project/pull/82015 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C11] Diagnose C11 keywords as being incompatible w/earlier standards (PR #82015)
@@ -2742,6 +2742,19 @@ bool Parser::parseMisplacedModuleImport() { return false; } +void Parser::diagnoseUseOfC11Keyword(const Token& Tok) { + // Warn that this is a C11 extension if in an older mode or if in C++. + // Otherwise, warn that it is incompatible with standards before C11 if in + // C11 or later. + unsigned DiagId; + if (!getLangOpts().C11) { AaronBallman wrote: Done https://github.com/llvm/llvm-project/pull/82015 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C11] Diagnose C11 keywords as being incompatible w/earlier standards (PR #82015)
https://github.com/AaronBallman commented: Made both changes (thanks) and moved the test file to a more appropriate location. https://github.com/llvm/llvm-project/pull/82015 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C11] Diagnose C11 keywords as being incompatible w/earlier standards (PR #82015)
@@ -2742,6 +2742,19 @@ bool Parser::parseMisplacedModuleImport() { return false; } +void Parser::diagnoseUseOfC11Keyword(const Token& Tok) { + // Warn that this is a C11 extension if in an older mode or if in C++. + // Otherwise, warn that it is incompatible with standards before C11 if in + // C11 or later. + unsigned DiagId; + if (!getLangOpts().C11) { +DiagId = diag::ext_c11_feature; + } else { +DiagId = diag::warn_c11_compat_keyword; + } + Diag(Tok, DiagId) << Tok.getName(); AaronBallman wrote: Yeah, I had originally structured it this way because I thought we might want to give a different diagnostic in C++ mode (where we call these C11 extensions), but then I realized that diagnostic is reasonable as-is. I'll change. https://github.com/llvm/llvm-project/pull/82015 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C11] Diagnose C11 keywords as being incompatible w/earlier standards (PR #82015)
@@ -2742,6 +2742,19 @@ bool Parser::parseMisplacedModuleImport() { return false; } +void Parser::diagnoseUseOfC11Keyword(const Token& Tok) { + // Warn that this is a C11 extension if in an older mode or if in C++. + // Otherwise, warn that it is incompatible with standards before C11 if in + // C11 or later. + unsigned DiagId; + if (!getLangOpts().C11) { +DiagId = diag::ext_c11_feature; + } else { +DiagId = diag::warn_c11_compat_keyword; + } + Diag(Tok, DiagId) << Tok.getName(); erichkeane wrote: I dont think it is worth the DiagId pattern here, I think just a Diag + Ternary is probably fine. https://github.com/llvm/llvm-project/pull/82015 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C11] Diagnose C11 keywords as being incompatible w/earlier standards (PR #82015)
@@ -2742,6 +2742,19 @@ bool Parser::parseMisplacedModuleImport() { return false; } +void Parser::diagnoseUseOfC11Keyword(const Token& Tok) { + // Warn that this is a C11 extension if in an older mode or if in C++. + // Otherwise, warn that it is incompatible with standards before C11 if in + // C11 or later. + unsigned DiagId; + if (!getLangOpts().C11) { erichkeane wrote: Don't use curleys on 1 liners https://github.com/llvm/llvm-project/pull/82015 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C11] Diagnose C11 keywords as being incompatible w/earlier standards (PR #82015)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff f55b79f59a77b4be586d649e9ced9f8667265011 6bce3bc879072a915c6c77b2a3d9d96d60d568ee -- clang/test/Sema/c11-keywords.c clang/include/clang/Parse/Parser.h clang/lib/Parse/ParseDecl.cpp clang/lib/Parse/ParseDeclCXX.cpp clang/lib/Parse/ParseExpr.cpp clang/lib/Parse/Parser.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index abc06468fc..c5a18e4bd7 100644 --- a/clang/lib/Parse/Parser.cpp +++ b/clang/lib/Parse/Parser.cpp @@ -2742,7 +2742,7 @@ bool Parser::parseMisplacedModuleImport() { return false; } -void Parser::diagnoseUseOfC11Keyword(const Token& Tok) { +void Parser::diagnoseUseOfC11Keyword(const Token ) { // Warn that this is a C11 extension if in an older mode or if in C++. // Otherwise, warn that it is incompatible with standards before C11 if in // C11 or later. `` https://github.com/llvm/llvm-project/pull/82015 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [C11] Diagnose C11 keywords as being incompatible w/earlier standards (PR #82015)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Aaron Ballman (AaronBallman) Changes Our usual pattern when issuing an extension warning is to also issue a default-off diagnostic about the keywords not being compatible with standards before a certain point. This adds those diagnostics for C11 keywords. --- Full diff: https://github.com/llvm/llvm-project/pull/82015.diff 9 Files Affected: - (modified) clang/docs/ReleaseNotes.rst (+3) - (modified) clang/include/clang/Basic/DiagnosticGroups.td (+3) - (modified) clang/include/clang/Basic/DiagnosticParseKinds.td (+3) - (modified) clang/include/clang/Parse/Parser.h (+2) - (modified) clang/lib/Parse/ParseDecl.cpp (+5-11) - (modified) clang/lib/Parse/ParseDeclCXX.cpp (+3-3) - (modified) clang/lib/Parse/ParseExpr.cpp (+3-4) - (modified) clang/lib/Parse/Parser.cpp (+13) - (added) clang/test/Sema/c11-keywords.c (+37) ``diff diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 16f79a349c20c8..06c7d57d73ca70 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -185,6 +185,9 @@ Improvements to Clang's diagnostics - Clang now diagnoses friend declarations with an ``enum`` elaborated-type-specifier in language modes after C++98. +- Added diagnostics for C11 keywords being incompatible with language standards + before C11, under a new warning group: ``-Wpre-c11-compat``. + Improvements to Clang's time-trace -- diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 7679b8528a4197..e8b4139d7893ce 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -290,6 +290,9 @@ def : DiagGroup<"c++1z-compat-mangling", [CXX17CompatMangling]>; def NoexceptType : DiagGroup<"noexcept-type", [CXX17CompatMangling]>; // Warnings for C code which is not compatible with previous C standards. +def CPre11Compat : DiagGroup<"pre-c11-compat">; +def CPre11CompatPedantic : DiagGroup<"pre-c11-compat-pedantic", + [CPre11Compat]>; def CPre23Compat : DiagGroup<"pre-c23-compat">; def CPre23CompatPedantic : DiagGroup<"pre-c23-compat-pedantic", [CPre23Compat]>; diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td index 11b490a0928e60..c0dbc25a0c3265 100644 --- a/clang/include/clang/Basic/DiagnosticParseKinds.td +++ b/clang/include/clang/Basic/DiagnosticParseKinds.td @@ -165,6 +165,9 @@ def ext_c99_feature : Extension< "'%0' is a C99 extension">, InGroup; def ext_c11_feature : Extension< "'%0' is a C11 extension">, InGroup; +def warn_c11_compat_keyword : Warning< + "'%0' is incompatible with C standards before C11">, + InGroup, DefaultIgnore; def warn_c23_compat_keyword : Warning< "'%0' is incompatible with C standards before C23">, InGroup, DefaultIgnore; diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index 69b9e837fe8bef..071520f535bc95 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -1122,6 +1122,8 @@ class Parser : public CodeCompletionHandler { void checkCompoundToken(SourceLocation FirstTokLoc, tok::TokenKind FirstTokKind, CompoundToken Op); + void diagnoseUseOfC11Keyword(const Token ); + public: //======// // Scope manipulation diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 9640d7ee70d27f..0728113ba7c936 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -3520,8 +3520,7 @@ void Parser::ParseDeclarationSpecifiers( // alignment-specifier case tok::kw__Alignas: - if (!getLangOpts().C11) -Diag(Tok, diag::ext_c11_feature) << Tok.getName(); + diagnoseUseOfC11Keyword(Tok); [[fallthrough]]; case tok::kw_alignas: // _Alignas and alignas (C23, not C++) should parse the same way. The C++ @@ -4184,8 +4183,7 @@ void Parser::ParseDeclarationSpecifiers( isStorageClass = true; break; case tok::kw__Thread_local: - if (!getLangOpts().C11) -Diag(Tok, diag::ext_c11_feature) << Tok.getName(); + diagnoseUseOfC11Keyword(Tok); isInvalid = DS.SetStorageClassSpecThread(DeclSpec::TSCS__Thread_local, Loc, PrevSpec, DiagID); isStorageClass = true; @@ -4245,8 +4243,7 @@ void Parser::ParseDeclarationSpecifiers( break; } case tok::kw__Noreturn: - if (!getLangOpts().C11) -Diag(Tok, diag::ext_c11_feature) << Tok.getName(); + diagnoseUseOfC11Keyword(Tok); isInvalid = DS.setFunctionSpecNoreturn(Loc, PrevSpec, DiagID); break; @@ -4576,9 +4573,7 @@ void Parser::ParseDeclarationSpecifiers(