Skip to content

Commit d68ca8d

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 fbad380 commit d68ca8d

File tree

7 files changed

+39
-2
lines changed

7 files changed

+39
-2
lines changed

include/swift/AST/DiagnosticEngine.h

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

617617
/// Don't emit any warnings
618618
bool suppressWarnings = false;
619+
620+
/// Don't emit any notes
621+
bool suppressNotes = false;
619622

620623
/// Don't emit any remarks
621624
bool suppressRemarks = false;
@@ -663,6 +666,10 @@ namespace swift {
663666
void setSuppressWarnings(bool val) { suppressWarnings = val; }
664667
bool getSuppressWarnings() const { return suppressWarnings; }
665668

669+
/// Whether to skip emitting notes
670+
void setSuppressNotes(bool val) { suppressNotes = val; }
671+
bool getSuppressNotes() const { return suppressNotes; }
672+
666673
/// Whether to skip emitting remarks
667674
void setSuppressRemarks(bool val) { suppressRemarks = val; }
668675
bool getSuppressRemarks() const { return suppressRemarks; }
@@ -708,6 +715,7 @@ namespace swift {
708715
void swap(DiagnosticState &other) {
709716
std::swap(showDiagnosticsAfterFatalError, other.showDiagnosticsAfterFatalError);
710717
std::swap(suppressWarnings, other.suppressWarnings);
718+
std::swap(suppressNotes, other.suppressNotes);
711719
std::swap(suppressRemarks, other.suppressRemarks);
712720
std::swap(warningsAsErrors, other.warningsAsErrors);
713721
std::swap(fatalErrorOccurred, other.fatalErrorOccurred);
@@ -904,6 +912,12 @@ namespace swift {
904912
return state.getSuppressWarnings();
905913
}
906914

915+
/// Whether to skip emitting notes
916+
void setSuppressNotes(bool val) { state.setSuppressNotes(val); }
917+
bool getSuppressNotes() const {
918+
return state.getSuppressNotes();
919+
}
920+
907921
/// Whether to skip emitting remarks
908922
void setSuppressRemarks(bool val) { state.setSuppressRemarks(val); }
909923
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ struct InterfaceSubContextDelegateImpl : InterfaceSubContextDelegate {
643643
const LangOptions &LangOpts,
644644
const ClangImporterOptions &clangImporterOpts,
645645
const CASOptions &casOpts,
646-
bool suppressRemarks);
646+
bool suppressNotes, bool suppressRemarks);
647647
bool extractSwiftInterfaceVersionAndArgs(CompilerInvocation &subInvocation,
648648
DiagnosticEngine &subInstanceDiags,
649649
SwiftInterfaceInfo &interfaceInfo,

include/swift/Option/Options.td

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

932+
def suppress_notes : Flag<["-"], "suppress-notes">,
933+
Flags<[FrontendOption]>,
934+
HelpText<"Suppress all notes">;
935+
932936
def suppress_remarks : Flag<["-"], "suppress-remarks">,
933937
Flags<[FrontendOption]>,
934938
HelpText<"Suppress all remarks">;

lib/AST/DiagnosticEngine.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,6 +1345,11 @@ DiagnosticState::determineBehavior(const Diagnostic &diag) const {
13451345
if (suppressWarnings)
13461346
lvl = DiagnosticBehavior::Ignore;
13471347
}
1348+
1349+
if (lvl == DiagnosticBehavior::Note) {
1350+
if (suppressNotes)
1351+
lvl = DiagnosticBehavior::Ignore;
1352+
}
13481353

13491354
if (lvl == DiagnosticBehavior::Remark) {
13501355
if (suppressRemarks)

lib/Frontend/CompilerInvocation.cpp

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

26542654
Opts.SuppressWarnings |= Args.hasArg(OPT_suppress_warnings);
2655+
Opts.SuppressNotes |= Args.hasArg(OPT_suppress_notes);
26552656
Opts.SuppressRemarks |= Args.hasArg(OPT_suppress_remarks);
26562657
for (const Arg *arg : Args.filtered(OPT_warning_treating_Group)) {
26572658
Opts.WarningsAsErrorsRules.push_back([&] {
@@ -2732,6 +2733,9 @@ static void configureDiagnosticEngine(
27322733
if (Options.SuppressWarnings) {
27332734
Diagnostics.setSuppressWarnings(true);
27342735
}
2736+
if (Options.SuppressNotes) {
2737+
Diagnostics.setSuppressNotes(true);
2738+
}
27352739
if (Options.SuppressRemarks) {
27362740
Diagnostics.setSuppressRemarks(true);
27372741
}

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1663,7 +1663,7 @@ void InterfaceSubContextDelegateImpl::inheritOptionsForBuildingInterface(
16631663
FrontendOptions::ActionType requestedAction,
16641664
const SearchPathOptions &SearchPathOpts, const LangOptions &LangOpts,
16651665
const ClangImporterOptions &clangImporterOpts, const CASOptions &casOpts,
1666-
bool suppressRemarks) {
1666+
bool suppressNotes, bool suppressRemarks) {
16671667
GenericArgs.push_back("-frontend");
16681668
// Start with a genericSubInvocation that copies various state from our
16691669
// invoking ASTContext.
@@ -1752,6 +1752,12 @@ void InterfaceSubContextDelegateImpl::inheritOptionsForBuildingInterface(
17521752
genericSubInvocation.getDiagnosticOptions().SuppressWarnings = true;
17531753
GenericArgs.push_back("-suppress-warnings");
17541754

1755+
// Inherit the parent invocation's setting on whether to suppress remarks
1756+
if (suppressNotes) {
1757+
genericSubInvocation.getDiagnosticOptions().SuppressNotes = true;
1758+
GenericArgs.push_back("-suppress-notes");
1759+
}
1760+
17551761
// Inherit the parent invocation's setting on whether to suppress remarks
17561762
if (suppressRemarks) {
17571763
genericSubInvocation.getDiagnosticOptions().SuppressRemarks = true;
@@ -1863,6 +1869,7 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
18631869
genericSubInvocation.setMainExecutablePath(LoaderOpts.mainExecutablePath);
18641870
inheritOptionsForBuildingInterface(LoaderOpts.requestedAction, searchPathOpts,
18651871
langOpts, clangImporterOpts, casOpts,
1872+
Diags->getSuppressNotes(),
18661873
Diags->getSuppressRemarks());
18671874
// Configure front-end input.
18681875
auto &SubFEOpts = genericSubInvocation.getFrontendOptions();

0 commit comments

Comments
 (0)