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(C17 , 1, 0, "C17") 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") Index: include/clang/Frontend/LangStandard.h =================================================================== --- include/clang/Frontend/LangStandard.h +++ include/clang/Frontend/LangStandard.h @@ -22,16 +22,17 @@ LineComment = (1 << 0), C99 = (1 << 1), C11 = (1 << 2), - CPlusPlus = (1 << 3), - CPlusPlus11 = (1 << 4), - CPlusPlus14 = (1 << 5), - CPlusPlus1z = (1 << 6), - CPlusPlus2a = (1 << 7), - Digraphs = (1 << 8), - GNUMode = (1 << 9), - HexFloat = (1 << 10), - ImplicitInt = (1 << 11), - OpenCL = (1 << 12) + C17 = (1 << 3), + CPlusPlus = (1 << 4), + CPlusPlus11 = (1 << 5), + CPlusPlus14 = (1 << 6), + CPlusPlus1z = (1 << 7), + CPlusPlus2a = (1 << 8), + Digraphs = (1 << 9), + GNUMode = (1 << 10), + HexFloat = (1 << 11), + ImplicitInt = (1 << 12), + OpenCL = (1 << 13) }; } @@ -70,6 +71,9 @@ /// isC11 - Language is a superset of C11. bool isC11() const { return Flags & frontend::C11; } + /// isC17 - Language is a superset of C17. + bool isC17() const { return Flags & frontend::C17; } + /// isCPlusPlus - Language is a C++ variant. bool isCPlusPlus() const { return Flags & frontend::CPlusPlus; } Index: include/clang/Frontend/LangStandards.def =================================================================== --- include/clang/Frontend/LangStandards.def +++ include/clang/Frontend/LangStandards.def @@ -77,6 +77,15 @@ LineComment | C99 | C11 | Digraphs | GNUMode | HexFloat) LANGSTANDARD_ALIAS_DEPR(gnu11, "gnu1x") +// C17 modes +LANGSTANDARD(c17, "c17", + C, "ISO C 2017", + LineComment | C99 | C11 | C17 | Digraphs | HexFloat) +LANGSTANDARD_ALIAS(c17, "iso9899:2017") +LANGSTANDARD(gnu17, "gnu17", + C, "ISO C 2017 with GNU extensions", + LineComment | C99 | C11 | C17 | Digraphs | GNUMode | HexFloat) + // C++ modes LANGSTANDARD(cxx98, "c++98", CXX, "ISO C++ 1998 with amendments", Index: lib/Frontend/CompilerInvocation.cpp =================================================================== --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -1738,6 +1738,7 @@ Opts.LineComment = Std.hasLineComments(); Opts.C99 = Std.isC99(); Opts.C11 = Std.isC11(); + Opts.C17 = Std.isC17(); Opts.CPlusPlus = Std.isCPlusPlus(); Opts.CPlusPlus11 = Std.isCPlusPlus11(); Opts.CPlusPlus14 = Std.isCPlusPlus14(); Index: lib/Frontend/InitPreprocessor.cpp =================================================================== --- lib/Frontend/InitPreprocessor.cpp +++ lib/Frontend/InitPreprocessor.cpp @@ -370,7 +370,9 @@ Builder.defineMacro("__STDC_HOSTED__"); if (!LangOpts.CPlusPlus) { - if (LangOpts.C11) + if (LangOpts.C17) + Builder.defineMacro("__STDC_VERSION__", "201710L"); + else if (LangOpts.C11) Builder.defineMacro("__STDC_VERSION__", "201112L"); else if (LangOpts.C99) Builder.defineMacro("__STDC_VERSION__", "199901L"); Index: test/Driver/unknown-std.c =================================================================== --- test/Driver/unknown-std.c +++ test/Driver/unknown-std.c @@ -14,6 +14,8 @@ // CHECK-NEXT: note: use 'gnu99' for 'ISO C 1999 with GNU extensions' standard // CHECK-NEXT: note: use 'c11' or 'iso9899:2011' for 'ISO C 2011' standard // CHECK-NEXT: note: use 'gnu11' for 'ISO C 2011 with GNU extensions' standard +// CHECK-NEXT: note: use 'c17' or 'iso9899:2017' for 'ISO C 2017' standard +// CHECK-NEXT: note: use 'gnu17' for 'ISO C 2017 with GNU extensions' standard // Make sure that no other output is present. // CHECK-NOT: {{^.+$}} Index: test/Preprocessor/c17.c =================================================================== --- test/Preprocessor/c17.c +++ test/Preprocessor/c17.c @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -std=c17 %s +// expected-no-diagnostics + +_Static_assert(__STDC_VERSION__ == 201710L, "Incorrect __STDC_VERSION__"); +