diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-09-09 01:14:04 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-09-09 01:14:04 +0000 |
commit | 6d9bc278eff5aea217afcaa0c58a4ab74e592804 (patch) | |
tree | 7fba890a2b14f952ac5d0e1f8e273341091f7e2a /clang/lib/Frontend/FrontendAction.cpp | |
parent | 4b82f9c37ade37516eeae82d3599da84eb1551e7 (diff) | |
download | bcm5719-llvm-6d9bc278eff5aea217afcaa0c58a4ab74e592804.tar.gz bcm5719-llvm-6d9bc278eff5aea217afcaa0c58a4ab74e592804.zip |
Fix ownership of the MemoryBuffer in a FrontendInputFile.
This fixes a possible crash on certain kinds of corrupted AST file, but
checking in an AST file corrupted in just the right way will be a maintenance
nightmare because the format changes frequently.
llvm-svn: 312851
Diffstat (limited to 'clang/lib/Frontend/FrontendAction.cpp')
-rw-r--r-- | clang/lib/Frontend/FrontendAction.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp index 704d5150985..52e2799deb5 100644 --- a/clang/lib/Frontend/FrontendAction.cpp +++ b/clang/lib/Frontend/FrontendAction.cpp @@ -754,10 +754,11 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, goto failure; // Reinitialize the main file entry to refer to the new input. - if (!CI.InitializeSourceManager(FrontendInputFile( - Buffer.release(), Input.getKind().withFormat(InputKind::Source), - CurrentModule->IsSystem))) - goto failure; + auto Kind = CurrentModule->IsSystem ? SrcMgr::C_System : SrcMgr::C_User; + auto &SourceMgr = CI.getSourceManager(); + auto BufferID = SourceMgr.createFileID(std::move(Buffer), Kind); + assert(BufferID.isValid() && "couldn't creaate module buffer ID"); + SourceMgr.setMainFileID(BufferID); } } |