r301507 - Improve diagnostics for bad -std= flag.

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 26 18:17:05 PDT 2017


Author: rsmith
Date: Wed Apr 26 20:17:05 2017
New Revision: 301507

URL: http://llvm.org/viewvc/llvm-project?rev=301507&view=rev
Log:
Improve diagnostics for bad -std= flag.

Don't list deprecated -std= values (c++0x etc). Only produce one line of output
per standard, even if we know it by multiple names.

In passing, add missing -std=gnu++03 alias (supported by GCC), and add new
spelling '-std=cl1.0' for OpenCL 1.0 for consistency with the other values,
with the same meaning as the preexisting '-std=cl'.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
    cfe/trunk/include/clang/Frontend/LangStandards.def
    cfe/trunk/lib/Frontend/CompilerInvocation.cpp
    cfe/trunk/test/Driver/unknown-std.c
    cfe/trunk/test/Driver/unknown-std.cl
    cfe/trunk/test/Driver/unknown-std.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=301507&r1=301506&r2=301507&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Wed Apr 26 20:17:05 2017
@@ -233,7 +233,9 @@ def note_drv_t_option_is_global : Note<
   "The last /TC or /TP option takes precedence over earlier instances">;
 def note_drv_address_sanitizer_debug_runtime : Note<
   "AddressSanitizer doesn't support linking with debug runtime libraries yet">;
-def note_drv_use_standard : Note<"use '%0' for '%1' standard">;
+def note_drv_use_standard : Note<"use '%0'"
+  "%select{| or '%3'|, '%3', or '%4'|, '%3', '%4', or '%5'}2 "
+  "for '%1' standard">;
 
 def err_analyzer_config_no_value : Error<
   "analyzer-config option '%0' has a key but no value">;

Modified: cfe/trunk/include/clang/Frontend/LangStandards.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/LangStandards.def?rev=301507&r1=301506&r2=301507&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/LangStandards.def (original)
+++ cfe/trunk/include/clang/Frontend/LangStandards.def Wed Apr 26 20:17:05 2017
@@ -24,20 +24,23 @@
 /// \param IDENT - The name of the standard as a C++ identifier.
 /// \param ALIAS - The alias of the standard.
 
+/// LANGSTANDARD_ALIAS_DEPR(IDENT, ALIAS)
+/// Same as LANGSTANDARD_ALIAS, but for a deprecated alias.
+
 #ifndef LANGSTANDARD_ALIAS
 #define LANGSTANDARD_ALIAS(IDENT, ALIAS)
 #endif
 
+#ifndef LANGSTANDARD_ALIAS_DEPR
+#define LANGSTANDARD_ALIAS_DEPR(IDENT, ALIAS) LANGSTANDARD_ALIAS(IDENT, ALIAS)
+#endif
+
 // C89-ish modes.
 LANGSTANDARD(c89, "c89",
              C, "ISO C 1990",
              ImplicitInt)
-LANGSTANDARD(c90, "c90", C,
-             "ISO C 1990",
-             ImplicitInt)
-LANGSTANDARD(iso9899_1990, "iso9899:1990",
-             C, "ISO C 1990",
-             ImplicitInt)
+LANGSTANDARD_ALIAS(c89, "c90")
+LANGSTANDARD_ALIAS(c89, "iso9899:1990")
 
 LANGSTANDARD(c94, "iso9899:199409",
              C, "ISO C 1990 with amendment 1",
@@ -46,104 +49,82 @@ LANGSTANDARD(c94, "iso9899:199409",
 LANGSTANDARD(gnu89, "gnu89",
              C, "ISO C 1990 with GNU extensions",
              LineComment | Digraphs | GNUMode | ImplicitInt)
-LANGSTANDARD(gnu90, "gnu90",
-             C, "ISO C 1990 with GNU extensions",
-             LineComment | Digraphs | GNUMode | ImplicitInt)
+LANGSTANDARD_ALIAS(gnu89, "gnu90")
 
 // C99-ish modes
 LANGSTANDARD(c99, "c99",
              C, "ISO C 1999",
              LineComment | C99 | Digraphs | HexFloat)
-LANGSTANDARD(c9x, "c9x",
-             C, "ISO C 1999",
-             LineComment | C99 | Digraphs | HexFloat)
-LANGSTANDARD(iso9899_1999, "iso9899:1999",
-             C, "ISO C 1999",
-             LineComment | C99 | Digraphs | HexFloat)
-LANGSTANDARD(iso9899_199x, "iso9899:199x",
-             C, "ISO C 1999",
-             LineComment | C99 | Digraphs | HexFloat)
+LANGSTANDARD_ALIAS(c99, "iso9899:1999")
+LANGSTANDARD_ALIAS_DEPR(c99, "c9x")
+LANGSTANDARD_ALIAS_DEPR(c99, "iso9899:199x")
 
 LANGSTANDARD(gnu99, "gnu99",
              C, "ISO C 1999 with GNU extensions",
              LineComment | C99 | Digraphs | GNUMode | HexFloat)
-LANGSTANDARD(gnu9x, "gnu9x",
-             C, "ISO C 1999 with GNU extensions",
-             LineComment | C99 | Digraphs | GNUMode | HexFloat)
+LANGSTANDARD_ALIAS_DEPR(gnu99, "gnu9x")
 
 // C11 modes
 LANGSTANDARD(c11, "c11",
              C, "ISO C 2011",
              LineComment | C99 | C11 | Digraphs | HexFloat)
-LANGSTANDARD(c1x, "c1x",
-             C, "ISO C 2011",
-             LineComment | C99 | C11 | Digraphs | HexFloat)
-LANGSTANDARD(iso9899_2011, "iso9899:2011",
-             C, "ISO C 2011",
-             LineComment | C99 | C11 | Digraphs | HexFloat)
-LANGSTANDARD(iso9899_201x, "iso9899:201x",
-             C, "ISO C 2011",
-             LineComment | C99 | C11 | Digraphs | HexFloat)
+LANGSTANDARD_ALIAS(c11, "iso9899:2011")
+LANGSTANDARD_ALIAS_DEPR(c11, "c1x")
+LANGSTANDARD_ALIAS_DEPR(c11, "iso9899:201x")
 
 LANGSTANDARD(gnu11, "gnu11",
              C, "ISO C 2011 with GNU extensions",
              LineComment | C99 | C11 | Digraphs | GNUMode | HexFloat)
-LANGSTANDARD(gnu1x, "gnu1x",
-             C, "ISO C 2011 with GNU extensions",
-             LineComment | C99 | C11 | Digraphs | GNUMode | HexFloat)
+LANGSTANDARD_ALIAS_DEPR(gnu11, "gnu1x")
 
 // C++ modes
 LANGSTANDARD(cxx98, "c++98",
              CXX, "ISO C++ 1998 with amendments",
              LineComment | CPlusPlus | Digraphs)
-LANGSTANDARD(cxx03, "c++03",
-             CXX, "ISO C++ 1998 with amendments",
-             LineComment | CPlusPlus | Digraphs)
+LANGSTANDARD_ALIAS(cxx98, "c++03")
+
 LANGSTANDARD(gnucxx98, "gnu++98",
              CXX, "ISO C++ 1998 with amendments and GNU extensions",
              LineComment | CPlusPlus | Digraphs | GNUMode)
+LANGSTANDARD_ALIAS(gnucxx98, "gnu++03")
 
-LANGSTANDARD(cxx0x, "c++0x",
-             CXX, "ISO C++ 2011 with amendments",
-             LineComment | CPlusPlus | CPlusPlus11 | Digraphs)
 LANGSTANDARD(cxx11, "c++11",
              CXX, "ISO C++ 2011 with amendments",
              LineComment | CPlusPlus | CPlusPlus11 | Digraphs)
-LANGSTANDARD(gnucxx0x, "gnu++0x",
-             CXX, "ISO C++ 2011 with amendments and GNU extensions",
-             LineComment | CPlusPlus | CPlusPlus11 | Digraphs | GNUMode)
+LANGSTANDARD_ALIAS_DEPR(cxx11, "c++0x")
+
 LANGSTANDARD(gnucxx11, "gnu++11", CXX,
              "ISO C++ 2011 with amendments and GNU extensions",
              LineComment | CPlusPlus | CPlusPlus11 | Digraphs | GNUMode)
+LANGSTANDARD_ALIAS_DEPR(gnucxx11, "gnu++0x")
 
-LANGSTANDARD(cxx1y, "c++1y",
-             CXX, "ISO C++ 2014 with amendments",
-             LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | Digraphs)
 LANGSTANDARD(cxx14, "c++14",
              CXX, "ISO C++ 2014 with amendments",
              LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | Digraphs)
-LANGSTANDARD(gnucxx1y, "gnu++1y",
-             CXX, "ISO C++ 2014 with amendments and GNU extensions",
-             LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | Digraphs |
-             GNUMode)
+LANGSTANDARD_ALIAS_DEPR(cxx14, "c++1y")
+
 LANGSTANDARD(gnucxx14, "gnu++14",
              CXX, "ISO C++ 2014 with amendments and GNU extensions",
              LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | Digraphs |
              GNUMode)
+LANGSTANDARD_ALIAS_DEPR(gnucxx14, "gnu++1y")
 
 LANGSTANDARD(cxx1z, "c++1z",
              CXX, "Working draft for ISO C++ 2017",
              LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | CPlusPlus1z |
              Digraphs | HexFloat)
+
 LANGSTANDARD(gnucxx1z, "gnu++1z",
              CXX, "Working draft for ISO C++ 2017 with GNU extensions",
              LineComment | CPlusPlus | CPlusPlus11 | CPlusPlus14 | CPlusPlus1z |
              Digraphs | HexFloat | GNUMode)
 
 // OpenCL
-LANGSTANDARD(opencl, "cl",
+LANGSTANDARD(opencl10, "cl1.0",
              OpenCL, "OpenCL 1.0",
              LineComment | C99 | Digraphs | HexFloat | OpenCL)
+LANGSTANDARD_ALIAS_DEPR(opencl10, "cl")
+
 LANGSTANDARD(opencl11, "cl1.1",
              OpenCL, "OpenCL 1.1",
              LineComment | C99 | Digraphs | HexFloat | OpenCL)
@@ -154,10 +135,10 @@ LANGSTANDARD(opencl20, "cl2.0",
              OpenCL, "OpenCL 2.0",
              LineComment | C99 | Digraphs | HexFloat | OpenCL)
 
-LANGSTANDARD_ALIAS(opencl, "CL")
-LANGSTANDARD_ALIAS(opencl11, "CL1.1")
-LANGSTANDARD_ALIAS(opencl12, "CL1.2")
-LANGSTANDARD_ALIAS(opencl20, "CL2.0")
+LANGSTANDARD_ALIAS_DEPR(opencl10, "CL")
+LANGSTANDARD_ALIAS_DEPR(opencl11, "CL1.1")
+LANGSTANDARD_ALIAS_DEPR(opencl12, "CL1.2")
+LANGSTANDARD_ALIAS_DEPR(opencl20, "CL2.0")
 
 // CUDA
 LANGSTANDARD(cuda, "cuda", CUDA, "NVIDIA CUDA(tm)",
@@ -165,4 +146,4 @@ LANGSTANDARD(cuda, "cuda", CUDA, "NVIDIA
 
 #undef LANGSTANDARD
 #undef LANGSTANDARD_ALIAS
-
+#undef LANGSTANDARD_ALIAS_DEPR

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=301507&r1=301506&r2=301507&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Wed Apr 26 20:17:05 2017
@@ -1575,7 +1575,7 @@ void CompilerInvocation::setLangDefaults
     case InputKind::LLVM_IR:
       llvm_unreachable("Invalid input kind!");
     case InputKind::OpenCL:
-      LangStd = LangStandard::lang_opencl;
+      LangStd = LangStandard::lang_opencl10;
       break;
     case InputKind::CUDA:
       LangStd = LangStandard::lang_cuda;
@@ -1621,7 +1621,7 @@ void CompilerInvocation::setLangDefaults
 
   // Set OpenCL Version.
   Opts.OpenCL = Std.isOpenCL();
-  if (LangStd == LangStandard::lang_opencl)
+  if (LangStd == LangStandard::lang_opencl10)
     Opts.OpenCLVersion = 100;
   else if (LangStd == LangStandard::lang_opencl11)
     Opts.OpenCLVersion = 110;
@@ -1778,8 +1778,20 @@ static void ParseLangArgs(LangOptions &O
         const LangStandard &Std = LangStandard::getLangStandardForKind(
           static_cast<LangStandard::Kind>(KindValue));
         if (IsInputCompatibleWithStandard(IK, Std)) {
-          Diags.Report(diag::note_drv_use_standard)
-            << Std.getName() << Std.getDescription();
+          auto Diag = Diags.Report(diag::note_drv_use_standard);
+          Diag << Std.getName() << Std.getDescription();
+          unsigned NumAliases = 0;
+#define LANGSTANDARD(id, name, lang, desc, features)
+#define LANGSTANDARD_ALIAS(id, alias) \
+          if (KindValue == LangStandard::lang_##id) ++NumAliases;
+#define LANGSTANDARD_ALIAS_DEPR(id, alias)
+#include "clang/Frontend/LangStandards.def"
+          Diag << NumAliases;
+#define LANGSTANDARD(id, name, lang, desc, features)
+#define LANGSTANDARD_ALIAS(id, alias) \
+          if (KindValue == LangStandard::lang_##id) Diag << alias;
+#define LANGSTANDARD_ALIAS_DEPR(id, alias)
+#include "clang/Frontend/LangStandards.def"
         }
       }
     } else {
@@ -1798,7 +1810,7 @@ static void ParseLangArgs(LangOptions &O
   if (const Arg *A = Args.getLastArg(OPT_cl_std_EQ)) {
     LangStandard::Kind OpenCLLangStd
       = llvm::StringSwitch<LangStandard::Kind>(A->getValue())
-        .Cases("cl", "CL", LangStandard::lang_opencl)
+        .Cases("cl", "CL", LangStandard::lang_opencl10)
         .Cases("cl1.1", "CL1.1", LangStandard::lang_opencl11)
         .Cases("cl1.2", "CL1.2", LangStandard::lang_opencl12)
         .Cases("cl2.0", "CL2.0", LangStandard::lang_opencl20)

Modified: cfe/trunk/test/Driver/unknown-std.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/unknown-std.c?rev=301507&r1=301506&r2=301507&view=diff
==============================================================================
--- cfe/trunk/test/Driver/unknown-std.c (original)
+++ cfe/trunk/test/Driver/unknown-std.c Wed Apr 26 20:17:05 2017
@@ -7,24 +7,13 @@
 // RUN: not %clang -x renderscript %s -std=foobar -c 2>&1 | FileCheck --match-full-lines %s
 
 // CHECK: error: invalid value 'foobar' in '-std=foobar'
-// CHECK-NEXT: note: use 'c89' for 'ISO C 1990' standard
-// CHECK-NEXT: note: use 'c90' for 'ISO C 1990' standard
-// CHECK-NEXT: note: use 'iso9899:1990' for 'ISO C 1990' standard
+// CHECK-NEXT: note: use 'c89', 'c90', or 'iso9899:1990' for 'ISO C 1990' standard
 // CHECK-NEXT: note: use 'iso9899:199409' for 'ISO C 1990 with amendment 1' standard
-// CHECK-NEXT: note: use 'gnu89' for 'ISO C 1990 with GNU extensions' standard
-// CHECK-NEXT: note: use 'gnu90' for 'ISO C 1990 with GNU extensions' standard
-// CHECK-NEXT: note: use 'c99' for 'ISO C 1999' standard
-// CHECK-NEXT: note: use 'c9x' for 'ISO C 1999' standard
-// CHECK-NEXT: note: use 'iso9899:1999' for 'ISO C 1999' standard
-// CHECK-NEXT: note: use 'iso9899:199x' for 'ISO C 1999' standard
+// CHECK-NEXT: note: use 'gnu89' or 'gnu90' for 'ISO C 1990 with GNU extensions' standard
+// CHECK-NEXT: note: use 'c99' or 'iso9899:1999' for 'ISO C 1999' standard
 // CHECK-NEXT: note: use 'gnu99' for 'ISO C 1999 with GNU extensions' standard
-// CHECK-NEXT: note: use 'gnu9x' for 'ISO C 1999 with GNU extensions' standard
-// CHECK-NEXT: note: use 'c11' for 'ISO C 2011' standard
-// CHECK-NEXT: note: use 'c1x' for 'ISO C 2011' standard
-// CHECK-NEXT: note: use 'iso9899:2011' for 'ISO C 2011' standard
-// CHECK-NEXT: note: use 'iso9899:201x' for 'ISO C 2011' 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 'gnu1x' for 'ISO C 2011 with GNU extensions' standard
 
 // Make sure that no other output is present.
 // CHECK-NOT: {{^.+$}}

Modified: cfe/trunk/test/Driver/unknown-std.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/unknown-std.cl?rev=301507&r1=301506&r2=301507&view=diff
==============================================================================
--- cfe/trunk/test/Driver/unknown-std.cl (original)
+++ cfe/trunk/test/Driver/unknown-std.cl Wed Apr 26 20:17:05 2017
@@ -6,7 +6,7 @@
 // RUN: FileCheck --match-full-lines %s
 
 // CHECK: error: invalid value 'foobar' in '-std=foobar'
-// CHECK-NEXT: note: use 'cl' for 'OpenCL 1.0' standard
+// CHECK-NEXT: note: use 'cl1.0' for 'OpenCL 1.0' standard
 // CHECK-NEXT: note: use 'cl1.1' for 'OpenCL 1.1' standard
 // CHECK-NEXT: note: use 'cl1.2' for 'OpenCL 1.2' standard
 // CHECK-NEXT: note: use 'cl2.0' for 'OpenCL 2.0' standard

Modified: cfe/trunk/test/Driver/unknown-std.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/unknown-std.cpp?rev=301507&r1=301506&r2=301507&view=diff
==============================================================================
--- cfe/trunk/test/Driver/unknown-std.cpp (original)
+++ cfe/trunk/test/Driver/unknown-std.cpp Wed Apr 26 20:17:05 2017
@@ -7,16 +7,11 @@
 // RUN: not %clang -x cuda -nocudainc -nocudalib %s -std=foobar -c 2>&1 | FileCheck --match-full-lines --check-prefix=CHECK --check-prefix=CUDA %s
 
 // CHECK: error: invalid value 'foobar' in '-std=foobar'
-// CHECK-NEXT: note: use 'c++98' for 'ISO C++ 1998 with amendments' standard
-// CHECK-NEXT: note: use 'c++03' for 'ISO C++ 1998 with amendments' standard
-// CHECK-NEXT: note: use 'gnu++98' for 'ISO C++ 1998 with amendments and GNU extensions' standard
-// CHECK-NEXT: note: use 'c++0x' for 'ISO C++ 2011 with amendments' standard
+// CHECK-NEXT: note: use 'c++98' or 'c++03' for 'ISO C++ 1998 with amendments' standard
+// CHECK-NEXT: note: use 'gnu++98' or 'gnu++03' for 'ISO C++ 1998 with amendments and GNU extensions' standard
 // CHECK-NEXT: note: use 'c++11' for 'ISO C++ 2011 with amendments' standard
-// CHECK-NEXT: note: use 'gnu++0x' for 'ISO C++ 2011 with amendments and GNU extensions' standard
 // CHECK-NEXT: note: use 'gnu++11' for 'ISO C++ 2011 with amendments and GNU extensions' standard
-// CHECK-NEXT: note: use 'c++1y' for 'ISO C++ 2014 with amendments' standard
 // CHECK-NEXT: note: use 'c++14' for 'ISO C++ 2014 with amendments' standard
-// CHECK-NEXT: note: use 'gnu++1y' for 'ISO C++ 2014 with amendments and GNU extensions' standard
 // CHECK-NEXT: note: use 'gnu++14' for 'ISO C++ 2014 with amendments and GNU extensions' standard
 // CHECK-NEXT: note: use 'c++1z' for 'Working draft for ISO C++ 2017' standard
 // CHECK-NEXT: note: use 'gnu++1z' for 'Working draft for ISO C++ 2017 with GNU extensions' standard




More information about the cfe-commits mailing list