Skip to content

Commit aa0687a

Browse files
author
David Ungar
committed
Typo and handle recursive RAII case.
1 parent c8cd0f3 commit aa0687a

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/AST/DiagnosticConsumer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ FileSpecificDiagnosticConsumer::subconsumerForLocation(SourceManager &SM,
119119
return None;
120120

121121
// What if a there's a FileSpecificDiagnosticConsumer but there are no
122-
// subconsumers in it? (This situation obtains for the fix-its
122+
// subconsumers in it? (This situation occurs for the fix-its
123123
// FileSpecificDiagnosticConsumer.) In such a case, bail out now.
124124
if (Subconsumers.empty())
125125
return None;

lib/AST/DiagnosticEngine.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,8 +849,16 @@ const char *DiagnosticEngine::diagnosticStringFor(const DiagID id) {
849849

850850
void DiagnosticEngine::setBufferIndirectlyCausingDiagnosticToInput(
851851
SourceLoc loc) {
852+
// If in the future, nested BufferIndirectlyCausingDiagnosticRAII need be
853+
// supported, the compiler will need a stack for
854+
// bufferIndirectlyCausingDiagnostic.
855+
assert(bufferIndirectlyCausingDiagnostic.isInvalid() &&
856+
"Buffer should not already be set.");
852857
bufferIndirectlyCausingDiagnostic = loc;
858+
assert(bufferIndirectlyCausingDiagnostic.isValid() &&
859+
"Buffer must be valid for previous assertion to work.");
853860
}
861+
854862
void DiagnosticEngine::resetBufferIndirectlyCausingDiagnostic() {
855863
bufferIndirectlyCausingDiagnostic = SourceLoc();
856864
}
@@ -873,5 +881,6 @@ BufferIndirectlyCausingDiagnosticRAII::BufferIndirectlyCausingDiagnosticRAII(
873881
if (!id)
874882
return;
875883
auto loc = SF.getASTContext().SourceMgr.getLocForBufferStart(*id);
876-
Diags.setBufferIndirectlyCausingDiagnosticToInput(loc);
884+
if (loc.isValid())
885+
Diags.setBufferIndirectlyCausingDiagnosticToInput(loc);
877886
}

0 commit comments

Comments
 (0)