|
19 | 19 | #include "swift/AST/DiagnosticEngine.h"
|
20 | 20 | #include "swift/Basic/Defer.h"
|
21 | 21 | #include "swift/Basic/SourceManager.h"
|
| 22 | +#include "llvm/ADT/STLExtras.h" |
22 | 23 | #include "llvm/ADT/StringRef.h"
|
23 | 24 | #include "llvm/ADT/StringSet.h"
|
24 | 25 | #include "llvm/Support/Debug.h"
|
@@ -116,6 +117,20 @@ FileSpecificDiagnosticConsumer::consumerForLocation(SourceManager &SM,
|
116 | 117 | // FileSpecificDiagnosticConsumer to be set up before the source files are
|
117 | 118 | // actually loaded.
|
118 | 119 | if (ConsumersOrderedByRange.empty()) {
|
| 120 | + |
| 121 | + // It's possible to get here while a bridging header PCH is being |
| 122 | + // attached-to, if there's some sort of AST-reader warning or error, which |
| 123 | + // happens before CompilerInstance::setUpInputs(), at which point _no_ |
| 124 | + // source buffers are loaded in yet. In that case we return nullptr, rather |
| 125 | + // than trying to build a nonsensical map (and actually crashing since we |
| 126 | + // can't find buffers for the inputs). |
| 127 | + assert(!SubConsumers.empty()); |
| 128 | + if (!SM.getIDForBufferIdentifier(SubConsumers.begin()->first).hasValue()) { |
| 129 | + assert(llvm::none_of(SubConsumers, [&](const ConsumerPair &pair) { |
| 130 | + return SM.getIDForBufferIdentifier(pair.first).hasValue(); |
| 131 | + })); |
| 132 | + return nullptr; |
| 133 | + } |
119 | 134 | auto *mutableThis = const_cast<FileSpecificDiagnosticConsumer*>(this);
|
120 | 135 | mutableThis->computeConsumersOrderedByRange(SM);
|
121 | 136 | }
|
|
0 commit comments