163a9e0ff79f01a542afaf9b912e3dee3d395ebc5Sebastian Redl//===--- Warnings.cpp - C-Language Front-end ------------------------------===//
263a9e0ff79f01a542afaf9b912e3dee3d395ebc5Sebastian Redl//
363a9e0ff79f01a542afaf9b912e3dee3d395ebc5Sebastian Redl//                     The LLVM Compiler Infrastructure
463a9e0ff79f01a542afaf9b912e3dee3d395ebc5Sebastian Redl//
563a9e0ff79f01a542afaf9b912e3dee3d395ebc5Sebastian Redl// This file is distributed under the University of Illinois Open Source
663a9e0ff79f01a542afaf9b912e3dee3d395ebc5Sebastian Redl// License. See LICENSE.TXT for details.
763a9e0ff79f01a542afaf9b912e3dee3d395ebc5Sebastian Redl//
863a9e0ff79f01a542afaf9b912e3dee3d395ebc5Sebastian Redl//===----------------------------------------------------------------------===//
963a9e0ff79f01a542afaf9b912e3dee3d395ebc5Sebastian Redl//
1063a9e0ff79f01a542afaf9b912e3dee3d395ebc5Sebastian Redl// Command line warning options handler.
1163a9e0ff79f01a542afaf9b912e3dee3d395ebc5Sebastian Redl//
1263a9e0ff79f01a542afaf9b912e3dee3d395ebc5Sebastian Redl//===----------------------------------------------------------------------===//
1363a9e0ff79f01a542afaf9b912e3dee3d395ebc5Sebastian Redl//
1463a9e0ff79f01a542afaf9b912e3dee3d395ebc5Sebastian Redl// This file is responsible for handling all warning options. This includes
1563a9e0ff79f01a542afaf9b912e3dee3d395ebc5Sebastian Redl// a number of -Wfoo options and their variants, which are driven by TableGen-
16a3b089e062133bdc0e5c39ea03f8b78230953f6cChris Lattner// generated data, and the special cases -pedantic, -pedantic-errors, -w,
17a3b089e062133bdc0e5c39ea03f8b78230953f6cChris Lattner// -Werror and -Wfatal-errors.
1863a9e0ff79f01a542afaf9b912e3dee3d395ebc5Sebastian Redl//
19c5613db921c87067660b262af379b38a2791e412Sebastian Redl// Each warning option controls any number of actual warnings.
2063a9e0ff79f01a542afaf9b912e3dee3d395ebc5Sebastian Redl// Given a warning option 'foo', the following are valid:
21a3b089e062133bdc0e5c39ea03f8b78230953f6cChris Lattner//    -Wfoo, -Wno-foo, -Werror=foo, -Wfatal-errors=foo
2263a9e0ff79f01a542afaf9b912e3dee3d395ebc5Sebastian Redl//
23176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines// Remark options are also handled here, analogously, except that they are much
24176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines// simpler because a remark can't be promoted to an error.
256bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines#include "clang/Basic/AllDiagnostics.h"
2663a9e0ff79f01a542afaf9b912e3dee3d395ebc5Sebastian Redl#include "clang/Basic/Diagnostic.h"
2702c23ebf41ae2f70da0ba7337e05c51fbfe35f7fDouglas Gregor#include "clang/Basic/DiagnosticOptions.h"
2855fc873017f10f6f566b182b70f6fc22aefa3464Chandler Carruth#include <algorithm>
29ac8d6298a8ae9276412d8c054957dfa65a69eb14Eli Friedman#include <cstring>
3063a9e0ff79f01a542afaf9b912e3dee3d395ebc5Sebastian Redl#include <utility>
3163a9e0ff79f01a542afaf9b912e3dee3d395ebc5Sebastian Redlusing namespace clang;
3263a9e0ff79f01a542afaf9b912e3dee3d395ebc5Sebastian Redl
33588e83bf3e998d79d3acc7c7179ca466787f72ccChad Rosier// EmitUnknownDiagWarning - Emit a warning and typo hint for unknown warning
34588e83bf3e998d79d3acc7c7179ca466787f72ccChad Rosier// opts
3599643d951e56359c1bead5ce70be3883a06b520aChad Rosierstatic void EmitUnknownDiagWarning(DiagnosticsEngine &Diags,
36176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines                                   diag::Flavor Flavor, StringRef Prefix,
37176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines                                   StringRef Opt) {
38176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  StringRef Suggestion = DiagnosticIDs::getNearestOption(Flavor, Opt);
39176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  Diags.Report(diag::warn_unknown_diag_option)
40176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    << (Flavor == diag::Flavor::WarningOrError ? 0 : 1) << (Prefix.str() += Opt)
41176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    << !Suggestion.empty() << (Prefix.str() += Suggestion);
42dce6327160a6e333137b34cce77e2dfc2cd5aab6Benjamin Kramer}
43dce6327160a6e333137b34cce77e2dfc2cd5aab6Benjamin Kramer
44d6471f7c1921c7802804ce3ff6fe9768310f72b9David Blaikievoid clang::ProcessWarningOptions(DiagnosticsEngine &Diags,
4508e79d2f075d1326ff7a849fd1bc88dadf99d574Chad Rosier                                  const DiagnosticOptions &Opts,
4608e79d2f075d1326ff7a849fd1bc88dadf99d574Chad Rosier                                  bool ReportDiags) {
4727ceb9d77d929f02a8a811d189a96885629c7c0cChris Lattner  Diags.setSuppressSystemWarnings(true);  // Default to -Wno-system-headers
486907943901e0aae5be7618c36c0f8275634e6ab5Daniel Dunbar  Diags.setIgnoreAllWarnings(Opts.IgnoreWarnings);
49dc7b641574a733624489bd87fc7061771edf2113Douglas Gregor  Diags.setShowOverloads(Opts.getShowOverloads());
50246b6aa6763de8c617d564ef33123a8f3293a80eRichard Trieu
51246b6aa6763de8c617d564ef33123a8f3293a80eRichard Trieu  Diags.setElideType(Opts.ElideType);
52246b6aa6763de8c617d564ef33123a8f3293a80eRichard Trieu  Diags.setPrintTemplateTree(Opts.ShowTemplateTree);
53246b6aa6763de8c617d564ef33123a8f3293a80eRichard Trieu  Diags.setShowColors(Opts.ShowColors);
54246b6aa6763de8c617d564ef33123a8f3293a80eRichard Trieu
55c100214fdc41a7ea215f75d433eb1cb829fd4330Chris Lattner  // Handle -ferror-limit
56c100214fdc41a7ea215f75d433eb1cb829fd4330Chris Lattner  if (Opts.ErrorLimit)
57c100214fdc41a7ea215f75d433eb1cb829fd4330Chris Lattner    Diags.setErrorLimit(Opts.ErrorLimit);
58575cf3791216c33770ba950430493cdd43099f8fDouglas Gregor  if (Opts.TemplateBacktraceLimit)
59575cf3791216c33770ba950430493cdd43099f8fDouglas Gregor    Diags.setTemplateBacktraceLimit(Opts.TemplateBacktraceLimit);
6008d6e032a2a0a8656d12b3b7b93942987bb12eb7Richard Smith  if (Opts.ConstexprBacktraceLimit)
6108d6e032a2a0a8656d12b3b7b93942987bb12eb7Richard Smith    Diags.setConstexprBacktraceLimit(Opts.ConstexprBacktraceLimit);
6263a9e0ff79f01a542afaf9b912e3dee3d395ebc5Sebastian Redl
63b54b276a920246c595a0498da281821eb9d22996Chris Lattner  // If -pedantic or -pedantic-errors was specified, then we want to map all
64b54b276a920246c595a0498da281821eb9d22996Chris Lattner  // extension diagnostics onto WARNING or ERROR unless the user has futz'd
65b54b276a920246c595a0498da281821eb9d22996Chris Lattner  // around with them explicitly.
666907943901e0aae5be7618c36c0f8275634e6ab5Daniel Dunbar  if (Opts.PedanticErrors)
67c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines    Diags.setExtensionHandlingBehavior(diag::Severity::Error);
686907943901e0aae5be7618c36c0f8275634e6ab5Daniel Dunbar  else if (Opts.Pedantic)
69c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines    Diags.setExtensionHandlingBehavior(diag::Severity::Warning);
70b54b276a920246c595a0498da281821eb9d22996Chris Lattner  else
71c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines    Diags.setExtensionHandlingBehavior(diag::Severity::Ignored);
721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
73cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko  SmallVector<diag::kind, 10> _Diags;
74c93dc7889644293e318e19d82830ea2acc45b678Dylan Noblesmith  const IntrusiveRefCntPtr< DiagnosticIDs > DiagIDs =
7505272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier    Diags.getDiagnosticIDs();
7605272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier  // We parse the warning options twice.  The first pass sets diagnostic state,
7705272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier  // while the second pass reports warnings/errors.  This has the effect that
7805272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier  // we follow the more canonical "last option wins" paradigm when there are
7905272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier  // conflicting options.
8005272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier  for (unsigned Report = 0, ReportEnd = 2; Report != ReportEnd; ++Report) {
8105272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier    bool SetDiagnostic = (Report == 0);
8208e79d2f075d1326ff7a849fd1bc88dadf99d574Chad Rosier
8308e79d2f075d1326ff7a849fd1bc88dadf99d574Chad Rosier    // If we've set the diagnostic state and are not reporting diagnostics then
8408e79d2f075d1326ff7a849fd1bc88dadf99d574Chad Rosier    // we're done.
8508e79d2f075d1326ff7a849fd1bc88dadf99d574Chad Rosier    if (!SetDiagnostic && !ReportDiags)
8608e79d2f075d1326ff7a849fd1bc88dadf99d574Chad Rosier      break;
8708e79d2f075d1326ff7a849fd1bc88dadf99d574Chad Rosier
8805272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier    for (unsigned i = 0, e = Opts.Warnings.size(); i != e; ++i) {
89176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines      const auto Flavor = diag::Flavor::WarningOrError;
9005272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier      StringRef Opt = Opts.Warnings[i];
91ff1affef282d7146e14c8aa894eb5466a659398cChad Rosier      StringRef OrigOpt = Opts.Warnings[i];
921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
93c8769460f1c03bc321b00f5611f9965e8385e64dHans Wennborg      // Treat -Wformat=0 as an alias for -Wno-format.
94c8769460f1c03bc321b00f5611f9965e8385e64dHans Wennborg      if (Opt == "format=0")
95c8769460f1c03bc321b00f5611f9965e8385e64dHans Wennborg        Opt = "no-format";
96c8769460f1c03bc321b00f5611f9965e8385e64dHans Wennborg
9705272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier      // Check to see if this warning starts with "no-", if so, this is a
9805272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier      // negative form of the option.
9905272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier      bool isPositive = true;
10005272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier      if (Opt.startswith("no-")) {
10105272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier        isPositive = false;
10205272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier        Opt = Opt.substr(3);
1035147e8e0186ec7d4c2c2aeb348c0354c1c3302f9Chris Lattner      }
1041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump
10505272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier      // Figure out how this option affects the warning.  If -Wfoo, map the
10605272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier      // diagnostic to a warning, if -Wno-foo, map it to ignore.
107c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines      diag::Severity Mapping =
108c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines          isPositive ? diag::Severity::Warning : diag::Severity::Ignored;
109c568f1e98938584c0ef0b12ae5018ff7d90a4072Stephen Hines
11005272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier      // -Wsystem-headers is a special case, not driven by the option table.  It
11105272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier      // cannot be controlled with -Werror.
11205272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier      if (Opt == "system-headers") {
11305272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier        if (SetDiagnostic)
11405272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier          Diags.setSuppressSystemWarnings(!isPositive);
1155147e8e0186ec7d4c2c2aeb348c0354c1c3302f9Chris Lattner        continue;
11663a9e0ff79f01a542afaf9b912e3dee3d395ebc5Sebastian Redl      }
11705272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier
11805272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier      // -Weverything is a special case as well.  It implicitly enables all
11905272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier      // warnings, including ones not explicitly in a warning group.
12005272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier      if (Opt == "everything") {
12111583c757bac6ce5c342f2eb572055dd2619a657Argyrios Kyrtzidis        if (SetDiagnostic) {
12211583c757bac6ce5c342f2eb572055dd2619a657Argyrios Kyrtzidis          if (isPositive) {
12311583c757bac6ce5c342f2eb572055dd2619a657Argyrios Kyrtzidis            Diags.setEnableAllWarnings(true);
12411583c757bac6ce5c342f2eb572055dd2619a657Argyrios Kyrtzidis          } else {
12511583c757bac6ce5c342f2eb572055dd2619a657Argyrios Kyrtzidis            Diags.setEnableAllWarnings(false);
126176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines            Diags.setSeverityForAll(Flavor, diag::Severity::Ignored);
12711583c757bac6ce5c342f2eb572055dd2619a657Argyrios Kyrtzidis          }
12811583c757bac6ce5c342f2eb572055dd2619a657Argyrios Kyrtzidis        }
12905272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier        continue;
1304aa8f2bce0f498152d624f748712a991adc23fddDaniel Dunbar      }
13105272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier
13205272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier      // -Werror/-Wno-error is a special case, not controlled by the option
13305272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier      // table. It also has the "specifier" form of -Werror=foo and -Werror-foo.
13405272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier      if (Opt.startswith("error")) {
13505272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier        StringRef Specifier;
13605272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier        if (Opt.size() > 5) {  // Specifier must be present.
13705272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier          if ((Opt[5] != '=' && Opt[5] != '-') || Opt.size() == 6) {
13805272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier            if (Report)
13905272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier              Diags.Report(diag::warn_unknown_warning_specifier)
140ff1affef282d7146e14c8aa894eb5466a659398cChad Rosier                << "-Werror" << ("-W" + OrigOpt.str());
14105272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier            continue;
14205272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier          }
14305272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier          Specifier = Opt.substr(6);
14405272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier        }
14505272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier
14605272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier        if (Specifier.empty()) {
14705272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier          if (SetDiagnostic)
14805272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier            Diags.setWarningsAsErrors(isPositive);
149e663c720063fc9ff9f75bcbe38cd070c73c78b0eChris Lattner          continue;
150e663c720063fc9ff9f75bcbe38cd070c73c78b0eChris Lattner        }
15105272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier
15205272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier        if (SetDiagnostic) {
15305272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier          // Set the warning as error flag for this specifier.
15405272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier          Diags.setDiagnosticGroupWarningAsError(Specifier, isPositive);
155176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        } else if (DiagIDs->getDiagnosticsInGroup(Flavor, Specifier, _Diags)) {
156176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines          EmitUnknownDiagWarning(Diags, Flavor, "-Werror=", Specifier);
15705272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier        }
15805272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier        continue;
159e663c720063fc9ff9f75bcbe38cd070c73c78b0eChris Lattner      }
16005272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier
16105272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier      // -Wfatal-errors is yet another special case.
16205272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier      if (Opt.startswith("fatal-errors")) {
16305272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier        StringRef Specifier;
16405272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier        if (Opt.size() != 12) {
16505272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier          if ((Opt[12] != '=' && Opt[12] != '-') || Opt.size() == 13) {
16605272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier            if (Report)
16705272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier              Diags.Report(diag::warn_unknown_warning_specifier)
168ff1affef282d7146e14c8aa894eb5466a659398cChad Rosier                << "-Wfatal-errors" << ("-W" + OrigOpt.str());
16905272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier            continue;
17005272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier          }
17105272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier          Specifier = Opt.substr(13);
17205272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier        }
173e663c720063fc9ff9f75bcbe38cd070c73c78b0eChris Lattner
17405272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier        if (Specifier.empty()) {
17505272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier          if (SetDiagnostic)
17605272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier            Diags.setErrorsAsFatal(isPositive);
17705272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier          continue;
17805272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier        }
17905272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier
18005272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier        if (SetDiagnostic) {
18105272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier          // Set the error as fatal flag for this specifier.
18205272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier          Diags.setDiagnosticGroupErrorAsFatal(Specifier, isPositive);
183176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        } else if (DiagIDs->getDiagnosticsInGroup(Flavor, Specifier, _Diags)) {
184176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines          EmitUnknownDiagWarning(Diags, Flavor, "-Wfatal-errors=", Specifier);
18505272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier        }
186e663c720063fc9ff9f75bcbe38cd070c73c78b0eChris Lattner        continue;
187e663c720063fc9ff9f75bcbe38cd070c73c78b0eChris Lattner      }
18805272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier
189496cc8eae2c69b8fd36a2b3e815dd0e8207ec493Chad Rosier      if (Report) {
190176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        if (DiagIDs->getDiagnosticsInGroup(Flavor, Opt, _Diags))
191176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines          EmitUnknownDiagWarning(Diags, Flavor, isPositive ? "-W" : "-Wno-",
192176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines                                 Opt);
193176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines      } else {
194176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        Diags.setSeverityForGroup(Flavor, Opt, Mapping);
195176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines      }
196176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    }
197176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
198176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    for (unsigned i = 0, e = Opts.Remarks.size(); i != e; ++i) {
199176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines      StringRef Opt = Opts.Remarks[i];
200176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines      const auto Flavor = diag::Flavor::Remark;
201176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
202176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines      // Check to see if this warning starts with "no-", if so, this is a
203176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines      // negative form of the option.
204176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines      bool IsPositive = !Opt.startswith("no-");
205176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines      if (!IsPositive) Opt = Opt.substr(3);
206176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
207176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines      auto Severity = IsPositive ? diag::Severity::Remark
208176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines                                 : diag::Severity::Ignored;
209176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
210176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines      // -Reverything sets the state of all remarks. Note that all remarks are
211176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines      // in remark groups, so we don't need a separate 'all remarks enabled'
212176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines      // flag.
213176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines      if (Opt == "everything") {
214176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        if (SetDiagnostic)
215176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines          Diags.setSeverityForAll(Flavor, Severity);
216176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        continue;
217176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines      }
218176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
219176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines      if (Report) {
220176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        if (DiagIDs->getDiagnosticsInGroup(Flavor, Opt, _Diags))
221176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines          EmitUnknownDiagWarning(Diags, Flavor, IsPositive ? "-R" : "-Rno-",
222176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines                                 Opt);
22305272a659437fc6ec7fa5a7c3f3fc6eb220a6fa2Chad Rosier      } else {
224176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines        Diags.setSeverityForGroup(Flavor, Opt,
225176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines                                  IsPositive ? diag::Severity::Remark
226176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines                                             : diag::Severity::Ignored);
2274aa8f2bce0f498152d624f748712a991adc23fddDaniel Dunbar      }
2284aa8f2bce0f498152d624f748712a991adc23fddDaniel Dunbar    }
22963a9e0ff79f01a542afaf9b912e3dee3d395ebc5Sebastian Redl  }
23063a9e0ff79f01a542afaf9b912e3dee3d395ebc5Sebastian Redl}
231