forked from OSchip/llvm-project
clang/Modules: Clean up modules on error in ReadAST
ReadASTBlock and ReadASTExtensions can both return failures. Be consistent and remove all the just-loaded modules, just like when ReadASTCore returns failures. https://reviews.llvm.org/D70055
This commit is contained in:
parent
6c86d6efaf
commit
c46b3a2abd
|
@ -4176,17 +4176,8 @@ ASTReader::ASTReadResult ASTReader::ReadAST(StringRef FileName,
|
|||
PreviousGeneration = incrementGeneration(*ContextObj);
|
||||
|
||||
unsigned NumModules = ModuleMgr.size();
|
||||
SmallVector<ImportedModule, 4> Loaded;
|
||||
switch (ASTReadResult ReadResult =
|
||||
ReadASTCore(FileName, Type, ImportLoc,
|
||||
/*ImportedBy=*/nullptr, Loaded, 0, 0,
|
||||
ASTFileSignature(), ClientLoadCapabilities)) {
|
||||
case Failure:
|
||||
case Missing:
|
||||
case OutOfDate:
|
||||
case VersionMismatch:
|
||||
case ConfigurationMismatch:
|
||||
case HadErrors: {
|
||||
auto removeModulesAndReturn = [&](ASTReadResult ReadResult) {
|
||||
assert(ReadResult && "expected to return error");
|
||||
ModuleMgr.removeModules(ModuleMgr.begin() + NumModules,
|
||||
PP.getLangOpts().Modules
|
||||
? &PP.getHeaderSearchInfo().getModuleMap()
|
||||
|
@ -4197,7 +4188,20 @@ ASTReader::ASTReadResult ASTReader::ReadAST(StringRef FileName,
|
|||
GlobalIndex.reset();
|
||||
ModuleMgr.setGlobalIndex(nullptr);
|
||||
return ReadResult;
|
||||
}
|
||||
};
|
||||
|
||||
SmallVector<ImportedModule, 4> Loaded;
|
||||
switch (ASTReadResult ReadResult =
|
||||
ReadASTCore(FileName, Type, ImportLoc,
|
||||
/*ImportedBy=*/nullptr, Loaded, 0, 0,
|
||||
ASTFileSignature(), ClientLoadCapabilities)) {
|
||||
case Failure:
|
||||
case Missing:
|
||||
case OutOfDate:
|
||||
case VersionMismatch:
|
||||
case ConfigurationMismatch:
|
||||
case HadErrors:
|
||||
return removeModulesAndReturn(ReadResult);
|
||||
case Success:
|
||||
break;
|
||||
}
|
||||
|
@ -4211,12 +4215,12 @@ ASTReader::ASTReadResult ASTReader::ReadAST(StringRef FileName,
|
|||
|
||||
// Read the AST block.
|
||||
if (ASTReadResult Result = ReadASTBlock(F, ClientLoadCapabilities))
|
||||
return Result;
|
||||
return removeModulesAndReturn(Result);
|
||||
|
||||
// Read the extension blocks.
|
||||
while (!SkipCursorToBlock(F.Stream, EXTENSION_BLOCK_ID)) {
|
||||
if (ASTReadResult Result = ReadExtensionBlock(F))
|
||||
return Result;
|
||||
return removeModulesAndReturn(Result);
|
||||
}
|
||||
|
||||
// Once read, set the ModuleFile bit base offset and update the size in
|
||||
|
|
Loading…
Reference in New Issue