Author: Aaron Ballman
Date: 2024-07-02T07:00:19-04:00
New Revision: b67d557bd3627a428d5041edec129587d6d3972c

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

LOG: [C2y] Add -std=c2y and -std=gnu2y

This adds a language standard mode for the latest C standard. While
WG14 is hoping for a three-year cycle, it is not clear that the next
revision of C will be in 2026 and so a flag was not created for c26
specifically.

Added: 
    

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/docs/UsersManual.rst
    clang/include/clang/Basic/LangOptions.def
    clang/include/clang/Basic/LangStandard.h
    clang/include/clang/Basic/LangStandards.def
    clang/lib/Basic/LangOptions.cpp
    clang/lib/Frontend/InitPreprocessor.cpp
    clang/test/Driver/unknown-std.c
    clang/www/c_status.html

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index fd8d9ad34fb10..e4707bf15bb6c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -320,6 +320,12 @@ Resolutions to C++ Defect Reports
 C Language Changes
 ------------------
 
+C2y Feature Support
+^^^^^^^^^^^^^^^^^^^
+- Clang now enables C2y mode with ``-std=c2y``. This sets ``__STDC_VERSION__``
+  to ``202400L`` so that it's greater than the value for C23. The value of this
+  macro is subject to change in the future.
+
 C23 Feature Support
 ^^^^^^^^^^^^^^^^^^^
 - No longer diagnose use of binary literals as an extension in C23 mode. Fixes

diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index d273102fe9000..087c75bc39a16 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -3458,9 +3458,9 @@ Differences between various standard modes
 
 clang supports the -std option, which changes what language mode clang uses.
 The supported modes for C are c89, gnu89, c94, c99, gnu99, c11, gnu11, c17,
-gnu17, c23, gnu23, and various aliases for those modes. If no -std option is
-specified, clang defaults to gnu17 mode. Many C99 and C11 features are
-supported in earlier modes as a conforming extension, with a warning. Use
+gnu17, c23, gnu23, c2y, gnu2y, and various aliases for those modes. If no -std
+option is specified, clang defaults to gnu17 mode. Many C99 and C11 features
+are supported in earlier modes as a conforming extension, with a warning. Use
 ``-pedantic-errors`` to request an error if a feature from a later standard
 revision is used in an earlier mode.
 
@@ -3523,6 +3523,10 @@ Differences between ``*17`` and ``*23`` modes:
 - ``[[]]`` attributes are supported by default in ``*23`` mode, and as an
   extension in ``*17`` and earlier modes.
 
+Differences between ``*23`` and ``*2y`` modes:
+
+- ``__STDC_VERSION__`` is defined to ``202400L`` rather than ``202311L``.
+
 GCC extensions not implemented yet
 ----------------------------------
 

diff  --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 6dd6b5614f44c..491759e2fcdbb 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -87,6 +87,7 @@ LANGOPT(C99               , 1, 0, "C99")
 LANGOPT(C11               , 1, 0, "C11")
 LANGOPT(C17               , 1, 0, "C17")
 LANGOPT(C23               , 1, 0, "C23")
+LANGOPT(C2y               , 1, 0, "C2y")
 LANGOPT(MSVCCompat        , 1, 0, "Microsoft Visual C++ full compatibility 
mode")
 LANGOPT(Kernel            , 1, 0, "Kernel mode")
 LANGOPT(MicrosoftExt      , 1, 0, "Microsoft C++ extensions")

diff  --git a/clang/include/clang/Basic/LangStandard.h 
b/clang/include/clang/Basic/LangStandard.h
index 8e25afc833661..f79b4aafb0b26 100644
--- a/clang/include/clang/Basic/LangStandard.h
+++ b/clang/include/clang/Basic/LangStandard.h
@@ -52,18 +52,19 @@ enum LangFeatures {
   C11 = (1 << 2),
   C17 = (1 << 3),
   C23 = (1 << 4),
-  CPlusPlus = (1 << 5),
-  CPlusPlus11 = (1 << 6),
-  CPlusPlus14 = (1 << 7),
-  CPlusPlus17 = (1 << 8),
-  CPlusPlus20 = (1 << 9),
-  CPlusPlus23 = (1 << 10),
-  CPlusPlus26 = (1 << 11),
-  Digraphs = (1 << 12),
-  GNUMode = (1 << 13),
-  HexFloat = (1 << 14),
-  OpenCL = (1 << 15),
-  HLSL = (1 << 16)
+  C2y = (1 << 5),
+  CPlusPlus = (1 << 6),
+  CPlusPlus11 = (1 << 7),
+  CPlusPlus14 = (1 << 8),
+  CPlusPlus17 = (1 << 9),
+  CPlusPlus20 = (1 << 10),
+  CPlusPlus23 = (1 << 11),
+  CPlusPlus26 = (1 << 12),
+  Digraphs = (1 << 13),
+  GNUMode = (1 << 14),
+  HexFloat = (1 << 15),
+  OpenCL = (1 << 16),
+  HLSL = (1 << 17)
 };
 
 /// LangStandard - Information about the properties of a particular language
@@ -106,6 +107,9 @@ struct LangStandard {
   /// isC23 - Language is a superset of C23.
   bool isC23() const { return Flags & C23; }
 
+  /// isC2y - Language is a superset of C2y.
+  bool isC2y() const { return Flags & C2y; }
+
   /// isCPlusPlus - Language is a C++ variant.
   bool isCPlusPlus() const { return Flags & CPlusPlus; }
 

diff  --git a/clang/include/clang/Basic/LangStandards.def 
b/clang/include/clang/Basic/LangStandards.def
index b6192e48efc11..f0c259307ac4e 100644
--- a/clang/include/clang/Basic/LangStandards.def
+++ b/clang/include/clang/Basic/LangStandards.def
@@ -99,6 +99,15 @@ LANGSTANDARD_ALIAS_DEPR(gnu23, "gnu2x")
 // FIXME: Add the alias for iso9899:202* once we know the year ISO publishes
 // the document (expected to be 2024).
 
+// C2y modes
+LANGSTANDARD(c2y, "c2y",
+             C, "Working Draft for ISO C2y",
+             LineComment | C99 | C11 | C17 | C23 | C2y | Digraphs | HexFloat)
+LANGSTANDARD(gnu2y, "gnu2y",
+             C, "Working Draft for ISO C2y with GNU extensions",
+             LineComment | C99 | C11 | C17 | C23 | C2y | Digraphs | GNUMode | 
HexFloat)
+
+
 // C++ modes
 LANGSTANDARD(cxx98, "c++98",
              CXX, "ISO C++ 1998 with amendments",

diff  --git a/clang/lib/Basic/LangOptions.cpp b/clang/lib/Basic/LangOptions.cpp
index 2b906463931d3..61072b7b81bff 100644
--- a/clang/lib/Basic/LangOptions.cpp
+++ b/clang/lib/Basic/LangOptions.cpp
@@ -112,6 +112,7 @@ void LangOptions::setLangDefaults(LangOptions &Opts, 
Language Lang,
   Opts.C11 = Std.isC11();
   Opts.C17 = Std.isC17();
   Opts.C23 = Std.isC23();
+  Opts.C2y = Std.isC2y();
   Opts.CPlusPlus = Std.isCPlusPlus();
   Opts.CPlusPlus11 = Std.isCPlusPlus11();
   Opts.CPlusPlus14 = Std.isCPlusPlus14();

diff  --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index 55ec460064830..5e52555c6fee9 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -448,7 +448,9 @@ static void InitializeStandardPredefinedMacros(const 
TargetInfo &TI,
   //      value is, are implementation-defined.
   // (Removed in C++20.)
   if (!LangOpts.CPlusPlus) {
-    if (LangOpts.C23)
+    if (LangOpts.C2y)
+      Builder.defineMacro("__STDC_VERSION__", "202400L");
+    else if (LangOpts.C23)
       Builder.defineMacro("__STDC_VERSION__", "202311L");
     else if (LangOpts.C17)
       Builder.defineMacro("__STDC_VERSION__", "201710L");

diff  --git a/clang/test/Driver/unknown-std.c b/clang/test/Driver/unknown-std.c
index 564c633c09bd9..8f9047b2230ad 100644
--- a/clang/test/Driver/unknown-std.c
+++ b/clang/test/Driver/unknown-std.c
@@ -18,6 +18,8 @@
 // CHECK-NEXT: note: use 'gnu17' or 'gnu18' for 'ISO C 2017 with GNU 
extensions' standard
 // CHECK-NEXT: note: use 'c23' for 'Working Draft for ISO C23' standard
 // CHECK-NEXT: note: use 'gnu23' for 'Working Draft for ISO C23 with GNU 
extensions' standard
+// CHECK-NEXT: note: use 'c2y' for 'Working Draft for ISO C2y' standard
+// CHECK-NEXT: note: use 'gnu2y' for 'Working Draft for ISO C2y with GNU 
extensions' standard
 
 // Make sure that no other output is present.
 // CHECK-NOT: {{^.+$}}

diff  --git a/clang/www/c_status.html b/clang/www/c_status.html
index 8e42b8138a2b5..ccb39a15b25aa 100644
--- a/clang/www/c_status.html
+++ b/clang/www/c_status.html
@@ -71,7 +71,7 @@ <h1>C Support in Clang</h1>
 </tr>
 <tr>
  <td><a href="#c2y">C2y</a></td>
- <td><tt>(Flag currently unavailable)</tt></td>
+ <td><tt>-std=c2y</tt></td>
  <td class="partial" align="center">Partial</td>
 </tr>
 </table>
@@ -1229,8 +1229,7 @@ <h2 id="c2y">C2y implementation status</h2>
 
 <p>Clang has support for some of the features of the C standard following C23, 
informally referred to as C2y.</p>
 
-<p>Clang currently does not expose a language standard mode flag for C2y.
-<!--You can use Clang in C2y mode with the <code>-std=c2y</code> option 
(available in Clang 19 and later).--></p>
+<p>You can use Clang in C2y mode with the <code>-std=c2y</code> option 
(available in Clang 19 and later).</p>
 
 <details open>
 <summary>List of features and minimum Clang version with support</summary>


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to