[clang] efefee2 - [C2y] Modify diagnostics for generic selection with a type operand

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 2 05:19:24 PDT 2024


Author: Aaron Ballman
Date: 2024-07-02T08:19:07-04:00
New Revision: efefee28a41ec323f74ee481cce8b620b49ecf84

URL: https://github.com/llvm/llvm-project/commit/efefee28a41ec323f74ee481cce8b620b49ecf84
DIFF: https://github.com/llvm/llvm-project/commit/efefee28a41ec323f74ee481cce8b620b49ecf84.diff

LOG: [C2y] Modify diagnostics for generic selection with a type operand

We implemented WG14 N3260 as an extension, now it's a feature of C2y.

Added: 
    clang/test/C/C2y/n3260.c

Modified: 
    clang/include/clang/Basic/DiagnosticGroups.td
    clang/include/clang/Basic/DiagnosticParseKinds.td
    clang/lib/Parse/ParseExpr.cpp
    clang/test/Parser/generic-selection-type-extension-pedantic.c

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td
index 74deb92c94c7a..9431eea1f6be2 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -299,6 +299,10 @@ def CPre23CompatPedantic : DiagGroup<"pre-c23-compat-pedantic",
 def : DiagGroup<"pre-c2x-compat", [CPre23Compat]>;
 def : DiagGroup<"pre-c2x-compat-pedantic", [CPre23CompatPedantic]>;
 
+def CPre2yCompat : DiagGroup<"pre-c2y-compat">;
+def CPre2yCompatPedantic : DiagGroup<"pre-c2y-compat-pedantic",
+                                     [CPre2yCompat]>;
+
 // Warnings for C++ code which is not compatible with previous C++ standards.
 def CXXPre14Compat : DiagGroup<"pre-c++14-compat">;
 def : DiagGroup<"c++98-c++11-compat", [CXXPre14Compat]>;
@@ -1197,6 +1201,9 @@ def C23 : DiagGroup<"c23-extensions">;
 
 def : DiagGroup<"c2x-extensions", [C23]>;
 
+// A warning group for warnings about using C2y features as extensions.
+def C2y : DiagGroup<"c2y-extensions">;
+
 // Previously supported warning group which is no longer pertinent as binary
 // literals are a C++14 and C23 extension now instead of a GNU extension.
 def GNUBinaryLiteral : DiagGroup<"gnu-binary-literal">;

diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 1160b0f7a7a5a..12aab09f28556 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -157,9 +157,12 @@ def err_duplicate_default_assoc : Error<
   "duplicate default generic association">;
 def note_previous_default_assoc : Note<
   "previous default generic association is here">;
-def ext_generic_with_type_arg : Extension<
-  "passing a type argument as the first operand to '_Generic' is a Clang "
-  "extension">, InGroup<DiagGroup<"generic-type-extension">>;
+def ext_c2y_generic_with_type_arg : Extension<
+  "passing a type argument as the first operand to '_Generic' is a C2y "
+  "extension">, InGroup<C2y>;
+def warn_c2y_compat_generic_with_type_arg : Warning<
+  "passing a type argument as the first operand to '_Generic' is incompatible "
+  "with C standards before C2y">, InGroup<CPre2yCompat>, DefaultIgnore;
 
 def ext_c99_feature : Extension<
   "'%0' is a C99 extension">, InGroup<C99>;

diff  --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 9fc3cd73f73a0..2dd2e1b83548b 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -3449,7 +3449,8 @@ ExprResult Parser::ParseGenericSelectionExpression() {
     }
     const auto *LIT = cast<LocInfoType>(ControllingType.get().get());
     SourceLocation Loc = LIT->getTypeSourceInfo()->getTypeLoc().getBeginLoc();
-    Diag(Loc, diag::ext_generic_with_type_arg);
+    Diag(Loc, getLangOpts().C2y ? diag::warn_c2y_compat_generic_with_type_arg
+                                : diag::ext_c2y_generic_with_type_arg);
   } else {
     // C11 6.5.1.1p3 "The controlling expression of a generic selection is
     // not evaluated."

diff  --git a/clang/test/C/C2y/n3260.c b/clang/test/C/C2y/n3260.c
new file mode 100644
index 0000000000000..e7b0eef0e02c3
--- /dev/null
+++ b/clang/test/C/C2y/n3260.c
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -verify -std=c2y -Wall -pedantic -Wpre-c2y-compat %s
+// RUN: %clang_cc1 -verify=pre-c2y -std=c23 -Wall -pedantic %s
+
+/* WG14 N3260: Clang 17
+ * Generic selection expression with a type operand
+ */
+
+static_assert(
+  _Generic(
+    const int, /* pre-c2y-warning {{passing a type argument as the first operand to '_Generic' is a C2y extension}}
+                  expected-warning {{passing a type argument as the first operand to '_Generic' is incompatible with C standards before C2y}}
+                */
+    int : 0,
+    const int : 1
+  )
+);

diff  --git a/clang/test/Parser/generic-selection-type-extension-pedantic.c b/clang/test/Parser/generic-selection-type-extension-pedantic.c
index d73e80933e23e..e611703151aa6 100644
--- a/clang/test/Parser/generic-selection-type-extension-pedantic.c
+++ b/clang/test/Parser/generic-selection-type-extension-pedantic.c
@@ -4,7 +4,7 @@
 // in the right location.
 void test(void) {
   (void)_Generic(
-	  int,  // expected-warning {{passing a type argument as the first operand to '_Generic' is a Clang extension}}
+	  int,  // expected-warning {{passing a type argument as the first operand to '_Generic' is a C2y extension}}
 	  int : 0);
   (void)_Generic(
 	  12,


        


More information about the cfe-commits mailing list