|
44 | 44 | #include "clang/Basic/ASTSourceDescriptor.h" |
45 | 45 | #include "clang/Basic/CommentOptions.h" |
46 | 46 | #include "clang/Basic/Diagnostic.h" |
47 | | -#include "clang/Basic/DiagnosticError.h" |
48 | 47 | #include "clang/Basic/DiagnosticIDs.h" |
49 | 48 | #include "clang/Basic/DiagnosticOptions.h" |
50 | 49 | #include "clang/Basic/DiagnosticSema.h" |
@@ -1552,30 +1551,27 @@ void ASTReader::Error(unsigned DiagID, StringRef Arg1, StringRef Arg2, |
1552 | 1551 | Diag(DiagID) << Arg1 << Arg2 << Arg3; |
1553 | 1552 | } |
1554 | 1553 |
|
| 1554 | +namespace { |
| 1555 | +struct AlreadyReportedDiagnosticError |
| 1556 | + : llvm::ErrorInfo<AlreadyReportedDiagnosticError> { |
| 1557 | + static char ID; |
| 1558 | + |
| 1559 | + void log(raw_ostream &OS) const override { |
| 1560 | + llvm_unreachable("reporting an already-reported diagnostic error"); |
| 1561 | + } |
| 1562 | + |
| 1563 | + std::error_code convertToErrorCode() const override { |
| 1564 | + return llvm::inconvertibleErrorCode(); |
| 1565 | + } |
| 1566 | +}; |
| 1567 | + |
| 1568 | +char AlreadyReportedDiagnosticError::ID = 0; |
| 1569 | +} // namespace |
| 1570 | + |
1555 | 1571 | void ASTReader::Error(llvm::Error &&Err) const { |
1556 | | - llvm::Error RemainingErr = |
1557 | | - handleErrors(std::move(Err), [this](const DiagnosticError &E) { |
1558 | | - auto Diag = E.getDiagnostic().second; |
1559 | | - |
1560 | | - // Ideally we'd just emit it, but have to handle a possible in-flight |
1561 | | - // diagnostic. Note that the location is currently ignored as well. |
1562 | | - auto NumArgs = Diag.getStorage()->NumDiagArgs; |
1563 | | - assert(NumArgs <= 3 && "Can only have up to 3 arguments"); |
1564 | | - StringRef Arg1, Arg2, Arg3; |
1565 | | - switch (NumArgs) { |
1566 | | - case 3: |
1567 | | - Arg3 = Diag.getStringArg(2); |
1568 | | - [[fallthrough]]; |
1569 | | - case 2: |
1570 | | - Arg2 = Diag.getStringArg(1); |
1571 | | - [[fallthrough]]; |
1572 | | - case 1: |
1573 | | - Arg1 = Diag.getStringArg(0); |
1574 | | - } |
1575 | | - Error(Diag.getDiagID(), Arg1, Arg2, Arg3); |
1576 | | - }); |
1577 | | - if (RemainingErr) |
1578 | | - Error(toString(std::move(RemainingErr))); |
| 1572 | + handleAllErrors( |
| 1573 | + std::move(Err), [](AlreadyReportedDiagnosticError &) {}, |
| 1574 | + [&](llvm::ErrorInfoBase &E) { return Error(E.message()); }); |
1579 | 1575 | } |
1580 | 1576 |
|
1581 | 1577 | //===----------------------------------------------------------------------===// |
@@ -3349,8 +3345,6 @@ ASTReader::ReadControlBlock(ModuleFile &F, |
3349 | 3345 | if (isDiagnosedResult(Result, Capabilities) || recompilingFinalized) |
3350 | 3346 | Diag(diag::note_module_file_imported_by) |
3351 | 3347 | << F.FileName << !F.ModuleName.empty() << F.ModuleName; |
3352 | | - if (recompilingFinalized) |
3353 | | - Diag(diag::note_module_file_conflict); |
3354 | 3348 |
|
3355 | 3349 | switch (Result) { |
3356 | 3350 | case Failure: return Failure; |
@@ -4440,6 +4434,7 @@ ASTReader::ReadModuleMapFileBlock(RecordData &Record, ModuleFile &F, |
4440 | 4434 | // This module was defined by an imported (explicit) module. |
4441 | 4435 | Diag(diag::err_module_file_conflict) << F.ModuleName << F.FileName |
4442 | 4436 | << ASTFE->getName(); |
| 4437 | + // TODO: Add a note with the module map paths if they differ. |
4443 | 4438 | } else { |
4444 | 4439 | // This module was built with a different module map. |
4445 | 4440 | Diag(diag::err_imported_module_not_found) |
@@ -6105,14 +6100,21 @@ llvm::Error ASTReader::ReadSubmoduleBlock(ModuleFile &F, |
6105 | 6100 | if (OptionalFileEntryRef CurFile = CurrentModule->getASTFile()) { |
6106 | 6101 | // Don't emit module relocation error if we have -fno-validate-pch |
6107 | 6102 | if (!bool(PP.getPreprocessorOpts().DisablePCHOrModuleValidation & |
6108 | | - DisableValidationForModuleKind::Module) && |
6109 | | - CurFile != F.File) { |
6110 | | - auto ConflictError = |
6111 | | - PartialDiagnostic(diag::err_module_file_conflict, |
6112 | | - ContextObj->DiagAllocator) |
| 6103 | + DisableValidationForModuleKind::Module)) { |
| 6104 | + assert(CurFile != F.File && "ModuleManager did not de-duplicate"); |
| 6105 | + |
| 6106 | + Diag(diag::err_module_file_conflict) |
6113 | 6107 | << CurrentModule->getTopLevelModuleName() << CurFile->getName() |
6114 | 6108 | << F.File.getName(); |
6115 | | - return DiagnosticError::create(CurrentImportLoc, ConflictError); |
| 6109 | + |
| 6110 | + auto CurModMapFile = |
| 6111 | + ModMap.getContainingModuleMapFile(CurrentModule); |
| 6112 | + auto ModMapFile = FileMgr.getOptionalFileRef(F.ModuleMapPath); |
| 6113 | + if (CurModMapFile && ModMapFile && CurModMapFile != ModMapFile) |
| 6114 | + Diag(diag::note_module_file_conflict) |
| 6115 | + << CurModMapFile->getName() << ModMapFile->getName(); |
| 6116 | + |
| 6117 | + return llvm::make_error<AlreadyReportedDiagnosticError>(); |
6116 | 6118 | } |
6117 | 6119 | } |
6118 | 6120 |
|
|
0 commit comments