From 59456511f4bab95ccd3c918dae256f5ec0f8fb39 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Thu, 27 Apr 2017 01:17:05 +0000 Subject: [PATCH] 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'. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@301507 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticDriverKinds.td | 4 +- include/clang/Frontend/LangStandards.def | 91 ++++++++------------ lib/Frontend/CompilerInvocation.cpp | 22 +++-- test/Driver/unknown-std.c | 19 +--- test/Driver/unknown-std.cl | 2 +- test/Driver/unknown-std.cpp | 9 +- 6 files changed, 63 insertions(+), 84 deletions(-) diff --git a/include/clang/Basic/DiagnosticDriverKinds.td b/include/clang/Basic/DiagnosticDriverKinds.td index 3980805ef9..3833f0f28f 100644 --- a/include/clang/Basic/DiagnosticDriverKinds.td +++ b/include/clang/Basic/DiagnosticDriverKinds.td @@ -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">; diff --git a/include/clang/Frontend/LangStandards.def b/include/clang/Frontend/LangStandards.def index ee0deaa2ef..1d214fd2a2 100644 --- a/include/clang/Frontend/LangStandards.def +++ b/include/clang/Frontend/LangStandards.def @@ -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 CUDA(tm)", #undef LANGSTANDARD #undef LANGSTANDARD_ALIAS - +#undef LANGSTANDARD_ALIAS_DEPR diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 481ce5bfa6..2cc48e1d1d 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -1575,7 +1575,7 @@ void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK, 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(LangOptions &Opts, InputKind IK, // 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 &Opts, ArgList &Args, InputKind IK, const LangStandard &Std = LangStandard::getLangStandardForKind( static_cast(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 &Opts, ArgList &Args, InputKind IK, if (const Arg *A = Args.getLastArg(OPT_cl_std_EQ)) { LangStandard::Kind OpenCLLangStd = llvm::StringSwitch(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) diff --git a/test/Driver/unknown-std.c b/test/Driver/unknown-std.c index 047726fbef..41736ec488 100644 --- a/test/Driver/unknown-std.c +++ b/test/Driver/unknown-std.c @@ -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: {{^.+$}} diff --git a/test/Driver/unknown-std.cl b/test/Driver/unknown-std.cl index b87a8c881c..71c478afca 100644 --- a/test/Driver/unknown-std.cl +++ b/test/Driver/unknown-std.cl @@ -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 diff --git a/test/Driver/unknown-std.cpp b/test/Driver/unknown-std.cpp index 0ffc1e2cb7..4f7a5e64a6 100644 --- a/test/Driver/unknown-std.cpp +++ b/test/Driver/unknown-std.cpp @@ -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 -- 2.40.0