[PATCH] D23453: Add a c2x language mode

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 12 09:43:54 PDT 2016


aaron.ballman created this revision.
aaron.ballman added reviewers: rsmith, doug.gregor.
aaron.ballman added a subscriber: cfe-commits.

This patch adds support for a "c2x" language standard mode for the eventual new C language standard, expected to come out in 202x. The spelling and capitalization is pulled from the C2x charter (http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2021.htm).

I added a pretty simple driver test for this language mode because we do not currently have any C2x language features. However, I have a WIP patch that will require this functionality and figured that this part should be split off from it. If there is a better way to test this, or if it should wait for the WIP, please let me know.

https://reviews.llvm.org/D23453

Files:
  include/clang/Basic/LangOptions.def
  include/clang/Frontend/LangStandard.h
  include/clang/Frontend/LangStandards.def
  lib/Frontend/CompilerInvocation.cpp
  test/Driver/clang_std_c.c

Index: test/Driver/clang_std_c.c
===================================================================
--- test/Driver/clang_std_c.c
+++ test/Driver/clang_std_c.c
@@ -0,0 +1,7 @@
+/* Test various -std driver options for C. */
+// RUN: %clang -std=c11 -fsyntax-only %s 2>&1 | FileCheck %s
+// RUN: %clang -std=c2x -fsyntax-only %s 2>&1 | FileCheck %s
+
+// CHECK-NOT: invalid value 'c11' in '-std=c11'
+// CHECK-NOT: invalid value 'c2x' in '-std=c2x'
+
Index: lib/Frontend/CompilerInvocation.cpp
===================================================================
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -1535,6 +1535,7 @@
   Opts.LineComment = Std.hasLineComments();
   Opts.C99 = Std.isC99();
   Opts.C11 = Std.isC11();
+  Opts.C2x = Std.isC2x();
   Opts.CPlusPlus = Std.isCPlusPlus();
   Opts.CPlusPlus11 = Std.isCPlusPlus11();
   Opts.CPlusPlus14 = Std.isCPlusPlus14();
Index: include/clang/Frontend/LangStandards.def
===================================================================
--- include/clang/Frontend/LangStandards.def
+++ include/clang/Frontend/LangStandards.def
@@ -91,6 +91,11 @@
              "ISO C 2011 with GNU extensions",
              LineComment | C99 | C11 | Digraphs | GNUMode | HexFloat)
 
+// C2X modes
+LANGSTANDARD(c2x, "c2x",
+             "Working draft for ISO C 202x",
+             LineComment | C99 | C11 | C2x | Digraphs | HexFloat)
+
 // C++ modes
 LANGSTANDARD(cxx98, "c++98",
              "ISO C++ 1998 with amendments",
Index: include/clang/Frontend/LangStandard.h
===================================================================
--- include/clang/Frontend/LangStandard.h
+++ include/clang/Frontend/LangStandard.h
@@ -22,14 +22,15 @@
   C89 = (1 << 1),
   C99 = (1 << 2),
   C11 = (1 << 3),
-  CPlusPlus = (1 << 4),
-  CPlusPlus11 = (1 << 5),
-  CPlusPlus14 = (1 << 6),
-  CPlusPlus1z = (1 << 7),
-  Digraphs = (1 << 8),
-  GNUMode = (1 << 9),
-  HexFloat = (1 << 10),
-  ImplicitInt = (1 << 11)
+  C2x = (1 << 4),
+  CPlusPlus = (1 << 5),
+  CPlusPlus11 = (1 << 6),
+  CPlusPlus14 = (1 << 7),
+  CPlusPlus1z = (1 << 8),
+  Digraphs = (1 << 9),
+  GNUMode = (1 << 10),
+  HexFloat = (1 << 11),
+  ImplicitInt = (1 << 12)
 };
 
 }
@@ -67,6 +68,9 @@
   /// isC11 - Language is a superset of C11.
   bool isC11() const { return Flags & frontend::C11; }
 
+  /// isC2x - Language is a superset of C2x.
+  bool isC2x() const { return Flags & frontend::C2x; }
+
   /// isCPlusPlus - Language is a C++ variant.
   bool isCPlusPlus() const { return Flags & frontend::CPlusPlus; }
 
Index: include/clang/Basic/LangOptions.def
===================================================================
--- include/clang/Basic/LangOptions.def
+++ include/clang/Basic/LangOptions.def
@@ -82,6 +82,7 @@
 // FIXME: A lot of the BENIGN_ options should be COMPATIBLE_ instead.
 LANGOPT(C99               , 1, 0, "C99")
 LANGOPT(C11               , 1, 0, "C11")
+LANGOPT(C2x               , 1, 0, "C2x")
 LANGOPT(MSVCCompat        , 1, 0, "Microsoft Visual C++ full compatibility mode")
 LANGOPT(MicrosoftExt      , 1, 0, "Microsoft C++ extensions")
 LANGOPT(AsmBlocks         , 1, 0, "Microsoft inline asm blocks")


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23453.67848.patch
Type: text/x-patch
Size: 3180 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160812/d441ae32/attachment.bin>


More information about the cfe-commits mailing list