Skip to content

Commit 379b97f

Browse files
committed
ARCMigrate: simplify diagnostic handling
Recent enhancements in the diagnostics engine mean that TransformActions::report() no longer needs to duplicate this suppression logic. That's great because the old code was flawed and would have attached notes to the wrong primary diagnostic in non-trivial use. With these changes it becomes safe to use reportNote() freely in the migration tool. llvm-svn: 212191
1 parent 292fa19 commit 379b97f

File tree

4 files changed

+9
-15
lines changed

4 files changed

+9
-15
lines changed

clang/include/clang/Basic/Diagnostic.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ class ShowInSystemHeader {
8989
bit ShowInSystemHeader = 1;
9090
}
9191

92+
class SuppressInSystemHeader {
93+
bit ShowInSystemHeader = 0;
94+
}
95+
9296
// FIXME: ExtWarn and Extension should also be SFINAEFailure by default.
9397
class Error<string str> : Diagnostic<str, CLASS_ERROR, SEV_Error>, SFINAEFailure {
9498
bit ShowInSystemHeader = 1;

clang/include/clang/Basic/DiagnosticCommonKinds.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def err_module_file_conflict : Error<"module '%0' found in both '%1' and '%2'">;
138138

139139
// TransformActions
140140
// TODO: Use a custom category name to distinguish rewriter errors.
141-
def err_mt_message : Error<"[rewriter] %0">;
141+
def err_mt_message : Error<"[rewriter] %0">, SuppressInSystemHeader;
142142
def warn_mt_message : Warning<"[rewriter] %0">;
143143
def note_mt_message : Note<"[rewriter] %0">;
144144

clang/lib/ARCMigrate/Internals.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ void writeARCDiagsToPlist(const std::string &outPath,
4848
class TransformActions {
4949
DiagnosticsEngine &Diags;
5050
CapturedDiagList &CapturedDiags;
51-
bool ReportedErrors;
5251
void *Impl; // TransformActionsImpl.
5352

5453
public:
@@ -104,7 +103,9 @@ class TransformActions {
104103
void reportNote(StringRef note, SourceLocation loc,
105104
SourceRange range = SourceRange());
106105

107-
bool hasReportedErrors() const { return ReportedErrors; }
106+
bool hasReportedErrors() const {
107+
return Diags.hasUnrecoverableErrorOccurred();
108+
}
108109

109110
class RewriteReceiver {
110111
public:

clang/lib/ARCMigrate/TransformActions.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ TransformActions::RewriteReceiver::~RewriteReceiver() { }
601601
TransformActions::TransformActions(DiagnosticsEngine &diag,
602602
CapturedDiagList &capturedDiags,
603603
ASTContext &ctx, Preprocessor &PP)
604-
: Diags(diag), CapturedDiags(capturedDiags), ReportedErrors(false) {
604+
: Diags(diag), CapturedDiags(capturedDiags) {
605605
Impl = new TransformActionsImpl(capturedDiags, ctx, PP);
606606
}
607607

@@ -677,17 +677,6 @@ DiagnosticBuilder TransformActions::report(SourceLocation loc, unsigned diagId,
677677
SourceRange range) {
678678
assert(!static_cast<TransformActionsImpl *>(Impl)->isInTransaction() &&
679679
"Errors should be emitted out of a transaction");
680-
681-
SourceManager &SM = static_cast<TransformActionsImpl *>(Impl)
682-
->getASTContext()
683-
.getSourceManager();
684-
DiagnosticsEngine::Level L = Diags.getDiagnosticLevel(diagId, loc);
685-
// TODO: Move this check to the caller to ensure consistent note attachments.
686-
if (L == DiagnosticsEngine::Ignored ||
687-
SM.isInSystemHeader(SM.getExpansionLoc(loc)))
688-
return DiagnosticBuilder::getEmpty();
689-
if (L >= DiagnosticsEngine::Error)
690-
ReportedErrors = true;
691680
return Diags.Report(loc, diagId) << range;
692681
}
693682

0 commit comments

Comments
 (0)