Skip to content

Commit f83752d

Browse files
authored
Merge pull request #84870 from hnrklssn/verify-ignore-macro-note
[DiagnosticVerifier] Add -verify-ignore-macro-note
2 parents 0a4b6f0 + da55801 commit f83752d

File tree

6 files changed

+18
-3
lines changed

6 files changed

+18
-3
lines changed

include/swift/Basic/DiagnosticOptions.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ class DiagnosticOptions {
4646
/// allow diagnostics at <unknown>, that is controlled by VerifyIgnoreUnknown.
4747
bool VerifyIgnoreUnrelated = false;
4848

49+
/// Indicates whether to ignore \c diag::in_macro_expansion. This is useful
50+
/// for when they occur in unnamed buffers (such as clang attribute buffers),
51+
/// but VerifyIgnoreUnrelated is too blunt of a tool. Note that notes of this
52+
/// kind are not printed by \c PrintingDiagnosticConsumer.
53+
bool VerifyIgnoreMacroLocationNote = false;
54+
4955
/// Indicates whether diagnostic passes should be skipped.
5056
bool SkipDiagnosticPasses = false;
5157

include/swift/Frontend/DiagnosticVerifier.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,21 @@ class DiagnosticVerifier : public DiagnosticConsumer {
100100
bool AutoApplyFixes;
101101
bool IgnoreUnknown;
102102
bool IgnoreUnrelated;
103+
bool IgnoreMacroLocationNote;
103104
bool UseColor;
104105
ArrayRef<std::string> AdditionalExpectedPrefixes;
105106

106107
public:
107108
explicit DiagnosticVerifier(SourceManager &SM, ArrayRef<unsigned> BufferIDs,
108109
ArrayRef<std::string> AdditionalFilePaths,
109110
bool AutoApplyFixes, bool IgnoreUnknown,
110-
bool IgnoreUnrelated, bool UseColor,
111+
bool IgnoreUnrelated,
112+
bool IgnoreMacroLocationNote, bool UseColor,
111113
ArrayRef<std::string> AdditionalExpectedPrefixes)
112114
: SM(SM), BufferIDs(BufferIDs), AdditionalFilePaths(AdditionalFilePaths),
113115
AutoApplyFixes(AutoApplyFixes), IgnoreUnknown(IgnoreUnknown),
114-
IgnoreUnrelated(IgnoreUnrelated), UseColor(UseColor),
116+
IgnoreUnrelated(IgnoreUnrelated),
117+
IgnoreMacroLocationNote(IgnoreMacroLocationNote), UseColor(UseColor),
115118
AdditionalExpectedPrefixes(AdditionalExpectedPrefixes) {}
116119

117120
virtual void handleDiagnostic(SourceManager &SM,

include/swift/Option/FrontendOptions.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ def verify_ignore_unknown: Flag<["-"], "verify-ignore-unknown">,
179179
HelpText<"Allow diagnostics for '<unknown>' location in verify mode">;
180180
def verify_ignore_unrelated: Flag<["-"], "verify-ignore-unrelated">,
181181
HelpText<"Allow diagnostics in files outside those with expected diagnostics in verify mode">;
182+
def verify_ignore_macro_note: Flag<["-"], "verify-ignore-macro-note">,
183+
HelpText<"Skip verifying notes about macro location">;
182184
def verify_generic_signatures : Separate<["-"], "verify-generic-signatures">,
183185
MetaVarName<"<module-name>">,
184186
HelpText<"Verify the generic signatures in the given module">;

lib/Frontend/CompilerInvocation.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2614,6 +2614,7 @@ static bool ParseDiagnosticArgs(DiagnosticOptions &Opts, ArgList &Args,
26142614
Opts.VerifyMode = DiagnosticOptions::VerifyAndApplyFixes;
26152615
Opts.VerifyIgnoreUnknown |= Args.hasArg(OPT_verify_ignore_unknown);
26162616
Opts.VerifyIgnoreUnrelated |= Args.hasArg(OPT_verify_ignore_unrelated);
2617+
Opts.VerifyIgnoreMacroLocationNote |= Args.hasArg(OPT_verify_ignore_macro_note);
26172618
Opts.SkipDiagnosticPasses |= Args.hasArg(OPT_disable_diagnostic_passes);
26182619
Opts.ShowDiagnosticsAfterFatalError |=
26192620
Args.hasArg(OPT_show_diagnostics_after_fatal);

lib/Frontend/DiagnosticVerifier.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1502,6 +1502,8 @@ void DiagnosticVerifier::handleDiagnostic(SourceManager &SM,
15021502
// because there's no reason to verify them.
15031503
if (Info.ID == diag::verify_encountered_fatal.ID)
15041504
return;
1505+
if (IgnoreMacroLocationNote && Info.ID == diag::in_macro_expansion.ID)
1506+
return;
15051507
SmallVector<CapturedFixItInfo, 2> fixIts;
15061508
for (const auto &fixIt : Info.FixIts) {
15071509
fixIts.emplace_back(SM, fixIt);

lib/Frontend/Frontend.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,8 @@ bool CompilerInstance::setupDiagnosticVerifierIfNeeded() {
435435
SourceMgr, InputSourceCodeBufferIDs, diagOpts.AdditionalVerifierFiles,
436436
diagOpts.VerifyMode == DiagnosticOptions::VerifyAndApplyFixes,
437437
diagOpts.VerifyIgnoreUnknown, diagOpts.VerifyIgnoreUnrelated,
438-
diagOpts.UseColor, diagOpts.AdditionalDiagnosticVerifierPrefixes);
438+
diagOpts.VerifyIgnoreMacroLocationNote, diagOpts.UseColor,
439+
diagOpts.AdditionalDiagnosticVerifierPrefixes);
439440

440441
addDiagnosticConsumer(DiagVerifier.get());
441442
}

0 commit comments

Comments
 (0)