suppress non-primary errors if there is no responsible primary

This commit is contained in:
David Ungar
2019-04-03 16:19:45 -07:00
parent ee449ae52e
commit d0330523d0
3 changed files with 48 additions and 13 deletions

View File

@@ -1540,12 +1540,30 @@ createDispatchingDiagnosticConsumerIfNeeded(
inputsAndOutputs.forEachInputProducingSupplementaryOutput(
[&](const InputFile &input) -> bool {
if (auto consumer = maybeCreateConsumerForDiagnosticsFrom(input)) {
assert(consumer && "Consumer should always be non-null");
if (auto consumer = maybeCreateConsumerForDiagnosticsFrom(input))
subconsumers.emplace_back(input.file(), std::move(consumer));
}
return false;
});
// For batch mode, the compiler must sometimes swallow diagnostics pertaining to
// non-primary files in order to avoid Xcode showing the same diagnostic
// multiple times. So, create a diagnostic "eater" for those non-primary
// files.
//
// This routine gets called for \c createJSONFixItDiagnosticConsumerIfNeeded
// in cases where no primary subconsumers are created.
// Don't bother to create non-primary subconsumers if there aren't any primary
// ones.
//
// To avoid introducing bugs into WMO or single-file modes, test for multiple
// primaries.
if (!subconsumers.empty() && inputsAndOutputs.hasMultiplePrimaryInputs()) {
inputsAndOutputs.forEachNonPrimaryInput(
[&](const InputFile &input) -> bool {
subconsumers.emplace_back(input.file(), nullptr);
return false;
});
}
return FileSpecificDiagnosticConsumer::consolidateSubconsumers(subconsumers);
}