Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d06f391

Browse files
committedMay 14, 2019
Add a new language mode for C2x; enable [[attribute]] support by default in C2x.
llvm-svn: 360667
1 parent 2dd5283 commit d06f391

11 files changed

+37
-17
lines changed
 

‎clang/include/clang/Basic/LangOptions.def

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
LANGOPT(C99 , 1, 0, "C99")
8383
LANGOPT(C11 , 1, 0, "C11")
8484
LANGOPT(C17 , 1, 0, "C17")
85+
LANGOPT(C2x , 1, 0, "C2x")
8586
LANGOPT(MSVCCompat , 1, 0, "Microsoft Visual C++ full compatibility mode")
8687
LANGOPT(MicrosoftExt , 1, 0, "Microsoft C++ extensions")
8788
LANGOPT(AsmBlocks , 1, 0, "Microsoft inline asm blocks")

‎clang/include/clang/Frontend/LangStandard.h

+14-10
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,17 @@ enum LangFeatures {
2222
C99 = (1 << 1),
2323
C11 = (1 << 2),
2424
C17 = (1 << 3),
25-
CPlusPlus = (1 << 4),
26-
CPlusPlus11 = (1 << 5),
27-
CPlusPlus14 = (1 << 6),
28-
CPlusPlus17 = (1 << 7),
29-
CPlusPlus2a = (1 << 8),
30-
Digraphs = (1 << 9),
31-
GNUMode = (1 << 10),
32-
HexFloat = (1 << 11),
33-
ImplicitInt = (1 << 12),
34-
OpenCL = (1 << 13)
25+
C2x = (1 << 4),
26+
CPlusPlus = (1 << 5),
27+
CPlusPlus11 = (1 << 6),
28+
CPlusPlus14 = (1 << 7),
29+
CPlusPlus17 = (1 << 8),
30+
CPlusPlus2a = (1 << 9),
31+
Digraphs = (1 << 10),
32+
GNUMode = (1 << 11),
33+
HexFloat = (1 << 12),
34+
ImplicitInt = (1 << 13),
35+
OpenCL = (1 << 14)
3536
};
3637

3738
}
@@ -73,6 +74,9 @@ struct LangStandard {
7374
/// isC17 - Language is a superset of C17.
7475
bool isC17() const { return Flags & frontend::C17; }
7576

77+
/// isC2x - Language is a superset of C2x.
78+
bool isC2x() const { return Flags & frontend::C2x; }
79+
7680
/// isCPlusPlus - Language is a C++ variant.
7781
bool isCPlusPlus() const { return Flags & frontend::CPlusPlus; }
7882

‎clang/include/clang/Frontend/LangStandards.def

+8
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ LANGSTANDARD(gnu17, "gnu17",
8888
LineComment | C99 | C11 | C17 | Digraphs | GNUMode | HexFloat)
8989
LANGSTANDARD_ALIAS(gnu17, "gnu18")
9090

91+
// C2x modes
92+
LANGSTANDARD(c2x, "c2x",
93+
C, "Working Draft for ISO C2x",
94+
LineComment | C99 | C11 | C17 | C2x | Digraphs | HexFloat)
95+
LANGSTANDARD(gnu2x, "gnu2x",
96+
C, "Working Draft for ISO C2x with GNU extensions",
97+
LineComment | C99 | C11 | C17 | C2x | Digraphs | GNUMode | HexFloat)
98+
9199
// C++ modes
92100
LANGSTANDARD(cxx98, "c++98",
93101
CXX, "ISO C++ 1998 with amendments",

‎clang/lib/Frontend/CompilerInvocation.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -2134,6 +2134,7 @@ void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK,
21342134
Opts.C99 = Std.isC99();
21352135
Opts.C11 = Std.isC11();
21362136
Opts.C17 = Std.isC17();
2137+
Opts.C2x = Std.isC2x();
21372138
Opts.CPlusPlus = Std.isCPlusPlus();
21382139
Opts.CPlusPlus11 = Std.isCPlusPlus11();
21392140
Opts.CPlusPlus14 = Std.isCPlusPlus14();
@@ -2200,6 +2201,9 @@ void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK,
22002201
Opts.AlignedAllocation = Opts.CPlusPlus17;
22012202

22022203
Opts.DollarIdents = !Opts.AsmPreprocessor;
2204+
2205+
// Enable [[]] attributes in C++11 and C2x by default.
2206+
Opts.DoubleSquareBracketAttributes = Opts.CPlusPlus11 || Opts.C2x;
22032207
}
22042208

22052209
/// Attempt to parse a visibility value out of the given argument.
@@ -2605,10 +2609,10 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
26052609
Opts.BlocksRuntimeOptional = Args.hasArg(OPT_fblocks_runtime_optional);
26062610
Opts.Coroutines = Opts.CPlusPlus2a || Args.hasArg(OPT_fcoroutines_ts);
26072611

2608-
// Enable [[]] attributes in C++11 by default.
26092612
Opts.DoubleSquareBracketAttributes =
26102613
Args.hasFlag(OPT_fdouble_square_bracket_attributes,
2611-
OPT_fno_double_square_bracket_attributes, Opts.CPlusPlus11);
2614+
OPT_fno_double_square_bracket_attributes,
2615+
Opts.DoubleSquareBracketAttributes);
26122616

26132617
Opts.CPlusPlusModules = Opts.CPlusPlus2a;
26142618
Opts.ModulesTS = Args.hasArg(OPT_fmodules_ts);

‎clang/test/Driver/unknown-std.c

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
// CHECK-NEXT: note: use 'gnu11' for 'ISO C 2011 with GNU extensions' standard
1717
// CHECK-NEXT: note: use 'c17', 'iso9899:2017', 'c18', or 'iso9899:2018' for 'ISO C 2017' standard
1818
// CHECK-NEXT: note: use 'gnu17' or 'gnu18' for 'ISO C 2017 with GNU extensions' standard
19+
// CHECK-NEXT: note: use 'c2x' for 'Working Draft for ISO C2x' standard
20+
// CHECK-NEXT: note: use 'gnu2x' for 'Working Draft for ISO C2x with GNU extensions' standard
1921

2022
// Make sure that no other output is present.
2123
// CHECK-NOT: {{^.+$}}

‎clang/test/Parser/c2x-attributes.c

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %clang_cc1 -fsyntax-only -fdouble-square-bracket-attributes -verify %s
2+
// RUN: %clang_cc1 -fsyntax-only -std=gnu2x -verify %s
23

34
enum [[]] E {
45
One [[]],

‎clang/test/Sema/attr-cx2.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -fdouble-square-bracket-attributes %s
1+
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=c2x %s
22

33
struct S {};
44
struct S * [[clang::address_space(1)]] Foo;

‎clang/test/Sema/attr-deprecated-c2x.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 %s -verify -fsyntax-only -fdouble-square-bracket-attributes
1+
// RUN: %clang_cc1 %s -verify -fsyntax-only --std=c2x
22

33
int f() [[deprecated]]; // expected-note 2 {{'f' has been explicitly marked deprecated here}}
44
void g() [[deprecated]];// expected-note {{'g' has been explicitly marked deprecated here}}

‎clang/test/Sema/c2x-maybe_unused-errors.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -fsyntax-only -Wunused -fdouble-square-bracket-attributes -verify %s
1+
// RUN: %clang_cc1 -fsyntax-only -Wunused -std=c2x -verify %s
22

33
struct [[maybe_unused]] S1 { // ok
44
int a [[maybe_unused]];

‎clang/test/Sema/c2x-maybe_unused.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -fsyntax-only -Wunused -fdouble-square-bracket-attributes -verify %s
1+
// RUN: %clang_cc1 -fsyntax-only -Wunused -std=c2x -verify %s
22

33
struct [[maybe_unused]] S1 { // ok
44
int a [[maybe_unused]];

‎clang/test/Sema/c2x-nodiscard.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -fsyntax-only -fdouble-square-bracket-attributes -verify %s
1+
// RUN: %clang_cc1 -fsyntax-only -std=c2x -verify %s
22

33
struct [[nodiscard]] S1 { // ok
44
int i;

0 commit comments

Comments
 (0)
Failed to load comments.