On Sat, Feb 8, 2014 at 1:38 AM, Dmitri Gribenko <[email protected]> wrote:
> Author: gribozavr > Date: Fri Feb 7 18:38:15 2014 > New Revision: 201010 > > URL: http://llvm.org/viewvc/llvm-project?rev=201010&view=rev > Log: > ASTUnit: remove dead code in remapping files > > ASTUnit contains code to remap files to other files on disk. This code is > not > used. We only remap files to MemoryBuffers. > > Modified: > cfe/trunk/include/clang/Frontend/ASTUnit.h > cfe/trunk/lib/Frontend/ASTUnit.cpp > > Modified: cfe/trunk/include/clang/Frontend/ASTUnit.h > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/ASTUnit.h?rev=201010&r1=201009&r2=201010&view=diff > > ============================================================================== > --- cfe/trunk/include/clang/Frontend/ASTUnit.h (original) > +++ cfe/trunk/include/clang/Frontend/ASTUnit.h Fri Feb 7 18:38:15 2014 > @@ -671,11 +671,9 @@ public: > /// \brief Determine what kind of translation unit this AST represents. > TranslationUnitKind getTranslationUnitKind() const { return TUKind; } > > - typedef llvm::PointerUnion<const char *, const llvm::MemoryBuffer *> > - FilenameOrMemBuf; > /// \brief A mapping from a file name to the memory buffer that stores > the > /// remapped contents of that file. > - typedef std::pair<std::string, FilenameOrMemBuf> RemappedFile; > + typedef std::pair<std::string, const llvm::MemoryBuffer *> RemappedFile; > > /// \brief Create a ASTUnit. Gets ownership of the passed > CompilerInvocation. > static ASTUnit *create(CompilerInvocation *CI, > > Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=201010&r1=201009&r2=201010&view=diff > > ============================================================================== > --- cfe/trunk/lib/Frontend/ASTUnit.cpp (original) > +++ cfe/trunk/lib/Frontend/ASTUnit.cpp Fri Feb 7 18:38:15 2014 > @@ -710,54 +710,24 @@ ASTUnit *ASTUnit::LoadFromASTFile(const > AST->getDiagnostics(), > AST->ASTFileLangOpts, > /*Target=*/0)); > - > - for (unsigned I = 0, N = RemappedFiles.size(); I != N; ++I) { > - FilenameOrMemBuf fileOrBuf = RemappedFiles[I].second; > - if (const llvm::MemoryBuffer * > - memBuf = fileOrBuf.dyn_cast<const llvm::MemoryBuffer *>()) { > - // Create the file entry for the file that we're mapping from. > - const FileEntry *FromFile > - = AST->getFileManager().getVirtualFile(RemappedFiles[I].first, > - memBuf->getBufferSize(), > - 0); > - if (!FromFile) { > - AST->getDiagnostics().Report(diag::err_fe_remap_missing_from_file) > - << RemappedFiles[I].first; > - delete memBuf; > - continue; > - } > - > - // Override the contents of the "from" file with the contents of > - // the "to" file. > - AST->getSourceManager().overrideFileContents(FromFile, memBuf); > > - } else { > - const char *fname = fileOrBuf.get<const char *>(); > - const FileEntry *ToFile = AST->FileMgr->getFile(fname); > - if (!ToFile) { > - AST->getDiagnostics().Report(diag::err_fe_remap_missing_to_file) > - << RemappedFiles[I].first << fname; > - continue; > - } > - > - // Create the file entry for the file that we're mapping from. > - const FileEntry *FromFile > - = AST->getFileManager().getVirtualFile(RemappedFiles[I].first, > - ToFile->getSize(), > - 0); > - if (!FromFile) { > - AST->getDiagnostics().Report(diag::err_fe_remap_missing_from_file) > + for (unsigned I = 0, N = RemappedFiles.size(); I != N; ++I) { > + const llvm::MemoryBuffer *MemBuf = RemappedFiles[I].second; > + // Create the file entry for the file that we're mapping from. > + const FileEntry *FromFile = AST->getFileManager().getVirtualFile( > + RemappedFiles[I].first, MemBuf->getBufferSize(), 0); > + if (!FromFile) { > + AST->getDiagnostics().Report(diag::err_fe_remap_missing_from_file) > << RemappedFiles[I].first; > - delete memBuf; > - continue; > - } > - > - // Override the contents of the "from" file with the contents of > - // the "to" file. > - AST->getSourceManager().overrideFileContents(FromFile, ToFile); > + delete MemBuf; > + continue; > } > + > + // Override the contents of the "from" file with the contents of > + // the "to" file. > + AST->getSourceManager().overrideFileContents(FromFile, MemBuf); > } > - > + > // Gather Info for preprocessor construction later on. > > HeaderSearch &HeaderInfo = *AST->HeaderInfo.get(); > @@ -2055,14 +2025,8 @@ ASTUnit *ASTUnit::LoadFromCommandLine(co > > // Override any files that need remapping > for (unsigned I = 0, N = RemappedFiles.size(); I != N; ++I) { > - FilenameOrMemBuf fileOrBuf = RemappedFiles[I].second; > - if (const llvm::MemoryBuffer * > - memBuf = fileOrBuf.dyn_cast<const llvm::MemoryBuffer *>()) { > - CI->getPreprocessorOpts().addRemappedFile(RemappedFiles[I].first, > memBuf); > - } else { > - const char *fname = fileOrBuf.get<const char *>(); > - CI->getPreprocessorOpts().addRemappedFile(RemappedFiles[I].first, > fname); > - } > + CI->getPreprocessorOpts().addRemappedFile(RemappedFiles[I].first, > + RemappedFiles[I].second); > } > PreprocessorOptions &PPOpts = CI->getPreprocessorOpts(); > PPOpts.RemappedFilesKeepOriginalName = RemappedFilesKeepOriginalName; > @@ -2132,18 +2096,10 @@ bool ASTUnit::Reparse(ArrayRef<RemappedF > } > Invocation->getPreprocessorOpts().clearRemappedFiles(); > for (unsigned I = 0, N = RemappedFiles.size(); I != N; ++I) { > - FilenameOrMemBuf fileOrBuf = RemappedFiles[I].second; > - if (const llvm::MemoryBuffer * > - memBuf = fileOrBuf.dyn_cast<const llvm::MemoryBuffer *>()) { > - > Invocation->getPreprocessorOpts().addRemappedFile(RemappedFiles[I].first, > - memBuf); > - } else { > - const char *fname = fileOrBuf.get<const char *>(); > - > Invocation->getPreprocessorOpts().addRemappedFile(RemappedFiles[I].first, > - fname); > - } > + > Invocation->getPreprocessorOpts().addRemappedFile(RemappedFiles[I].first, > + > RemappedFiles[I].second); > } > - > + > // If we have a preamble file lying around, or if we might try to > // build a precompiled preamble, do so now. > llvm::MemoryBuffer *OverrideMainBuffer = 0; > @@ -2497,17 +2453,10 @@ void ASTUnit::CodeComplete(StringRef Fil > PreprocessorOpts.clearRemappedFiles(); > PreprocessorOpts.RetainRemappedFileBuffers = true; > for (unsigned I = 0, N = RemappedFiles.size(); I != N; ++I) { > - FilenameOrMemBuf fileOrBuf = RemappedFiles[I].second; > - if (const llvm::MemoryBuffer * > - memBuf = fileOrBuf.dyn_cast<const llvm::MemoryBuffer *>()) { > - PreprocessorOpts.addRemappedFile(RemappedFiles[I].first, memBuf); > - OwnedBuffers.push_back(memBuf); Not adding MemoryBuffers to OwnedBuffers creates a memory leak. Did you intentionally remove that? > - } else { > - const char *fname = fileOrBuf.get<const char *>(); > - PreprocessorOpts.addRemappedFile(RemappedFiles[I].first, fname); > - } > + PreprocessorOpts.addRemappedFile(RemappedFiles[I].first, > + RemappedFiles[I].second); > } > - > + > // Use the code completion consumer we were given, but adding any cached > // code-completion results. > AugmentedCodeCompleteConsumer *AugmentedConsumer > > > _______________________________________________ > cfe-commits mailing list > [email protected] > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits >
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
