llvm-project/clang/lib/Basic/Warnings.cpp

231 lines
8.6 KiB
C++
Raw Normal View History

//===--- Warnings.cpp - C-Language Front-end ------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Command line warning options handler.
//
//===----------------------------------------------------------------------===//
//
// This file is responsible for handling all warning options. This includes
// a number of -Wfoo options and their variants, which are driven by TableGen-
// generated data, and the special cases -pedantic, -pedantic-errors, -w,
// -Werror and -Wfatal-errors.
//
// Each warning option controls any number of actual warnings.
// Given a warning option 'foo', the following are valid:
// -Wfoo, -Wno-foo, -Werror=foo, -Wfatal-errors=foo
//
// Remark options are also handled here, analogously, except that they are much
// simpler because a remark can't be promoted to an error.
#include "clang/Basic/AllDiagnostics.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/DiagnosticOptions.h"
#include <algorithm>
#include <cstring>
#include <utility>
using namespace clang;
// EmitUnknownDiagWarning - Emit a warning and typo hint for unknown warning
// opts
2011-11-16 03:03:03 +08:00
static void EmitUnknownDiagWarning(DiagnosticsEngine &Diags,
diag::Flavor Flavor, StringRef Prefix,
StringRef Opt) {
StringRef Suggestion = DiagnosticIDs::getNearestOption(Flavor, Opt);
Diags.Report(diag::warn_unknown_diag_option)
<< (Flavor == diag::Flavor::WarningOrError ? 0 : 1) << (Prefix.str() += Opt)
<< !Suggestion.empty() << (Prefix.str() += Suggestion);
}
void clang::ProcessWarningOptions(DiagnosticsEngine &Diags,
const DiagnosticOptions &Opts,
bool ReportDiags) {
Diags.setSuppressSystemWarnings(true); // Default to -Wno-system-headers
Diags.setIgnoreAllWarnings(Opts.IgnoreWarnings);
Diags.setShowOverloads(Opts.getShowOverloads());
Diags.setElideType(Opts.ElideType);
Diags.setPrintTemplateTree(Opts.ShowTemplateTree);
Diags.setShowColors(Opts.ShowColors);
// Handle -ferror-limit
if (Opts.ErrorLimit)
Diags.setErrorLimit(Opts.ErrorLimit);
if (Opts.TemplateBacktraceLimit)
Diags.setTemplateBacktraceLimit(Opts.TemplateBacktraceLimit);
if (Opts.ConstexprBacktraceLimit)
Diags.setConstexprBacktraceLimit(Opts.ConstexprBacktraceLimit);
// If -pedantic or -pedantic-errors was specified, then we want to map all
// extension diagnostics onto WARNING or ERROR unless the user has futz'd
// around with them explicitly.
if (Opts.PedanticErrors)
Diags.setExtensionHandlingBehavior(diag::Severity::Error);
else if (Opts.Pedantic)
Diags.setExtensionHandlingBehavior(diag::Severity::Warning);
else
Diags.setExtensionHandlingBehavior(diag::Severity::Ignored);
SmallVector<diag::kind, 10> _Diags;
const IntrusiveRefCntPtr< DiagnosticIDs > DiagIDs =
Parse the warning options twice. The first pass sets diagnostic state, while the second pass reports warnings/errors. This has the effect that we follow the more canonical "last option wins" paradigm when there are conflicting options. rdar://10383776 Previously, we parsed the warning options in order. This caused non-intuitive behavior: 1) clang test.c -Wnosuchwarning -Wno-unknown-warning-option Before: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 1 warning generated. After: [0 warning generated.] 2) clang test.c -Wnosuchwarning -Werror=unknown-warning-option Before: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 1 warning generated. After: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] 3) clang test.c -Werror=unknown-warning-option -Wnosuchwarning -Wno-error=unknown-warning-option -Wnosuchwarning Before: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] After: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 2 warnings generated. 4) clang test.c -Werror=unknown-warning-option -Wnosuchwarning -Wno-error=unknown-warning-option -Wno-unknown-warning-option -Wnosuchwarning Before: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] After: [0 warning generated.] llvm-svn: 143657
2011-11-04 05:23:39 +08:00
Diags.getDiagnosticIDs();
// We parse the warning options twice. The first pass sets diagnostic state,
// while the second pass reports warnings/errors. This has the effect that
// we follow the more canonical "last option wins" paradigm when there are
Parse the warning options twice. The first pass sets diagnostic state, while the second pass reports warnings/errors. This has the effect that we follow the more canonical "last option wins" paradigm when there are conflicting options. rdar://10383776 Previously, we parsed the warning options in order. This caused non-intuitive behavior: 1) clang test.c -Wnosuchwarning -Wno-unknown-warning-option Before: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 1 warning generated. After: [0 warning generated.] 2) clang test.c -Wnosuchwarning -Werror=unknown-warning-option Before: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 1 warning generated. After: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] 3) clang test.c -Werror=unknown-warning-option -Wnosuchwarning -Wno-error=unknown-warning-option -Wnosuchwarning Before: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] After: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 2 warnings generated. 4) clang test.c -Werror=unknown-warning-option -Wnosuchwarning -Wno-error=unknown-warning-option -Wno-unknown-warning-option -Wnosuchwarning Before: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] After: [0 warning generated.] llvm-svn: 143657
2011-11-04 05:23:39 +08:00
// conflicting options.
for (unsigned Report = 0, ReportEnd = 2; Report != ReportEnd; ++Report) {
bool SetDiagnostic = (Report == 0);
// If we've set the diagnostic state and are not reporting diagnostics then
// we're done.
if (!SetDiagnostic && !ReportDiags)
break;
Parse the warning options twice. The first pass sets diagnostic state, while the second pass reports warnings/errors. This has the effect that we follow the more canonical "last option wins" paradigm when there are conflicting options. rdar://10383776 Previously, we parsed the warning options in order. This caused non-intuitive behavior: 1) clang test.c -Wnosuchwarning -Wno-unknown-warning-option Before: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 1 warning generated. After: [0 warning generated.] 2) clang test.c -Wnosuchwarning -Werror=unknown-warning-option Before: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 1 warning generated. After: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] 3) clang test.c -Werror=unknown-warning-option -Wnosuchwarning -Wno-error=unknown-warning-option -Wnosuchwarning Before: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] After: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 2 warnings generated. 4) clang test.c -Werror=unknown-warning-option -Wnosuchwarning -Wno-error=unknown-warning-option -Wno-unknown-warning-option -Wnosuchwarning Before: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] After: [0 warning generated.] llvm-svn: 143657
2011-11-04 05:23:39 +08:00
for (unsigned i = 0, e = Opts.Warnings.size(); i != e; ++i) {
const auto Flavor = diag::Flavor::WarningOrError;
Parse the warning options twice. The first pass sets diagnostic state, while the second pass reports warnings/errors. This has the effect that we follow the more canonical "last option wins" paradigm when there are conflicting options. rdar://10383776 Previously, we parsed the warning options in order. This caused non-intuitive behavior: 1) clang test.c -Wnosuchwarning -Wno-unknown-warning-option Before: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 1 warning generated. After: [0 warning generated.] 2) clang test.c -Wnosuchwarning -Werror=unknown-warning-option Before: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 1 warning generated. After: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] 3) clang test.c -Werror=unknown-warning-option -Wnosuchwarning -Wno-error=unknown-warning-option -Wnosuchwarning Before: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] After: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 2 warnings generated. 4) clang test.c -Werror=unknown-warning-option -Wnosuchwarning -Wno-error=unknown-warning-option -Wno-unknown-warning-option -Wnosuchwarning Before: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] After: [0 warning generated.] llvm-svn: 143657
2011-11-04 05:23:39 +08:00
StringRef Opt = Opts.Warnings[i];
StringRef OrigOpt = Opts.Warnings[i];
// Treat -Wformat=0 as an alias for -Wno-format.
if (Opt == "format=0")
Opt = "no-format";
Parse the warning options twice. The first pass sets diagnostic state, while the second pass reports warnings/errors. This has the effect that we follow the more canonical "last option wins" paradigm when there are conflicting options. rdar://10383776 Previously, we parsed the warning options in order. This caused non-intuitive behavior: 1) clang test.c -Wnosuchwarning -Wno-unknown-warning-option Before: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 1 warning generated. After: [0 warning generated.] 2) clang test.c -Wnosuchwarning -Werror=unknown-warning-option Before: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 1 warning generated. After: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] 3) clang test.c -Werror=unknown-warning-option -Wnosuchwarning -Wno-error=unknown-warning-option -Wnosuchwarning Before: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] After: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 2 warnings generated. 4) clang test.c -Werror=unknown-warning-option -Wnosuchwarning -Wno-error=unknown-warning-option -Wno-unknown-warning-option -Wnosuchwarning Before: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] After: [0 warning generated.] llvm-svn: 143657
2011-11-04 05:23:39 +08:00
// Check to see if this warning starts with "no-", if so, this is a
// negative form of the option.
bool isPositive = true;
if (Opt.startswith("no-")) {
isPositive = false;
Opt = Opt.substr(3);
}
Parse the warning options twice. The first pass sets diagnostic state, while the second pass reports warnings/errors. This has the effect that we follow the more canonical "last option wins" paradigm when there are conflicting options. rdar://10383776 Previously, we parsed the warning options in order. This caused non-intuitive behavior: 1) clang test.c -Wnosuchwarning -Wno-unknown-warning-option Before: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 1 warning generated. After: [0 warning generated.] 2) clang test.c -Wnosuchwarning -Werror=unknown-warning-option Before: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 1 warning generated. After: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] 3) clang test.c -Werror=unknown-warning-option -Wnosuchwarning -Wno-error=unknown-warning-option -Wnosuchwarning Before: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] After: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 2 warnings generated. 4) clang test.c -Werror=unknown-warning-option -Wnosuchwarning -Wno-error=unknown-warning-option -Wno-unknown-warning-option -Wnosuchwarning Before: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] After: [0 warning generated.] llvm-svn: 143657
2011-11-04 05:23:39 +08:00
// Figure out how this option affects the warning. If -Wfoo, map the
// diagnostic to a warning, if -Wno-foo, map it to ignore.
diag::Severity Mapping =
isPositive ? diag::Severity::Warning : diag::Severity::Ignored;
Parse the warning options twice. The first pass sets diagnostic state, while the second pass reports warnings/errors. This has the effect that we follow the more canonical "last option wins" paradigm when there are conflicting options. rdar://10383776 Previously, we parsed the warning options in order. This caused non-intuitive behavior: 1) clang test.c -Wnosuchwarning -Wno-unknown-warning-option Before: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 1 warning generated. After: [0 warning generated.] 2) clang test.c -Wnosuchwarning -Werror=unknown-warning-option Before: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 1 warning generated. After: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] 3) clang test.c -Werror=unknown-warning-option -Wnosuchwarning -Wno-error=unknown-warning-option -Wnosuchwarning Before: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] After: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 2 warnings generated. 4) clang test.c -Werror=unknown-warning-option -Wnosuchwarning -Wno-error=unknown-warning-option -Wno-unknown-warning-option -Wnosuchwarning Before: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] After: [0 warning generated.] llvm-svn: 143657
2011-11-04 05:23:39 +08:00
// -Wsystem-headers is a special case, not driven by the option table. It
// cannot be controlled with -Werror.
if (Opt == "system-headers") {
if (SetDiagnostic)
Diags.setSuppressSystemWarnings(!isPositive);
continue;
}
Parse the warning options twice. The first pass sets diagnostic state, while the second pass reports warnings/errors. This has the effect that we follow the more canonical "last option wins" paradigm when there are conflicting options. rdar://10383776 Previously, we parsed the warning options in order. This caused non-intuitive behavior: 1) clang test.c -Wnosuchwarning -Wno-unknown-warning-option Before: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 1 warning generated. After: [0 warning generated.] 2) clang test.c -Wnosuchwarning -Werror=unknown-warning-option Before: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 1 warning generated. After: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] 3) clang test.c -Werror=unknown-warning-option -Wnosuchwarning -Wno-error=unknown-warning-option -Wnosuchwarning Before: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] After: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 2 warnings generated. 4) clang test.c -Werror=unknown-warning-option -Wnosuchwarning -Wno-error=unknown-warning-option -Wno-unknown-warning-option -Wnosuchwarning Before: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] After: [0 warning generated.] llvm-svn: 143657
2011-11-04 05:23:39 +08:00
// -Weverything is a special case as well. It implicitly enables all
// warnings, including ones not explicitly in a warning group.
if (Opt == "everything") {
if (SetDiagnostic) {
if (isPositive) {
Diags.setEnableAllWarnings(true);
} else {
Diags.setEnableAllWarnings(false);
Diags.setSeverityForAll(Flavor, diag::Severity::Ignored);
}
}
Parse the warning options twice. The first pass sets diagnostic state, while the second pass reports warnings/errors. This has the effect that we follow the more canonical "last option wins" paradigm when there are conflicting options. rdar://10383776 Previously, we parsed the warning options in order. This caused non-intuitive behavior: 1) clang test.c -Wnosuchwarning -Wno-unknown-warning-option Before: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 1 warning generated. After: [0 warning generated.] 2) clang test.c -Wnosuchwarning -Werror=unknown-warning-option Before: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 1 warning generated. After: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] 3) clang test.c -Werror=unknown-warning-option -Wnosuchwarning -Wno-error=unknown-warning-option -Wnosuchwarning Before: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] After: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 2 warnings generated. 4) clang test.c -Werror=unknown-warning-option -Wnosuchwarning -Wno-error=unknown-warning-option -Wno-unknown-warning-option -Wnosuchwarning Before: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] After: [0 warning generated.] llvm-svn: 143657
2011-11-04 05:23:39 +08:00
continue;
}
// -Werror/-Wno-error is a special case, not controlled by the option
Parse the warning options twice. The first pass sets diagnostic state, while the second pass reports warnings/errors. This has the effect that we follow the more canonical "last option wins" paradigm when there are conflicting options. rdar://10383776 Previously, we parsed the warning options in order. This caused non-intuitive behavior: 1) clang test.c -Wnosuchwarning -Wno-unknown-warning-option Before: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 1 warning generated. After: [0 warning generated.] 2) clang test.c -Wnosuchwarning -Werror=unknown-warning-option Before: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 1 warning generated. After: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] 3) clang test.c -Werror=unknown-warning-option -Wnosuchwarning -Wno-error=unknown-warning-option -Wnosuchwarning Before: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] After: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 2 warnings generated. 4) clang test.c -Werror=unknown-warning-option -Wnosuchwarning -Wno-error=unknown-warning-option -Wno-unknown-warning-option -Wnosuchwarning Before: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] After: [0 warning generated.] llvm-svn: 143657
2011-11-04 05:23:39 +08:00
// table. It also has the "specifier" form of -Werror=foo and -Werror-foo.
if (Opt.startswith("error")) {
StringRef Specifier;
if (Opt.size() > 5) { // Specifier must be present.
if ((Opt[5] != '=' && Opt[5] != '-') || Opt.size() == 6) {
if (Report)
Diags.Report(diag::warn_unknown_warning_specifier)
<< "-Werror" << ("-W" + OrigOpt.str());
Parse the warning options twice. The first pass sets diagnostic state, while the second pass reports warnings/errors. This has the effect that we follow the more canonical "last option wins" paradigm when there are conflicting options. rdar://10383776 Previously, we parsed the warning options in order. This caused non-intuitive behavior: 1) clang test.c -Wnosuchwarning -Wno-unknown-warning-option Before: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 1 warning generated. After: [0 warning generated.] 2) clang test.c -Wnosuchwarning -Werror=unknown-warning-option Before: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 1 warning generated. After: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] 3) clang test.c -Werror=unknown-warning-option -Wnosuchwarning -Wno-error=unknown-warning-option -Wnosuchwarning Before: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] After: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 2 warnings generated. 4) clang test.c -Werror=unknown-warning-option -Wnosuchwarning -Wno-error=unknown-warning-option -Wno-unknown-warning-option -Wnosuchwarning Before: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] After: [0 warning generated.] llvm-svn: 143657
2011-11-04 05:23:39 +08:00
continue;
}
Specifier = Opt.substr(6);
}
Parse the warning options twice. The first pass sets diagnostic state, while the second pass reports warnings/errors. This has the effect that we follow the more canonical "last option wins" paradigm when there are conflicting options. rdar://10383776 Previously, we parsed the warning options in order. This caused non-intuitive behavior: 1) clang test.c -Wnosuchwarning -Wno-unknown-warning-option Before: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 1 warning generated. After: [0 warning generated.] 2) clang test.c -Wnosuchwarning -Werror=unknown-warning-option Before: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 1 warning generated. After: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] 3) clang test.c -Werror=unknown-warning-option -Wnosuchwarning -Wno-error=unknown-warning-option -Wnosuchwarning Before: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] After: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 2 warnings generated. 4) clang test.c -Werror=unknown-warning-option -Wnosuchwarning -Wno-error=unknown-warning-option -Wno-unknown-warning-option -Wnosuchwarning Before: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] After: [0 warning generated.] llvm-svn: 143657
2011-11-04 05:23:39 +08:00
if (Specifier.empty()) {
if (SetDiagnostic)
Diags.setWarningsAsErrors(isPositive);
continue;
}
Parse the warning options twice. The first pass sets diagnostic state, while the second pass reports warnings/errors. This has the effect that we follow the more canonical "last option wins" paradigm when there are conflicting options. rdar://10383776 Previously, we parsed the warning options in order. This caused non-intuitive behavior: 1) clang test.c -Wnosuchwarning -Wno-unknown-warning-option Before: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 1 warning generated. After: [0 warning generated.] 2) clang test.c -Wnosuchwarning -Werror=unknown-warning-option Before: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 1 warning generated. After: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] 3) clang test.c -Werror=unknown-warning-option -Wnosuchwarning -Wno-error=unknown-warning-option -Wnosuchwarning Before: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] After: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 2 warnings generated. 4) clang test.c -Werror=unknown-warning-option -Wnosuchwarning -Wno-error=unknown-warning-option -Wno-unknown-warning-option -Wnosuchwarning Before: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] After: [0 warning generated.] llvm-svn: 143657
2011-11-04 05:23:39 +08:00
if (SetDiagnostic) {
// Set the warning as error flag for this specifier.
Diags.setDiagnosticGroupWarningAsError(Specifier, isPositive);
} else if (DiagIDs->getDiagnosticsInGroup(Flavor, Specifier, _Diags)) {
EmitUnknownDiagWarning(Diags, Flavor, "-Werror=", Specifier);
Parse the warning options twice. The first pass sets diagnostic state, while the second pass reports warnings/errors. This has the effect that we follow the more canonical "last option wins" paradigm when there are conflicting options. rdar://10383776 Previously, we parsed the warning options in order. This caused non-intuitive behavior: 1) clang test.c -Wnosuchwarning -Wno-unknown-warning-option Before: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 1 warning generated. After: [0 warning generated.] 2) clang test.c -Wnosuchwarning -Werror=unknown-warning-option Before: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 1 warning generated. After: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] 3) clang test.c -Werror=unknown-warning-option -Wnosuchwarning -Wno-error=unknown-warning-option -Wnosuchwarning Before: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] After: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 2 warnings generated. 4) clang test.c -Werror=unknown-warning-option -Wnosuchwarning -Wno-error=unknown-warning-option -Wno-unknown-warning-option -Wnosuchwarning Before: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] After: [0 warning generated.] llvm-svn: 143657
2011-11-04 05:23:39 +08:00
}
continue;
}
Parse the warning options twice. The first pass sets diagnostic state, while the second pass reports warnings/errors. This has the effect that we follow the more canonical "last option wins" paradigm when there are conflicting options. rdar://10383776 Previously, we parsed the warning options in order. This caused non-intuitive behavior: 1) clang test.c -Wnosuchwarning -Wno-unknown-warning-option Before: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 1 warning generated. After: [0 warning generated.] 2) clang test.c -Wnosuchwarning -Werror=unknown-warning-option Before: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 1 warning generated. After: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] 3) clang test.c -Werror=unknown-warning-option -Wnosuchwarning -Wno-error=unknown-warning-option -Wnosuchwarning Before: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] After: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 2 warnings generated. 4) clang test.c -Werror=unknown-warning-option -Wnosuchwarning -Wno-error=unknown-warning-option -Wno-unknown-warning-option -Wnosuchwarning Before: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] After: [0 warning generated.] llvm-svn: 143657
2011-11-04 05:23:39 +08:00
// -Wfatal-errors is yet another special case.
if (Opt.startswith("fatal-errors")) {
StringRef Specifier;
if (Opt.size() != 12) {
if ((Opt[12] != '=' && Opt[12] != '-') || Opt.size() == 13) {
if (Report)
Diags.Report(diag::warn_unknown_warning_specifier)
<< "-Wfatal-errors" << ("-W" + OrigOpt.str());
Parse the warning options twice. The first pass sets diagnostic state, while the second pass reports warnings/errors. This has the effect that we follow the more canonical "last option wins" paradigm when there are conflicting options. rdar://10383776 Previously, we parsed the warning options in order. This caused non-intuitive behavior: 1) clang test.c -Wnosuchwarning -Wno-unknown-warning-option Before: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 1 warning generated. After: [0 warning generated.] 2) clang test.c -Wnosuchwarning -Werror=unknown-warning-option Before: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 1 warning generated. After: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] 3) clang test.c -Werror=unknown-warning-option -Wnosuchwarning -Wno-error=unknown-warning-option -Wnosuchwarning Before: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] After: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 2 warnings generated. 4) clang test.c -Werror=unknown-warning-option -Wnosuchwarning -Wno-error=unknown-warning-option -Wno-unknown-warning-option -Wnosuchwarning Before: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] After: [0 warning generated.] llvm-svn: 143657
2011-11-04 05:23:39 +08:00
continue;
}
Specifier = Opt.substr(13);
}
Parse the warning options twice. The first pass sets diagnostic state, while the second pass reports warnings/errors. This has the effect that we follow the more canonical "last option wins" paradigm when there are conflicting options. rdar://10383776 Previously, we parsed the warning options in order. This caused non-intuitive behavior: 1) clang test.c -Wnosuchwarning -Wno-unknown-warning-option Before: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 1 warning generated. After: [0 warning generated.] 2) clang test.c -Wnosuchwarning -Werror=unknown-warning-option Before: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 1 warning generated. After: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] 3) clang test.c -Werror=unknown-warning-option -Wnosuchwarning -Wno-error=unknown-warning-option -Wnosuchwarning Before: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] After: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 2 warnings generated. 4) clang test.c -Werror=unknown-warning-option -Wnosuchwarning -Wno-error=unknown-warning-option -Wno-unknown-warning-option -Wnosuchwarning Before: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] After: [0 warning generated.] llvm-svn: 143657
2011-11-04 05:23:39 +08:00
if (Specifier.empty()) {
if (SetDiagnostic)
Diags.setErrorsAsFatal(isPositive);
continue;
}
Parse the warning options twice. The first pass sets diagnostic state, while the second pass reports warnings/errors. This has the effect that we follow the more canonical "last option wins" paradigm when there are conflicting options. rdar://10383776 Previously, we parsed the warning options in order. This caused non-intuitive behavior: 1) clang test.c -Wnosuchwarning -Wno-unknown-warning-option Before: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 1 warning generated. After: [0 warning generated.] 2) clang test.c -Wnosuchwarning -Werror=unknown-warning-option Before: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 1 warning generated. After: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] 3) clang test.c -Werror=unknown-warning-option -Wnosuchwarning -Wno-error=unknown-warning-option -Wnosuchwarning Before: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] After: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 2 warnings generated. 4) clang test.c -Werror=unknown-warning-option -Wnosuchwarning -Wno-error=unknown-warning-option -Wno-unknown-warning-option -Wnosuchwarning Before: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] After: [0 warning generated.] llvm-svn: 143657
2011-11-04 05:23:39 +08:00
if (SetDiagnostic) {
// Set the error as fatal flag for this specifier.
Diags.setDiagnosticGroupErrorAsFatal(Specifier, isPositive);
} else if (DiagIDs->getDiagnosticsInGroup(Flavor, Specifier, _Diags)) {
EmitUnknownDiagWarning(Diags, Flavor, "-Wfatal-errors=", Specifier);
Parse the warning options twice. The first pass sets diagnostic state, while the second pass reports warnings/errors. This has the effect that we follow the more canonical "last option wins" paradigm when there are conflicting options. rdar://10383776 Previously, we parsed the warning options in order. This caused non-intuitive behavior: 1) clang test.c -Wnosuchwarning -Wno-unknown-warning-option Before: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 1 warning generated. After: [0 warning generated.] 2) clang test.c -Wnosuchwarning -Werror=unknown-warning-option Before: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 1 warning generated. After: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] 3) clang test.c -Werror=unknown-warning-option -Wnosuchwarning -Wno-error=unknown-warning-option -Wnosuchwarning Before: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] After: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 2 warnings generated. 4) clang test.c -Werror=unknown-warning-option -Wnosuchwarning -Wno-error=unknown-warning-option -Wno-unknown-warning-option -Wnosuchwarning Before: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] After: [0 warning generated.] llvm-svn: 143657
2011-11-04 05:23:39 +08:00
}
continue;
}
if (Report) {
if (DiagIDs->getDiagnosticsInGroup(Flavor, Opt, _Diags))
EmitUnknownDiagWarning(Diags, Flavor, isPositive ? "-W" : "-Wno-",
Opt);
} else {
Diags.setSeverityForGroup(Flavor, Opt, Mapping);
}
}
for (unsigned i = 0, e = Opts.Remarks.size(); i != e; ++i) {
StringRef Opt = Opts.Remarks[i];
const auto Flavor = diag::Flavor::Remark;
// Check to see if this warning starts with "no-", if so, this is a
// negative form of the option.
bool IsPositive = !Opt.startswith("no-");
if (!IsPositive) Opt = Opt.substr(3);
auto Severity = IsPositive ? diag::Severity::Remark
: diag::Severity::Ignored;
// -Reverything sets the state of all remarks. Note that all remarks are
// in remark groups, so we don't need a separate 'all remarks enabled'
// flag.
if (Opt == "everything") {
if (SetDiagnostic)
Diags.setSeverityForAll(Flavor, Severity);
continue;
}
if (Report) {
if (DiagIDs->getDiagnosticsInGroup(Flavor, Opt, _Diags))
EmitUnknownDiagWarning(Diags, Flavor, IsPositive ? "-R" : "-Rno-",
Opt);
Parse the warning options twice. The first pass sets diagnostic state, while the second pass reports warnings/errors. This has the effect that we follow the more canonical "last option wins" paradigm when there are conflicting options. rdar://10383776 Previously, we parsed the warning options in order. This caused non-intuitive behavior: 1) clang test.c -Wnosuchwarning -Wno-unknown-warning-option Before: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 1 warning generated. After: [0 warning generated.] 2) clang test.c -Wnosuchwarning -Werror=unknown-warning-option Before: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 1 warning generated. After: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] 3) clang test.c -Werror=unknown-warning-option -Wnosuchwarning -Wno-error=unknown-warning-option -Wnosuchwarning Before: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] After: warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] warning: unknown warning option '-Wnosuchwarning' [-Wunknown-warning-option] 2 warnings generated. 4) clang test.c -Werror=unknown-warning-option -Wnosuchwarning -Wno-error=unknown-warning-option -Wno-unknown-warning-option -Wnosuchwarning Before: error: unknown warning option '-Wnosuchwarning' [-Werror,-Wunknown-warning-option] After: [0 warning generated.] llvm-svn: 143657
2011-11-04 05:23:39 +08:00
} else {
Diags.setSeverityForGroup(Flavor, Opt,
IsPositive ? diag::Severity::Remark
: diag::Severity::Ignored);
}
}
}
}