[PATCH] D70055: clang/Modules: Clean up modules on error in ReadAST
Duncan P. N. Exon Smith via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Nov 10 11:44:23 PST 2019
dexonsmith created this revision.
dexonsmith added reviewers: bruno, aprantl, Bigcheese.
Herald added a subscriber: ributzka.
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
Files:
clang/lib/Serialization/ASTReader.cpp
Index: clang/lib/Serialization/ASTReader.cpp
===================================================================
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -4174,17 +4174,8 @@
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()
@@ -4195,7 +4186,20 @@
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;
}
@@ -4210,12 +4214,12 @@
// 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70055.228613.patch
Type: text/x-patch
Size: 2159 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191110/1e889f4b/attachment-0001.bin>
More information about the cfe-commits
mailing list