From b2da538302d3f710f8c790b8e96f95ab43710f56 Mon Sep 17 00:00:00 2001 From: Vassil Vassilev Date: Mon, 25 Nov 2013 10:57:00 +0100 Subject: [PATCH] When non default memory buffer is provided add a common include file. When a CI is created with a custom membory buffer, we can just set it as the main memory buffer, becuase when clang tries to compare the include chains it won't find common predecessor and either will infinite-loop or crash. --- lib/Interpreter/CIFactory.cpp | 44 +++++++++++++++-------------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/lib/Interpreter/CIFactory.cpp b/lib/Interpreter/CIFactory.cpp index 1c3261fa..7e11a0d0 100644 --- a/lib/Interpreter/CIFactory.cpp +++ b/lib/Interpreter/CIFactory.cpp @@ -237,31 +237,25 @@ namespace cling { /*UserFilesAreVolatile*/ true); CI->setSourceManager(SM); // FIXME: SM leaks. - // Set up the memory buffer - if (buffer) - CI->getSourceManager().createMainFileIDForMemBuffer(buffer); - else { - // As main file we want - // * a virtual file that is claiming to be huge - // * with an empty memory buffer attached (to bring the content) - SourceManager& SM = CI->getSourceManager(); - FileManager& FM = SM.getFileManager(); - // Build the virtual file - const char* Filename = "InteractiveInputLineIncluder.h"; - const std::string& CGOptsMainFileName - = CI->getInvocation().getCodeGenOpts().MainFileName; - if (!CGOptsMainFileName.empty()) - Filename = CGOptsMainFileName.c_str(); - const FileEntry* FE - = FM.getVirtualFile(Filename, 1U << 15U, time(0)); - FileID MainFileID = SM.createMainFileID(FE, SrcMgr::C_User); - const SrcMgr::SLocEntry& MainFileSLocE = SM.getSLocEntry(MainFileID); - const SrcMgr::ContentCache* MainFileCC - = MainFileSLocE.getFile().getContentCache(); - llvm::MemoryBuffer* MainFileMB - = llvm::MemoryBuffer::getMemBuffer("/*CLING MAIN FILE*/\n"); - const_cast(MainFileCC)->setBuffer(MainFileMB); - } + // As main file we want + // * a virtual file that is claiming to be huge + // * with an empty memory buffer attached (to bring the content) + FileManager& FM = SM->getFileManager(); + // Build the virtual file + const char* Filename = "InteractiveInputLineIncluder.h"; + const std::string& CGOptsMainFileName + = CI->getInvocation().getCodeGenOpts().MainFileName; + if (!CGOptsMainFileName.empty()) + Filename = CGOptsMainFileName.c_str(); + const FileEntry* FE + = FM.getVirtualFile(Filename, 1U << 15U, time(0)); + FileID MainFileID = SM->createMainFileID(FE, SrcMgr::C_User); + const SrcMgr::SLocEntry& MainFileSLocE = SM->getSLocEntry(MainFileID); + const SrcMgr::ContentCache* MainFileCC + = MainFileSLocE.getFile().getContentCache(); + if (!buffer) + buffer = llvm::MemoryBuffer::getMemBuffer("/*CLING DEFAULT MEMBUF*/\n"); + const_cast(MainFileCC)->setBuffer(buffer); // Set up the preprocessor CI->createPreprocessor();