<div dir="ltr">Should be fixed in r304740.</div><div class="gmail_extra"><br><div class="gmail_quote">On 5 June 2017 at 14:09, Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Thanks, investigating.</div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On 5 June 2017 at 13:14, Evgenii Stepanov <span dir="ltr"><<a href="mailto:eugeni.stepanov@gmail.com" target="_blank">eugeni.stepanov@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This change leaks memory:<br>
<a href="http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/5453/steps/check-clang%20asan/logs/stdio" rel="noreferrer" target="_blank">http://lab.llvm.org:8011/build<wbr>ers/sanitizer-x86_64-linux-<wbr>fast/builds/5453/steps/check-<wbr>clang%20asan/logs/stdio</a><br>
<div class="m_-5052162683332594088HOEnZb"><div class="m_-5052162683332594088h5"><br>
On Mon, Jun 5, 2017 at 11:10 AM, Richard Smith via cfe-commits<br>
<<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>> wrote:<br>
> Author: rsmith<br>
> Date: Mon Jun 5 13:10:11 2017<br>
> New Revision: 304726<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=304726&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject?rev=304726&view=rev</a><br>
> Log:<br>
> Rather than rejecting attempts to run preprocessor-only actions on AST files,<br>
> replay the steps taken to create the AST file with the preprocessor-only action<br>
> installed to produce preprocessed output.<br>
><br>
> This can be used to produce the preprocessed text for an existing .pch or .pcm<br>
> file.<br>
><br>
> Modified:<br>
> cfe/trunk/include/clang/<wbr>Basic/LangOptions.h<br>
> cfe/trunk/include/clang/<wbr>Basic/SourceManager.h<br>
> cfe/trunk/include/clang/Front<wbr>end/ASTUnit.h<br>
> cfe/trunk/include/clang/Front<wbr>end/FrontendAction.h<br>
> cfe/trunk/lib/Basic/SourceMan<wbr>ager.cpp<br>
> cfe/trunk/lib/Frontend/ASTUni<wbr>t.cpp<br>
> cfe/trunk/lib/Frontend/Fronte<wbr>ndAction.cpp<br>
> cfe/trunk/lib/Serialization/A<wbr>STReader.cpp<br>
> cfe/trunk/test/Modules/prepro<wbr>cess-module.cpp<br>
><br>
> Modified: cfe/trunk/include/clang/Basic/<wbr>LangOptions.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.h?rev=304726&r1=304725&r2=304726&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/include/clang/<wbr>Basic/LangOptions.h?rev=304726<wbr>&r1=304725&r2=304726&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- cfe/trunk/include/clang/Basic/<wbr>LangOptions.h (original)<br>
> +++ cfe/trunk/include/clang/Basic/<wbr>LangOptions.h Mon Jun 5 13:10:11 2017<br>
> @@ -58,6 +58,7 @@ public:<br>
> SOB_Trapping // -ftrapv<br>
> };<br>
><br>
> + // FIXME: Unify with TUKind.<br>
> enum CompilingModuleKind {<br>
> CMK_None, ///< Not compiling a module interface at all.<br>
> CMK_ModuleMap, ///< Compiling a module from a module map.<br>
><br>
> Modified: cfe/trunk/include/clang/Basic/<wbr>SourceManager.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceManager.h?rev=304726&r1=304725&r2=304726&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/include/clang/<wbr>Basic/SourceManager.h?rev=<wbr>304726&r1=304725&r2=304726&<wbr>view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- cfe/trunk/include/clang/Basic/<wbr>SourceManager.h (original)<br>
> +++ cfe/trunk/include/clang/Basic/<wbr>SourceManager.h Mon Jun 5 13:10:11 2017<br>
> @@ -722,6 +722,10 @@ public:<br>
><br>
> void clearIDTables();<br>
><br>
> + /// Initialize this source manager suitably to replay the compilation<br>
> + /// described by \p Old. Requires that \p Old outlive \p *this.<br>
> + void initializeForReplay(const SourceManager &Old);<br>
> +<br>
> DiagnosticsEngine &getDiagnostics() const { return Diag; }<br>
><br>
> FileManager &getFileManager() const { return FileMgr; }<br>
><br>
> Modified: cfe/trunk/include/clang/Fronte<wbr>nd/ASTUnit.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/ASTUnit.h?rev=304726&r1=304725&r2=304726&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/include/clang/<wbr>Frontend/ASTUnit.h?rev=304726&<wbr>r1=304725&r2=304726&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- cfe/trunk/include/clang/Fronte<wbr>nd/ASTUnit.h (original)<br>
> +++ cfe/trunk/include/clang/Fronte<wbr>nd/ASTUnit.h Mon Jun 5 13:10:11 2017<br>
> @@ -51,6 +51,7 @@ class DiagnosticsEngine;<br>
> class FileEntry;<br>
> class FileManager;<br>
> class HeaderSearch;<br>
> +class InputKind;<br>
> class MemoryBufferCache;<br>
> class Preprocessor;<br>
> class PCHContainerOperations;<br>
> @@ -305,9 +306,6 @@ private:<br>
> /// (likely to change while trying to use them).<br>
> bool UserFilesAreVolatile : 1;<br>
><br>
> - /// \brief The language options used when we load an AST file.<br>
> - LangOptions ASTFileLangOpts;<br>
> -<br>
> static void ConfigureDiags(IntrusiveRefCnt<wbr>Ptr<DiagnosticsEngine> Diags,<br>
> ASTUnit &AST, bool CaptureDiagnostics);<br>
><br>
> @@ -702,6 +700,9 @@ public:<br>
> /// \brief Determine what kind of translation unit this AST represents.<br>
> TranslationUnitKind getTranslationUnitKind() const { return TUKind; }<br>
><br>
> + /// \brief Determine the input kind this AST unit represents.<br>
> + InputKind getInputKind() const;<br>
> +<br>
> /// \brief A mapping from a file name to the memory buffer that stores the<br>
> /// remapped contents of that file.<br>
> typedef std::pair<std::string, llvm::MemoryBuffer *> RemappedFile;<br>
><br>
> Modified: cfe/trunk/include/clang/Fronte<wbr>nd/FrontendAction.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/FrontendAction.h?rev=304726&r1=304725&r2=304726&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/include/clang/<wbr>Frontend/FrontendAction.h?rev=<wbr>304726&r1=304725&r2=304726&<wbr>view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- cfe/trunk/include/clang/Fronte<wbr>nd/FrontendAction.h (original)<br>
> +++ cfe/trunk/include/clang/Fronte<wbr>nd/FrontendAction.h Mon Jun 5 13:10:11 2017<br>
> @@ -176,10 +176,10 @@ public:<br>
> virtual TranslationUnitKind getTranslationUnitKind() { return TU_Complete; }<br>
><br>
> /// \brief Does this action support use with PCH?<br>
> - virtual bool hasPCHSupport() const { return !usesPreprocessorOnly(); }<br>
> + virtual bool hasPCHSupport() const { return true; }<br>
><br>
> /// \brief Does this action support use with AST files?<br>
> - virtual bool hasASTFileSupport() const { return !usesPreprocessorOnly(); }<br>
> + virtual bool hasASTFileSupport() const { return true; }<br>
><br>
> /// \brief Does this action support use with IR files?<br>
> virtual bool hasIRSupport() const { return false; }<br>
><br>
> Modified: cfe/trunk/lib/Basic/SourceMana<wbr>ger.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceManager.cpp?rev=304726&r1=304725&r2=304726&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/lib/Basic/Sour<wbr>ceManager.cpp?rev=304726&r1=<wbr>304725&r2=304726&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- cfe/trunk/lib/Basic/SourceMana<wbr>ger.cpp (original)<br>
> +++ cfe/trunk/lib/Basic/SourceMana<wbr>ger.cpp Mon Jun 5 13:10:11 2017<br>
> @@ -345,6 +345,41 @@ void SourceManager::clearIDTables() {<br>
> createExpansionLoc(SourceLocat<wbr>ion(),SourceLocation(),SourceL<wbr>ocation(), 1);<br>
> }<br>
><br>
> +void SourceManager::initializeForRe<wbr>play(const SourceManager &Old) {<br>
> + assert(MainFileID.isInvalid() && "expected uninitialized SourceManager");<br>
> +<br>
> + auto CloneContentCache = [&](const ContentCache *Cache) -> ContentCache * {<br>
> + auto *Clone = new (ContentCacheAlloc.Allocate<Co<wbr>ntentCache>()) ContentCache;<br>
> + Clone->OrigEntry = Cache->OrigEntry;<br>
> + Clone->ContentsEntry = Cache->ContentsEntry;<br>
> + Clone->BufferOverridden = Cache->BufferOverridden;<br>
> + Clone->IsSystemFile = Cache->IsSystemFile;<br>
> + Clone->IsTransient = Cache->IsTransient;<br>
> + Clone->replaceBuffer(Cache->ge<wbr>tRawBuffer(), /*DoNotFree*/true);<br>
> + return Clone;<br>
> + };<br>
> +<br>
> + // Set up our main file ID as a copy of the old source manager's main file.<br>
> + const SLocEntry &OldMainFile = Old.getSLocEntry(Old.getMainFi<wbr>leID());<br>
> + assert(OldMainFile.isFile() && "main file is macro expansion?");<br>
> + setMainFileID(createFileID(<br>
> + CloneContentCache(OldMainFile.<wbr>getFile().getContentCache()),<br>
> + SourceLocation(), OldMainFile.getFile().getFileC<wbr>haracteristic(), 0, 0));<br>
> +<br>
> + // Ensure all SLocEntries are loaded from the external source.<br>
> + for (unsigned I = 0, N = Old.LoadedSLocEntryTable.size(<wbr>); I != N; ++I)<br>
> + if (!Old.SLocEntryLoaded[I])<br>
> + Old.loadSLocEntry(I, nullptr);<br>
> +<br>
> + // Inherit any content cache data from the old source manager.<br>
> + for (auto &FileInfo : Old.FileInfos) {<br>
> + SrcMgr::ContentCache *&Slot = FileInfos[FileInfo.first];<br>
> + if (Slot)<br>
> + continue;<br>
> + Slot = CloneContentCache(FileInfo.sec<wbr>ond);<br>
> + }<br>
> +}<br>
> +<br>
> /// getOrCreateContentCache - Create or return a cached ContentCache for the<br>
> /// specified file.<br>
> const ContentCache *<br>
><br>
> Modified: cfe/trunk/lib/Frontend/ASTUnit<wbr>.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=304726&r1=304725&r2=304726&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/lib/Frontend/<wbr>ASTUnit.cpp?rev=304726&r1=<wbr>304725&r2=304726&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- cfe/trunk/lib/Frontend/ASTUnit<wbr>.cpp (original)<br>
> +++ cfe/trunk/lib/Frontend/ASTUnit<wbr>.cpp Mon Jun 5 13:10:11 2017<br>
> @@ -667,6 +667,7 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFr<br>
><br>
> ConfigureDiags(Diags, *AST, CaptureDiagnostics);<br>
><br>
> + AST->LangOpts = std::make_shared<LangOptions>(<wbr>);<br>
> AST->OnlyLocalDecls = OnlyLocalDecls;<br>
> AST->CaptureDiagnostics = CaptureDiagnostics;<br>
> AST->Diagnostics = Diags;<br>
> @@ -682,7 +683,7 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFr<br>
> AST->HeaderInfo.reset(new HeaderSearch(AST->HSOpts,<br>
> AST->getSourceManager(),<br>
> AST->getDiagnostics(),<br>
> - AST->ASTFileLangOpts,<br>
> + AST->getLangOpts(),<br>
> /*Target=*/nullptr));<br>
><br>
> auto PPOpts = std::make_shared<PreprocessorO<wbr>ptions>();<br>
> @@ -696,13 +697,13 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFr<br>
> unsigned Counter;<br>
><br>
> AST->PP = std::make_shared<Preprocessor><wbr>(<br>
> - std::move(PPOpts), AST->getDiagnostics(), AST->ASTFileLangOpts,<br>
> + std::move(PPOpts), AST->getDiagnostics(), *AST->LangOpts,<br>
> AST->getSourceManager(), *AST->PCMCache, HeaderInfo, *AST,<br>
> /*IILookup=*/nullptr,<br>
> /*OwnsHeaderSearch=*/false);<br>
> Preprocessor &PP = *AST->PP;<br>
><br>
> - AST->Ctx = new ASTContext(AST->ASTFileLangOpt<wbr>s, AST->getSourceManager(),<br>
> + AST->Ctx = new ASTContext(*AST->LangOpts, AST->getSourceManager(),<br>
> PP.getIdentifierTable(), PP.getSelectorTable(),<br>
> PP.getBuiltinInfo());<br>
> ASTContext &Context = *AST->Ctx;<br>
> @@ -716,7 +717,7 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFr<br>
> AllowPCHWithCompilerErrors);<br>
><br>
> AST->Reader->setListener(llvm:<wbr>:make_unique<ASTInfoCollector><wbr>(<br>
> - *AST->PP, Context, AST->ASTFileLangOpts, AST->TargetOpts, AST->Target,<br>
> + *AST->PP, Context, *AST->LangOpts, AST->TargetOpts, AST->Target,<br>
> Counter));<br>
><br>
> // Attach the AST reader to the AST context as an external AST<br>
> @@ -2879,7 +2880,32 @@ const FileEntry *ASTUnit::getPCHFile() {<br>
> }<br>
><br>
> bool ASTUnit::isModuleFile() {<br>
> - return isMainFileAST() && ASTFileLangOpts.isCompilingMod<wbr>ule();<br>
> + return isMainFileAST() && getLangOpts().isCompilingModul<wbr>e();<br>
> +}<br>
> +<br>
> +InputKind ASTUnit::getInputKind() const {<br>
> + auto &LangOpts = getLangOpts();<br>
> +<br>
> + InputKind::Language Lang;<br>
> + if (LangOpts.OpenCL)<br>
> + Lang = InputKind::OpenCL;<br>
> + else if (LangOpts.CUDA)<br>
> + Lang = InputKind::CUDA;<br>
> + else if (LangOpts.RenderScript)<br>
> + Lang = InputKind::RenderScript;<br>
> + else if (LangOpts.CPlusPlus)<br>
> + Lang = LangOpts.ObjC1 ? InputKind::ObjCXX : InputKind::CXX;<br>
> + else<br>
> + Lang = LangOpts.ObjC1 ? InputKind::ObjC : InputKind::C;<br>
> +<br>
> + InputKind::Format Fmt = InputKind::Source;<br>
> + if (LangOpts.getCompilingModule() == LangOptions::CMK_ModuleMap)<br>
> + Fmt = InputKind::ModuleMap;<br>
> +<br>
> + // We don't know if input was preprocessed. Assume not.<br>
> + bool PP = false;<br>
> +<br>
> + return InputKind(Lang, Fmt, PP);<br>
> }<br>
><br>
> void ASTUnit::PreambleData::countLi<wbr>nes() const {<br>
><br>
> Modified: cfe/trunk/lib/Frontend/Fronten<wbr>dAction.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendAction.cpp?rev=304726&r1=304725&r2=304726&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/lib/Frontend/<wbr>FrontendAction.cpp?rev=304726&<wbr>r1=304725&r2=304726&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- cfe/trunk/lib/Frontend/Fronten<wbr>dAction.cpp (original)<br>
> +++ cfe/trunk/lib/Frontend/Fronten<wbr>dAction.cpp Mon Jun 5 13:10:11 2017<br>
> @@ -387,8 +387,7 @@ static std::error_code collectModuleHead<br>
> return std::error_code();<br>
> }<br>
><br>
> -static bool loadModuleMapForModuleBuild(Co<wbr>mpilerInstance &CI,<br>
> - StringRef Filename, bool IsSystem,<br>
> +static bool loadModuleMapForModuleBuild(Co<wbr>mpilerInstance &CI, bool IsSystem,<br>
> bool IsPreprocessed,<br>
> std::string &PresumedModuleMapFile,<br>
> unsigned &Offset) {<br>
> @@ -523,7 +522,8 @@ getInputBufferForModule(Compil<wbr>erInstance<br>
> }<br>
><br>
> bool FrontendAction::BeginSourceFil<wbr>e(CompilerInstance &CI,<br>
> - const FrontendInputFile &Input) {<br>
> + const FrontendInputFile &RealInput) {<br>
> + FrontendInputFile Input(RealInput);<br>
> assert(!Instance && "Already processing a source file!");<br>
> assert(!Input.isEmpty() && "Unexpected empty filename!");<br>
> setCurrentInput(Input);<br>
> @@ -531,15 +531,69 @@ bool FrontendAction::BeginSourceFil<wbr>e(Com<br>
><br>
> StringRef InputFile = Input.getFile();<br>
> bool HasBegunSourceFile = false;<br>
> + bool ReplayASTFile = Input.getKind().getFormat() == InputKind::Precompiled &&<br>
> + usesPreprocessorOnly();<br>
> if (!BeginInvocation(CI))<br>
> goto failure;<br>
><br>
> + // If we're replaying the build of an AST file, import it and set up<br>
> + // the initial state from its build.<br>
> + if (ReplayASTFile) {<br>
> + IntrusiveRefCntPtr<Diagnostics<wbr>Engine> Diags(&CI.getDiagnostics());<br>
> +<br>
> + // The AST unit populates its own diagnostics engine rather than ours.<br>
> + IntrusiveRefCntPtr<Diagnostics<wbr>Engine> ASTDiags(<br>
> + new DiagnosticsEngine(Diags->getDi<wbr>agnosticIDs(),<br>
> + &Diags->getDiagnosticOptions()<wbr>));<br>
> + ASTDiags->setClient(Diags->get<wbr>Client(), /*OwnsClient*/false);<br>
> +<br>
> + std::unique_ptr<ASTUnit> AST = ASTUnit::LoadFromASTFile(<br>
> + InputFile, CI.getPCHContainerReader(), ASTDiags, CI.getFileSystemOpts(),<br>
> + CI.getCodeGenOpts().DebugTypeE<wbr>xtRefs);<br>
> + if (!AST)<br>
> + goto failure;<br>
> +<br>
> + // Options relating to how we treat the input (but not what we do with it)<br>
> + // are inherited from the AST unit.<br>
> + CI.getLangOpts() = AST->getLangOpts();<br>
> +<br>
> + // Preload all the module files loaded transitively by the AST unit.<br>
> + if (auto ASTReader = AST->getASTReader()) {<br>
> + auto &MM = ASTReader->getModuleManager();<br>
> + for (ModuleFile &MF : MM)<br>
> + if (&MF != &MM.getPrimaryModule())<br>
> + CI.getFrontendOpts().ModuleFil<wbr>es.push_back(MF.FileName);<br>
> + }<br>
> +<br>
> + // Set the shared objects, these are reset when we finish processing the<br>
> + // file, otherwise the CompilerInstance will happily destroy them.<br>
> + CI.setFileManager(&AST->getFil<wbr>eManager());<br>
> + CI.createSourceManager(CI.getF<wbr>ileManager());<br>
> + CI.getSourceManager().initiali<wbr>zeForReplay(AST->getSourceMana<wbr>ger());<br>
> + CI.createPreprocessor(getTrans<wbr>lationUnitKind());<br>
> +<br>
> + // Set up the input file for replay purposes.<br>
> + auto Kind = AST->getInputKind();<br>
> + if (Kind.getFormat() == InputKind::ModuleMap) {<br>
> + Module *ASTModule =<br>
> + AST->getPreprocessor().getHead<wbr>erSearchInfo().lookupModule(<br>
> + AST->getLangOpts().CurrentModu<wbr>le, /*AllowSearch*/ false);<br>
> + Input = FrontendInputFile(ASTModule->P<wbr>resumedModuleMapFile, Kind);<br>
> + } else {<br>
> + auto &SM = CI.getSourceManager();<br>
> + FileID ID = SM.getMainFileID();<br>
> + if (auto *File = SM.getFileEntryForID(ID))<br>
> + Input = FrontendInputFile(File->getNam<wbr>e(), Kind);<br>
> + else<br>
> + Input = FrontendInputFile(SM.getBuffer<wbr>(ID), Kind);<br>
> + }<br>
> + setCurrentInput(Input, std::move(AST));<br>
> + }<br>
> +<br>
> // AST files follow a very different path, since they share objects via the<br>
> // AST unit.<br>
> if (Input.getKind().getFormat() == InputKind::Precompiled) {<br>
> - // FIXME: We should not be asserting on bad command-line arguments.<br>
> - assert(!usesPreprocessorOnly() &&<br>
> - "Attempt to pass AST file to preprocessor only action!");<br>
> + assert(!usesPreprocessorOnly() && "this case was handled above");<br>
> assert(hasASTFileSupport() &&<br>
> "This action does not have AST file support!");<br>
><br>
> @@ -680,7 +734,7 @@ bool FrontendAction::BeginSourceFil<wbr>e(Com<br>
><br>
> std::string PresumedModuleMapFile;<br>
> unsigned OffsetToContents;<br>
> - if (loadModuleMapForModuleBuild(C<wbr>I, Input.getFile(), Input.isSystem(),<br>
> + if (loadModuleMapForModuleBuild(C<wbr>I, Input.isSystem(),<br>
> Input.isPreprocessed(),<br>
> PresumedModuleMapFile, OffsetToContents))<br>
> goto failure;<br>
> @@ -829,14 +883,7 @@ bool FrontendAction::BeginSourceFil<wbr>e(Com<br>
><br>
> // If we failed, reset state since the client will not end up calling the<br>
> // matching EndSourceFile().<br>
> - failure:<br>
> - if (isCurrentFileAST()) {<br>
> - CI.setASTContext(nullptr);<br>
> - CI.setPreprocessor(nullptr);<br>
> - CI.setSourceManager(nullptr);<br>
> - CI.setFileManager(nullptr);<br>
> - }<br>
> -<br>
> +failure:<br>
> if (HasBegunSourceFile)<br>
> CI.getDiagnosticClient().EndSo<wbr>urceFile();<br>
> CI.clearOutputFiles(/*EraseFil<wbr>es=*/true);<br>
> @@ -914,6 +961,7 @@ void FrontendAction::EndSourceFile(<wbr>) {<br>
> CI.resetAndLeakPreprocessor();<br>
> CI.resetAndLeakSourceManager()<wbr>;<br>
> CI.resetAndLeakFileManager();<br>
> + BuryPointer(CurrentASTUnit.rel<wbr>ease());<br>
> } else {<br>
> CI.setPreprocessor(nullptr);<br>
> CI.setSourceManager(nullptr);<br>
><br>
> Modified: cfe/trunk/lib/Serialization/AS<wbr>TReader.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=304726&r1=304725&r2=304726&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/lib/Serializat<wbr>ion/ASTReader.cpp?rev=304726&<wbr>r1=304725&r2=304726&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- cfe/trunk/lib/Serialization/AS<wbr>TReader.cpp (original)<br>
> +++ cfe/trunk/lib/Serialization/AS<wbr>TReader.cpp Mon Jun 5 13:10:11 2017<br>
> @@ -4918,6 +4918,7 @@ ASTReader::ReadSubmoduleBlock(<wbr>ModuleFile<br>
> }<br>
><br>
> CurrentModule->setASTFile(F.Fi<wbr>le);<br>
> + CurrentModule->PresumedModuleM<wbr>apFile = F.ModuleMapPath;<br>
> }<br>
><br>
> CurrentModule->Kind = ModuleKind;<br>
><br>
> Modified: cfe/trunk/test/Modules/preproc<wbr>ess-module.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/preprocess-module.cpp?rev=304726&r1=304725&r2=304726&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-pr<wbr>oject/cfe/trunk/test/Modules/<wbr>preprocess-module.cpp?rev=<wbr>304726&r1=304725&r2=304726&<wbr>view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- cfe/trunk/test/Modules/preproc<wbr>ess-module.cpp (original)<br>
> +++ cfe/trunk/test/Modules/preproc<wbr>ess-module.cpp Mon Jun 5 13:10:11 2017<br>
> @@ -34,10 +34,15 @@<br>
> // RUN: rm %t/fwd.h %t/file.h %t/file2.h %t/module.modulemap<br>
> // RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodule-file=%t/fwd.pcm -x c++-module-map-cpp-output %t/copy.ii -emit-module -o %t/copy.pcm<br>
><br>
> -// Finally, check that our module contains correct mapping information for the headers.<br>
> +// Check that our module contains correct mapping information for the headers.<br>
> // RUN: cp %S/Inputs/preprocess/fwd.h %S/Inputs/preprocess/file.h %S/Inputs/preprocess/file2.h %S/Inputs/preprocess/module.mo<wbr>dulemap %t<br>
> // RUN: %clang_cc1 -fmodules -fmodule-file=%t/copy.pcm %s -I%t -verify -fno-modules-error-recovery -DCOPY -DINCLUDE<br>
><br>
> +// Check that we can preprocess from a .pcm file and that we get the same result as preprocessing from the original sources.<br>
> +// RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodule-file=%t/fwd.pcm -I%S/Inputs/preprocess -x c++-module-map %S/Inputs/preprocess/module.mo<wbr>dulemap -emit-module -o %t/file.pcm<br>
> +// RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodule-file=%t/fwd.pcm -I%S/Inputs/preprocess %t/file.pcm -E -frewrite-includes -o %t/file.rewrite.ii<br>
> +// RUN: cmp %t/rewrite.ii %t/file.rewrite.ii<br>
> +<br>
> // == module map<br>
> // CHECK: # 1 "{{.*}}module.modulemap"<br>
> // CHECK: module file {<br>
><br>
><br>
> ______________________________<wbr>_________________<br>
> cfe-commits mailing list<br>
> <a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-commits</a><br>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>