Skip to content

Commit d2fe940

Browse files
committed
[Diagnostics] Add -suppress-notes flag
We already have -suppress-warnings and -suppress-remarks; this patch adds support for suppressing notes too. Doing so is useful for -verify tests where we don't really care about the emitted notes.
1 parent dbbdfce commit d2fe940

File tree

7 files changed

+40
-1
lines changed

7 files changed

+40
-1
lines changed

include/swift/AST/DiagnosticEngine.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,9 @@ namespace swift {
596596

597597
/// Don't emit any warnings
598598
bool suppressWarnings = false;
599+
600+
/// Don't emit any notes
601+
bool suppressNotes = false;
599602

600603
/// Don't emit any remarks
601604
bool suppressRemarks = false;
@@ -643,6 +646,10 @@ namespace swift {
643646
void setSuppressWarnings(bool val) { suppressWarnings = val; }
644647
bool getSuppressWarnings() const { return suppressWarnings; }
645648

649+
/// Whether to skip emitting notes
650+
void setSuppressNotes(bool val) { suppressNotes = val; }
651+
bool getSuppressNotes() const { return suppressNotes; }
652+
646653
/// Whether to skip emitting remarks
647654
void setSuppressRemarks(bool val) { suppressRemarks = val; }
648655
bool getSuppressRemarks() const { return suppressRemarks; }
@@ -684,6 +691,7 @@ namespace swift {
684691
void swap(DiagnosticState &other) {
685692
std::swap(showDiagnosticsAfterFatalError, other.showDiagnosticsAfterFatalError);
686693
std::swap(suppressWarnings, other.suppressWarnings);
694+
std::swap(suppressNotes, other.suppressNotes);
687695
std::swap(suppressRemarks, other.suppressRemarks);
688696
std::swap(warningsAsErrors, other.warningsAsErrors);
689697
std::swap(fatalErrorOccurred, other.fatalErrorOccurred);
@@ -880,6 +888,12 @@ namespace swift {
880888
return state.getSuppressWarnings();
881889
}
882890

891+
/// Whether to skip emitting notes
892+
void setSuppressNotes(bool val) { state.setSuppressNotes(val); }
893+
bool getSuppressNotes() const {
894+
return state.getSuppressNotes();
895+
}
896+
883897
/// Whether to skip emitting remarks
884898
void setSuppressRemarks(bool val) { state.setSuppressRemarks(val); }
885899
bool getSuppressRemarks() const {

include/swift/Basic/DiagnosticOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ class DiagnosticOptions {
5858
/// Suppress all warnings
5959
bool SuppressWarnings = false;
6060

61+
/// Suppress all notes
62+
bool SuppressNotes = false;
63+
6164
/// Suppress all remarks
6265
bool SuppressRemarks = false;
6366

include/swift/Frontend/ModuleInterfaceLoader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,7 @@ struct InterfaceSubContextDelegateImpl : InterfaceSubContextDelegate {
677677
const LangOptions &LangOpts,
678678
const ClangImporterOptions &clangImporterOpts,
679679
const CASOptions &casOpts,
680+
bool suppressNotes,
680681
bool suppressRemarks,
681682
RequireOSSAModules_t requireOSSAModules);
682683
bool extractSwiftInterfaceVersionAndArgs(CompilerInvocation &subInvocation,

include/swift/Option/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,10 @@ def Wwarning : Separate<["-"], "Wwarning">,
912912
MetaVarName<"<diagnostic_group>">,
913913
HelpText<"Treat this warning group as warning">;
914914

915+
def suppress_notes : Flag<["-"], "suppress-notes">,
916+
Flags<[FrontendOption]>,
917+
HelpText<"Suppress all notes">;
918+
915919
def suppress_remarks : Flag<["-"], "suppress-remarks">,
916920
Flags<[FrontendOption]>,
917921
HelpText<"Suppress all remarks">;

lib/AST/DiagnosticEngine.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,6 +1330,11 @@ DiagnosticState::determineBehavior(const Diagnostic &diag) const {
13301330
if (suppressWarnings)
13311331
lvl = DiagnosticBehavior::Ignore;
13321332
}
1333+
1334+
if (lvl == DiagnosticBehavior::Note) {
1335+
if (suppressNotes)
1336+
lvl = DiagnosticBehavior::Ignore;
1337+
}
13331338

13341339
if (lvl == DiagnosticBehavior::Remark) {
13351340
if (suppressRemarks)

lib/Frontend/CompilerInvocation.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2623,6 +2623,7 @@ static bool ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args,
26232623
}
26242624

26252625
Opts.SuppressWarnings |= Args.hasArg(OPT_suppress_warnings);
2626+
Opts.SuppressNotes |= Args.hasArg(OPT_suppress_notes);
26262627
Opts.SuppressRemarks |= Args.hasArg(OPT_suppress_remarks);
26272628
for (const Arg *arg : Args.filtered(OPT_warning_treating_Group)) {
26282629
Opts.WarningsAsErrorsRules.push_back([&] {
@@ -2703,6 +2704,9 @@ static void configureDiagnosticEngine(
27032704
if (Options.SuppressWarnings) {
27042705
Diagnostics.setSuppressWarnings(true);
27052706
}
2707+
if (Options.SuppressNotes) {
2708+
Diagnostics.setSuppressNotes(true);
2709+
}
27062710
if (Options.SuppressRemarks) {
27072711
Diagnostics.setSuppressRemarks(true);
27082712
}

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1657,7 +1657,8 @@ void InterfaceSubContextDelegateImpl::inheritOptionsForBuildingInterface(
16571657
FrontendOptions::ActionType requestedAction,
16581658
const SearchPathOptions &SearchPathOpts, const LangOptions &LangOpts,
16591659
const ClangImporterOptions &clangImporterOpts, const CASOptions &casOpts,
1660-
bool suppressRemarks, RequireOSSAModules_t RequireOSSAModules) {
1660+
bool suppressNotes, bool suppressRemarks,
1661+
RequireOSSAModules_t RequireOSSAModules) {
16611662
GenericArgs.push_back("-frontend");
16621663
// Start with a genericSubInvocation that copies various state from our
16631664
// invoking ASTContext.
@@ -1746,6 +1747,12 @@ void InterfaceSubContextDelegateImpl::inheritOptionsForBuildingInterface(
17461747
genericSubInvocation.getDiagnosticOptions().SuppressWarnings = true;
17471748
GenericArgs.push_back("-suppress-warnings");
17481749

1750+
// Inherit the parent invocation's setting on whether to suppress remarks
1751+
if (suppressNotes) {
1752+
genericSubInvocation.getDiagnosticOptions().SuppressNotes = true;
1753+
GenericArgs.push_back("-suppress-notes");
1754+
}
1755+
17491756
// Inherit the parent invocation's setting on whether to suppress remarks
17501757
if (suppressRemarks) {
17511758
genericSubInvocation.getDiagnosticOptions().SuppressRemarks = true;
@@ -1863,6 +1870,7 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
18631870
genericSubInvocation.setMainExecutablePath(LoaderOpts.mainExecutablePath);
18641871
inheritOptionsForBuildingInterface(LoaderOpts.requestedAction, searchPathOpts,
18651872
langOpts, clangImporterOpts, casOpts,
1873+
Diags->getSuppressNotes(),
18661874
Diags->getSuppressRemarks(),
18671875
requireOSSAModules);
18681876
// Configure front-end input.

0 commit comments

Comments
 (0)