On Thu, Apr 18, 2013 at 10:51 AM, Matthieu Monrocq < [email protected]> wrote:
> > > > On Wed, Apr 17, 2013 at 11:52 PM, Nico Weber <[email protected]> wrote: > >> Author: nico >> Date: Wed Apr 17 16:52:44 2013 >> New Revision: 179728 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=179728&view=rev >> Log: >> Add support for gcc's spelling of -fcolor-diagnostics. >> >> See http://gcc.gnu.org/onlinedocs/gcc/Language-Independent-Options.html >> >> >> Is there any reason to support both ? Or rather, any idea why gcc did not > align (since for once *they* are coming late to the party). > It's what they do. They also have -Wno-conversion-null instead of -Wno-null-conversion, etc. > > It seems rather wasteful to have both... > > -- Matthieu > > > >> Added: >> cfe/trunk/test/Driver/color-diagnostics.c >> Modified: >> cfe/trunk/include/clang/Driver/Options.td >> cfe/trunk/lib/Driver/Tools.cpp >> >> Modified: cfe/trunk/include/clang/Driver/Options.td >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=179728&r1=179727&r2=179728&view=diff >> >> ============================================================================== >> --- cfe/trunk/include/clang/Driver/Options.td (original) >> +++ cfe/trunk/include/clang/Driver/Options.td Wed Apr 17 16:52:44 2013 >> @@ -333,6 +333,8 @@ def fcatch_undefined_behavior : Flag<["- >> def fclasspath_EQ : Joined<["-"], "fclasspath=">, Group<f_Group>; >> def fcolor_diagnostics : Flag<["-"], "fcolor-diagnostics">, >> Group<f_Group>, Flags<[CC1Option]>, >> HelpText<"Use colors in diagnostics">; >> +def fdiagnostics_color : Flag<["-"], "fdiagnostics-color">, >> Group<f_Group>; >> +def fdiagnostics_color_EQ : Joined<["-"], "fdiagnostics-color=">, >> Group<f_Group>; >> def fcomment_block_commands : CommaJoined<["-"], >> "fcomment-block-commands=">, Group<f_clang_Group>, Flags<[CC1Option]>, >> HelpText<"Treat each comma separated argument in <arg> as a >> documentation comment block command">, >> MetaVarName<"<arg>">; >> @@ -539,6 +541,7 @@ def fno_builtin : Flag<["-"], "fno-built >> def fno_caret_diagnostics : Flag<["-"], "fno-caret-diagnostics">, >> Group<f_Group>, >> Flags<[CC1Option]>; >> def fno_color_diagnostics : Flag<["-"], "fno-color-diagnostics">, >> Group<f_Group>; >> +def fno_diagnostics_color : Flag<["-"], "fno-diagnostics-color">, >> Group<f_Group>; >> def fno_common : Flag<["-"], "fno-common">, Group<f_Group>, >> Flags<[CC1Option]>, >> HelpText<"Compile common globals like normal definitions">; >> def fno_constant_cfstrings : Flag<["-"], "fno-constant-cfstrings">, >> Group<f_Group>, >> >> Modified: cfe/trunk/lib/Driver/Tools.cpp >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=179728&r1=179727&r2=179728&view=diff >> >> ============================================================================== >> --- cfe/trunk/lib/Driver/Tools.cpp (original) >> +++ cfe/trunk/lib/Driver/Tools.cpp Wed Apr 17 16:52:44 2013 >> @@ -3200,9 +3200,42 @@ void Clang::ConstructJob(Compilation &C, >> >> // Color diagnostics are the default, unless the terminal doesn't >> support >> // them. >> - if (Args.hasFlag(options::OPT_fcolor_diagnostics, >> - options::OPT_fno_color_diagnostics, >> - llvm::sys::Process::StandardErrHasColors())) >> + // Support both clang's -f[no-]color-diagnostics and gcc's >> + // -f[no-]diagnostics-colors[=never|always|auto]. >> + enum { Colors_On, Colors_Off, Colors_Auto } ShowColors = Colors_Auto; >> + for (ArgList::const_iterator it = Args.begin(), ie = Args.end(); >> + it != ie; ++it) { >> + const Option &O = (*it)->getOption(); >> + if (!O.matches(options::OPT_fcolor_diagnostics) && >> + !O.matches(options::OPT_fdiagnostics_color) && >> + !O.matches(options::OPT_fno_color_diagnostics) && >> + !O.matches(options::OPT_fno_diagnostics_color) && >> + !O.matches(options::OPT_fdiagnostics_color_EQ)) >> + continue; >> + >> + (*it)->claim(); >> + if (O.matches(options::OPT_fcolor_diagnostics) || >> + O.matches(options::OPT_fdiagnostics_color)) { >> + ShowColors = Colors_On; >> + } else if (O.matches(options::OPT_fno_color_diagnostics) || >> + O.matches(options::OPT_fno_diagnostics_color)) { >> + ShowColors = Colors_Off; >> + } else { >> + assert(O.matches(options::OPT_fdiagnostics_color_EQ)); >> + StringRef value((*it)->getValue()); >> + if (value == "always") >> + ShowColors = Colors_On; >> + else if (value == "never") >> + ShowColors = Colors_Off; >> + else if (value == "auto") >> + ShowColors = Colors_Auto; >> + else >> + getToolChain().getDriver().Diag(diag::err_drv_clang_unsupported) >> + << ("-fdiagnostics-color=" + value).str(); >> + } >> + } >> + if (ShowColors == Colors_On || >> + (ShowColors == Colors_Auto && >> llvm::sys::Process::StandardErrHasColors())) >> CmdArgs.push_back("-fcolor-diagnostics"); >> >> if (!Args.hasFlag(options::OPT_fshow_source_location, >> >> Added: cfe/trunk/test/Driver/color-diagnostics.c >> URL: >> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/color-diagnostics.c?rev=179728&view=auto >> >> ============================================================================== >> --- cfe/trunk/test/Driver/color-diagnostics.c (added) >> +++ cfe/trunk/test/Driver/color-diagnostics.c Wed Apr 17 16:52:44 2013 >> @@ -0,0 +1,53 @@ >> +// RUN: %clang -fcolor-diagnostics -### -c %s 2>&1 \ >> +// RUN: | FileCheck --check-prefix=CD %s >> +// CHECK-CD: clang{{.*}}" "-fcolor-diagnostics" >> + >> +// RUN: %clang -fno-color-diagnostics -### -c %s 2>&1 \ >> +// RUN: | FileCheck --check-prefix=NCD %s >> +// CHECK-NCD-NOT: clang{{.*}}" "-fcolor-diagnostics" >> + >> +// RUN: %clang -fdiagnostics-color -### -c %s 2>&1 \ >> +// RUN: | FileCheck --check-prefix=DC %s >> +// CHECK-DC: clang{{.*}}" "-fcolor-diagnostics" >> + >> +// RUN: %clang -fno-diagnostics-color -### -c %s 2>&1 \ >> +// RUN: | FileCheck --check-prefix=NDC %s >> +// CHECK-NDC-NOT: clang{{.*}}" "-fcolor-diagnostics" >> + >> +// RUN: %clang -fdiagnostics-color=always -### -c %s 2>&1 \ >> +// RUN: | FileCheck --check-prefix=DCE_A %s >> +// CHECK-DCE_A: clang{{.*}}" "-fcolor-diagnostics" >> + >> +// RUN: %clang -fdiagnostics-color=never -### -c %s 2>&1 \ >> +// RUN: | FileCheck --check-prefix=DCE_N %s >> +// CHECK-DCE_N-NOT: clang{{.*}}" "-fcolor-diagnostics" >> + >> +// The test doesn't run in a PTY, so "auto" defaults to off. >> +// RUN: %clang -fdiagnostics-color=auto -### -c %s 2>&1 \ >> +// RUN: | FileCheck --check-prefix=DCE_AUTO %s >> +// CHECK-DCE_AUTO-NOT: clang{{.*}}" "-fcolor-diagnostics" >> + >> +// RUN: %clang -fdiagnostics-color=foo -### -c %s 2>&1 \ >> +// RUN: | FileCheck --check-prefix=DCE_FOO %s >> +// CHECK-DCE_FOO: error: the clang compiler does not support >> '-fdiagnostics-color=foo' >> + >> +// Check that the last flag wins. >> +// RUN: %clang -fno-color-diagnostics -fdiagnostics-color -### -c %s >> 2>&1 \ >> +// RUN: | FileCheck --check-prefix=NCD_DC_S %s >> +// CHECK-NCD_DC_S: clang{{.*}}" "-fcolor-diagnostics" >> + >> +// RUN: %clang -fcolor-diagnostics -fno-diagnostics-color -### -c %s >> 2>&1 \ >> +// RUN: | FileCheck --check-prefix=CD_NDC_S %s >> +// CHECK-CD_NDC_S-NOT: clang{{.*}}" "-fcolor-diagnostics" >> + >> +// RUN: %clang -fdiagnostics-color -fno-color-diagnostics -### -c %s >> 2>&1 \ >> +// RUN: | FileCheck --check-prefix=DC_NCD_S %s >> +// CHECK-DC_NCD_S-NOT: clang{{.*}}" "-fcolor-diagnostics" >> + >> +// RUN: %clang -fno-diagnostics-color -fcolor-diagnostics -### -c %s >> 2>&1 \ >> +// RUN: | FileCheck --check-prefix=NDC_CD_S %s >> +// CHECK-NDC_CD_S: clang{{.*}}" "-fcolor-diagnostics" >> + >> +// RUN: %clang -fcolor-diagnostics -fdiagnostics-color=auto -### -c %s >> 2>&1 \ >> +// RUN: | FileCheck --check-prefix=CD_DCE_AUTO_S %s >> +// CHECK-CD_DCE_AUTO_S-NOT: clang{{.*}}" "-fcolor-diagnostics" >> >> >> _______________________________________________ >> cfe-commits mailing list >> [email protected] >> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits >> > > > _______________________________________________ > cfe-commits mailing list > [email protected] > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits > >
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
