From 6d6fa28130326caf2393e8da71116f632b5138ca Mon Sep 17 00:00:00 2001 From: Bruno Cardoso Lopes Date: Tue, 11 Oct 2016 18:21:26 +0000 Subject: [PATCH] Reapply [Driver][Diagnostics] Make 'show option names' default for driver warnings Reapply r283827 by fixing the tests to not be target specific Currently, driver level warnings do not show option names (e.g. warning: complain about foo [-Woption-name]) in a diagnostic unless -fdiagnostics-show-option is explictly specified. OTOH, the driver by default turn this option on for CC1. Change the logic to show option names by default in the driver as well. Differential Revision: https://reviews.llvm.org/D24516 rdar://problem/27300909 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@283913 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Frontend/CompilerInvocation.h | 3 ++- lib/Frontend/CompilerInvocation.cpp | 11 +++++++---- test/Driver/show-option-names.c | 5 +++++ 3 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 test/Driver/show-option-names.c diff --git a/include/clang/Frontend/CompilerInvocation.h b/include/clang/Frontend/CompilerInvocation.h index 66ba60d39e..cb037c2654 100644 --- a/include/clang/Frontend/CompilerInvocation.h +++ b/include/clang/Frontend/CompilerInvocation.h @@ -48,7 +48,8 @@ class DiagnosticsEngine; /// report the error(s). bool ParseDiagnosticArgs(DiagnosticOptions &Opts, llvm::opt::ArgList &Args, DiagnosticsEngine *Diags = nullptr, - bool DefaultDiagColor = true); + bool DefaultDiagColor = true, + bool DefaultShowOpt = true); class CompilerInvocationBase : public RefCountedBase { void operator=(const CompilerInvocationBase &) = delete; diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index efffd3031d..39588e8af8 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -957,7 +957,7 @@ static bool parseShowColorsArgs(const ArgList &Args, bool DefaultColor) { bool clang::ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args, DiagnosticsEngine *Diags, - bool DefaultDiagColor) { + bool DefaultDiagColor, bool DefaultShowOpt) { using namespace options; bool Success = true; @@ -977,7 +977,9 @@ bool clang::ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args, Opts.ShowFixits = !Args.hasArg(OPT_fno_diagnostics_fixit_info); Opts.ShowLocation = !Args.hasArg(OPT_fno_show_source_location); Opts.AbsolutePath = Args.hasArg(OPT_fdiagnostics_absolute_paths); - Opts.ShowOptionNames = Args.hasArg(OPT_fdiagnostics_show_option); + Opts.ShowOptionNames = + Args.hasFlag(OPT_fdiagnostics_show_option, + OPT_fno_diagnostics_show_option, DefaultShowOpt); llvm::sys::Process::UseANSIEscapeCodes(Args.hasArg(OPT_fansi_escape_codes)); @@ -2404,8 +2406,9 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res, Success &= ParseAnalyzerArgs(*Res.getAnalyzerOpts(), Args, Diags); Success &= ParseMigratorArgs(Res.getMigratorOpts(), Args); ParseDependencyOutputArgs(Res.getDependencyOutputOpts(), Args); - Success &= ParseDiagnosticArgs(Res.getDiagnosticOpts(), Args, &Diags, - false /*DefaultDiagColor*/); + Success &= + ParseDiagnosticArgs(Res.getDiagnosticOpts(), Args, &Diags, + false /*DefaultDiagColor*/, false /*DefaultShowOpt*/); ParseCommentArgs(LangOpts.CommentOpts, Args); ParseFileSystemArgs(Res.getFileSystemOpts(), Args); // FIXME: We shouldn't have to pass the DashX option around here diff --git a/test/Driver/show-option-names.c b/test/Driver/show-option-names.c new file mode 100644 index 0000000000..a88dec2b6a --- /dev/null +++ b/test/Driver/show-option-names.c @@ -0,0 +1,5 @@ +// RUN: %clang -c -isysroot /FOO %s 2>&1 | FileCheck --check-prefix=CHECK-SHOW-OPTION-NAMES %s +// CHECK-SHOW-OPTION-NAMES: warning: no such sysroot directory: '{{([A-Za-z]:.*)?}}/FOO' [-Wmissing-sysroot] + +// RUN: %clang -c -fno-diagnostics-show-option -isysroot /FOO %s 2>&1 | FileCheck --check-prefix=CHECK-NO-SHOW-OPTION-NAMES %s +// CHECK-NO-SHOW-OPTION-NAMES: warning: no such sysroot directory: '{{([A-Za-z]:.*)?}}/FOO'{{$}} -- 2.40.0