aaron.ballman created this revision.
aaron.ballman added reviewers: rsmith, dblaikie.

WG14 has a working draft for C2x (WG14 N2346) and we've begun voting new 
features into it, so I think it's time for use to expose a C2x flag and use it. 
The new features we adopted this week that Clang already has support for are: 
the new attribute syntax (WG14 N2335), the `[[nodiscard]]` attribute (WG14 
N2267), the `[[maybe_unused]]` attribute (WG14 N2270), and the `[[deprecated]]` 
attribute (WG14 N2334).

This patch adds the new C2x language mode and flips a switch to allow 
double-square bracket attributes in that new mode.


https://reviews.llvm.org/D61370

Files:
  include/clang/Basic/LangOptions.def
  include/clang/Frontend/LangStandard.h
  include/clang/Frontend/LangStandards.def
  lib/Frontend/CompilerInvocation.cpp
  test/Driver/unknown-std.c
  test/Parser/c2x-attributes.c
  test/Sema/attr-cx2.c
  test/Sema/attr-deprecated-c2x.c
  test/Sema/c2x-maybe_unused-errors.c
  test/Sema/c2x-maybe_unused.c
  test/Sema/c2x-nodiscard.c

Index: test/Sema/c2x-nodiscard.c
===================================================================
--- test/Sema/c2x-nodiscard.c
+++ test/Sema/c2x-nodiscard.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -fdouble-square-bracket-attributes -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c2x -verify %s
 
 struct [[nodiscard]] S1 { // ok
   int i;
Index: test/Sema/c2x-maybe_unused.c
===================================================================
--- test/Sema/c2x-maybe_unused.c
+++ test/Sema/c2x-maybe_unused.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -Wunused -fdouble-square-bracket-attributes -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wunused -std=c2x -verify %s
 
 struct [[maybe_unused]] S1 { // ok
   int a [[maybe_unused]];
Index: test/Sema/c2x-maybe_unused-errors.c
===================================================================
--- test/Sema/c2x-maybe_unused-errors.c
+++ test/Sema/c2x-maybe_unused-errors.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -Wunused -fdouble-square-bracket-attributes -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wunused -std=c2x -verify %s
 
 struct [[maybe_unused]] S1 { // ok
   int a [[maybe_unused]];
Index: test/Sema/attr-deprecated-c2x.c
===================================================================
--- test/Sema/attr-deprecated-c2x.c
+++ test/Sema/attr-deprecated-c2x.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -verify -fsyntax-only -fdouble-square-bracket-attributes
+// RUN: %clang_cc1 %s -verify -fsyntax-only --std=c2x
 
 int f() [[deprecated]]; // expected-note 2 {{'f' has been explicitly marked deprecated here}}
 void g() [[deprecated]];// expected-note {{'g' has been explicitly marked deprecated here}}
Index: test/Sema/attr-cx2.c
===================================================================
--- test/Sema/attr-cx2.c
+++ test/Sema/attr-cx2.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -fdouble-square-bracket-attributes %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=c2x %s
 
 struct S {};
 struct S * [[clang::address_space(1)]] Foo;
Index: test/Parser/c2x-attributes.c
===================================================================
--- test/Parser/c2x-attributes.c
+++ test/Parser/c2x-attributes.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -fdouble-square-bracket-attributes -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=gnu2x -verify %s
 
 enum [[]] E {
   One [[]],
Index: test/Driver/unknown-std.c
===================================================================
--- test/Driver/unknown-std.c
+++ test/Driver/unknown-std.c
@@ -16,6 +16,8 @@
 // CHECK-NEXT: note: use 'gnu11' for 'ISO C 2011 with GNU extensions' standard
 // CHECK-NEXT: note: use 'c17', 'iso9899:2017', 'c18', or 'iso9899:2018' for 'ISO C 2017' standard
 // CHECK-NEXT: note: use 'gnu17' or 'gnu18' for 'ISO C 2017 with GNU extensions' standard
+// CHECK-NEXT: note: use 'c2x' for 'Working Draft for ISO C2x' standard
+// CHECK-NEXT: note: use 'gnu2x' for 'Working Draft for ISO C2x with GNU extensions' standard
 
 // Make sure that no other output is present.
 // CHECK-NOT: {{^.+$}}
Index: lib/Frontend/CompilerInvocation.cpp
===================================================================
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2118,6 +2118,7 @@
   Opts.C99 = Std.isC99();
   Opts.C11 = Std.isC11();
   Opts.C17 = Std.isC17();
+  Opts.C2x = Std.isC2x();
   Opts.CPlusPlus = Std.isCPlusPlus();
   Opts.CPlusPlus11 = Std.isCPlusPlus11();
   Opts.CPlusPlus14 = Std.isCPlusPlus14();
@@ -2589,10 +2590,10 @@
   Opts.BlocksRuntimeOptional = Args.hasArg(OPT_fblocks_runtime_optional);
   Opts.Coroutines = Opts.CPlusPlus2a || Args.hasArg(OPT_fcoroutines_ts);
 
-  // Enable [[]] attributes in C++11 by default.
-  Opts.DoubleSquareBracketAttributes =
-      Args.hasFlag(OPT_fdouble_square_bracket_attributes,
-                   OPT_fno_double_square_bracket_attributes, Opts.CPlusPlus11);
+  // Enable [[]] attributes in C++11 and C2x by default.
+  Opts.DoubleSquareBracketAttributes = Args.hasFlag(
+      OPT_fdouble_square_bracket_attributes,
+      OPT_fno_double_square_bracket_attributes, Opts.CPlusPlus11 || Opts.C2x);
 
   Opts.CPlusPlusModules = Opts.CPlusPlus2a;
   Opts.ModulesTS = Args.hasArg(OPT_fmodules_ts);
Index: include/clang/Frontend/LangStandards.def
===================================================================
--- include/clang/Frontend/LangStandards.def
+++ include/clang/Frontend/LangStandards.def
@@ -88,6 +88,14 @@
              LineComment | C99 | C11 | C17 | Digraphs | GNUMode | HexFloat)
 LANGSTANDARD_ALIAS(gnu17, "gnu18")
 
+// C2x modes
+LANGSTANDARD(c2x, "c2x",
+             C, "Working Draft for ISO C2x",
+             LineComment | C99 | C11 | C17 | C2x | Digraphs | HexFloat)
+LANGSTANDARD(gnu2x, "gnu2x",
+             C, "Working Draft for ISO C2x with GNU extensions",
+             LineComment | C99 | C11 | C17 | C2x | Digraphs | GNUMode | HexFloat)
+
 // C++ modes
 LANGSTANDARD(cxx98, "c++98",
              CXX, "ISO C++ 1998 with amendments",
Index: include/clang/Frontend/LangStandard.h
===================================================================
--- include/clang/Frontend/LangStandard.h
+++ include/clang/Frontend/LangStandard.h
@@ -22,16 +22,17 @@
   C99 = (1 << 1),
   C11 = (1 << 2),
   C17 = (1 << 3),
-  CPlusPlus = (1 << 4),
-  CPlusPlus11 = (1 << 5),
-  CPlusPlus14 = (1 << 6),
-  CPlusPlus17 = (1 << 7),
-  CPlusPlus2a = (1 << 8),
-  Digraphs = (1 << 9),
-  GNUMode = (1 << 10),
-  HexFloat = (1 << 11),
-  ImplicitInt = (1 << 12),
-  OpenCL = (1 << 13)
+  C2x = (1 << 4),
+  CPlusPlus = (1 << 5),
+  CPlusPlus11 = (1 << 6),
+  CPlusPlus14 = (1 << 7),
+  CPlusPlus17 = (1 << 8),
+  CPlusPlus2a = (1 << 9),
+  Digraphs = (1 << 10),
+  GNUMode = (1 << 11),
+  HexFloat = (1 << 12),
+  ImplicitInt = (1 << 13),
+  OpenCL = (1 << 14)
 };
 
 }
@@ -73,6 +74,9 @@
   /// isC17 - Language is a superset of C17.
   bool isC17() const { return Flags & frontend::C17; }
 
+  /// 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 @@
 LANGOPT(C99               , 1, 0, "C99")
 LANGOPT(C11               , 1, 0, "C11")
 LANGOPT(C17               , 1, 0, "C17")
+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")
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D61370: A... Aaron Ballman via Phabricator via cfe-commits

Reply via email to