diff options
| -rw-r--r-- | clang-tools-extra/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp | 2 | ||||
| -rw-r--r-- | clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp | 2 | ||||
| -rw-r--r-- | clang/include/clang/Basic/SourceManager.h | 31 | ||||
| -rw-r--r-- | clang/include/clang/Frontend/FrontendOptions.h | 6 | ||||
| -rw-r--r-- | clang/lib/Basic/SourceManager.cpp | 32 | ||||
| -rw-r--r-- | clang/lib/CodeGen/CGDebugInfo.cpp | 2 | ||||
| -rw-r--r-- | clang/lib/CodeGen/CodeGenAction.cpp | 5 | ||||
| -rw-r--r-- | clang/lib/Frontend/PrecompiledPreamble.cpp | 2 | ||||
| -rw-r--r-- | clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp | 2 | ||||
| -rw-r--r-- | clang/lib/StaticAnalyzer/Core/IssueHash.cpp | 4 | ||||
| -rw-r--r-- | clang/tools/clang-import-test/clang-import-test.cpp | 3 | ||||
| -rw-r--r-- | clang/tools/libclang/CIndex.cpp | 2 | ||||
| -rw-r--r-- | llvm/include/llvm/Support/MemoryBuffer.h | 2 |
13 files changed, 51 insertions, 44 deletions
diff --git a/clang-tools-extra/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp index 576fba51553..d94731beba9 100644 --- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousSemicolonCheck.cpp @@ -53,7 +53,7 @@ void SuspiciousSemicolonCheck::check(const MatchFinder::MatchResult &Result) { SourceLocation LocEnd = Semicolon->getEndLoc(); FileID FID = SM.getFileID(LocEnd); - llvm::MemoryBuffer *Buffer = SM.getBuffer(FID, LocEnd); + const llvm::MemoryBuffer *Buffer = SM.getBuffer(FID, LocEnd); Lexer Lexer(SM.getLocForStartOfFile(FID), Ctxt.getLangOpts(), Buffer->getBufferStart(), SM.getCharacterData(LocEnd) + 1, Buffer->getBufferEnd()); diff --git a/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp b/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp index 18d94128c38..a2f31797c4a 100644 --- a/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp @@ -145,7 +145,7 @@ SourceLocation StaticAssertCheck::getLastParenLoc(const ASTContext *ASTCtx, const LangOptions &Opts = ASTCtx->getLangOpts(); const SourceManager &SM = ASTCtx->getSourceManager(); - llvm::MemoryBuffer *Buffer = SM.getBuffer(SM.getFileID(AssertLoc)); + const llvm::MemoryBuffer *Buffer = SM.getBuffer(SM.getFileID(AssertLoc)); if (!Buffer) return SourceLocation(); diff --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h index 2bdf1d5e39f..a9882839958 100644 --- a/clang/include/clang/Basic/SourceManager.h +++ b/clang/include/clang/Basic/SourceManager.h @@ -105,7 +105,7 @@ namespace SrcMgr { /// /// This is owned by the ContentCache object. The bits indicate /// whether the buffer is invalid. - mutable llvm::PointerIntPair<llvm::MemoryBuffer *, 2> Buffer; + mutable llvm::PointerIntPair<const llvm::MemoryBuffer *, 2> Buffer; public: /// Reference to the file entry representing this ContentCache. @@ -184,10 +184,10 @@ namespace SrcMgr { /// will be emitted at. /// /// \param Invalid If non-NULL, will be set \c true if an error occurred. - llvm::MemoryBuffer *getBuffer(DiagnosticsEngine &Diag, - const SourceManager &SM, - SourceLocation Loc = SourceLocation(), - bool *Invalid = nullptr) const; + const llvm::MemoryBuffer *getBuffer(DiagnosticsEngine &Diag, + const SourceManager &SM, + SourceLocation Loc = SourceLocation(), + bool *Invalid = nullptr) const; /// Returns the size of the content encapsulated by this /// ContentCache. @@ -209,11 +209,13 @@ namespace SrcMgr { /// Get the underlying buffer, returning NULL if the buffer is not /// yet available. - llvm::MemoryBuffer *getRawBuffer() const { return Buffer.getPointer(); } + const llvm::MemoryBuffer *getRawBuffer() const { + return Buffer.getPointer(); + } /// Replace the existing buffer (which will be deleted) /// with the given buffer. - void replaceBuffer(llvm::MemoryBuffer *B, bool DoNotFree = false); + void replaceBuffer(const llvm::MemoryBuffer *B, bool DoNotFree = false); /// Determine whether the buffer itself is invalid. bool isBufferInvalid() const { @@ -841,7 +843,7 @@ public: /// /// This does no caching of the buffer and takes ownership of the /// MemoryBuffer, so only pass a MemoryBuffer to this once. - FileID createFileID(UnownedTag, llvm::MemoryBuffer *Buffer, + FileID createFileID(UnownedTag, const llvm::MemoryBuffer *Buffer, SrcMgr::CharacteristicKind FileCharacter = SrcMgr::C_User, int LoadedID = 0, unsigned LoadedOffset = 0, SourceLocation IncludeLoc = SourceLocation()) { @@ -887,8 +889,8 @@ public: /// /// \param Invalid If non-NULL, will be set \c true if an error /// occurs while retrieving the memory buffer. - llvm::MemoryBuffer *getMemoryBufferForFile(const FileEntry *File, - bool *Invalid = nullptr); + const llvm::MemoryBuffer *getMemoryBufferForFile(const FileEntry *File, + bool *Invalid = nullptr); /// Override the contents of the given source file by providing an /// already-allocated buffer. @@ -951,8 +953,8 @@ public: /// /// If there is an error opening this buffer the first time, this /// manufactures a temporary buffer and returns a non-empty error string. - llvm::MemoryBuffer *getBuffer(FileID FID, SourceLocation Loc, - bool *Invalid = nullptr) const { + const llvm::MemoryBuffer *getBuffer(FileID FID, SourceLocation Loc, + bool *Invalid = nullptr) const { bool MyInvalid = false; const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, &MyInvalid); if (MyInvalid || !Entry.isFile()) { @@ -966,7 +968,8 @@ public: Invalid); } - llvm::MemoryBuffer *getBuffer(FileID FID, bool *Invalid = nullptr) const { + const llvm::MemoryBuffer *getBuffer(FileID FID, + bool *Invalid = nullptr) const { bool MyInvalid = false; const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, &MyInvalid); if (MyInvalid || !Entry.isFile()) { @@ -1788,7 +1791,7 @@ private: /// Create a new ContentCache for the specified memory buffer. const SrcMgr::ContentCache * - createMemBufferContentCache(llvm::MemoryBuffer *Buf, bool DoNotFree); + createMemBufferContentCache(const llvm::MemoryBuffer *Buf, bool DoNotFree); FileID getFileIDSlow(unsigned SLocOffset) const; FileID getFileIDLocal(unsigned SLocOffset) const; diff --git a/clang/include/clang/Frontend/FrontendOptions.h b/clang/include/clang/Frontend/FrontendOptions.h index 8cbba55da4d..645e9ffe81f 100644 --- a/clang/include/clang/Frontend/FrontendOptions.h +++ b/clang/include/clang/Frontend/FrontendOptions.h @@ -202,7 +202,7 @@ class FrontendInputFile { /// The input, if it comes from a buffer rather than a file. This object /// does not own the buffer, and the caller is responsible for ensuring /// that it outlives any users. - llvm::MemoryBuffer *Buffer = nullptr; + const llvm::MemoryBuffer *Buffer = nullptr; /// The kind of input, e.g., C source, AST file, LLVM IR. InputKind Kind; @@ -214,7 +214,7 @@ public: FrontendInputFile() = default; FrontendInputFile(StringRef File, InputKind Kind, bool IsSystem = false) : File(File.str()), Kind(Kind), IsSystem(IsSystem) {} - FrontendInputFile(llvm::MemoryBuffer *Buffer, InputKind Kind, + FrontendInputFile(const llvm::MemoryBuffer *Buffer, InputKind Kind, bool IsSystem = false) : Buffer(Buffer), Kind(Kind), IsSystem(IsSystem) {} @@ -231,7 +231,7 @@ public: return File; } - llvm::MemoryBuffer *getBuffer() const { + const llvm::MemoryBuffer *getBuffer() const { assert(isBuffer()); return Buffer; } diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index 57b0bbd1db4..1b139c65523 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -69,7 +69,7 @@ llvm::MemoryBuffer::BufferKind ContentCache::getMemoryBufferKind() const { if (!Buffer.getPointer()) return llvm::MemoryBuffer::MemoryBuffer_Malloc; - llvm::MemoryBuffer *buf = Buffer.getPointer(); + const llvm::MemoryBuffer *buf = Buffer.getPointer(); return buf->getBufferKind(); } @@ -82,7 +82,7 @@ unsigned ContentCache::getSize() const { : (unsigned) ContentsEntry->getSize(); } -void ContentCache::replaceBuffer(llvm::MemoryBuffer *B, bool DoNotFree) { +void ContentCache::replaceBuffer(const llvm::MemoryBuffer *B, bool DoNotFree) { if (B && B == Buffer.getPointer()) { assert(0 && "Replacing with the same buffer"); Buffer.setInt(DoNotFree? DoNotFreeFlag : 0); @@ -95,10 +95,10 @@ void ContentCache::replaceBuffer(llvm::MemoryBuffer *B, bool DoNotFree) { Buffer.setInt((B && DoNotFree) ? DoNotFreeFlag : 0); } -llvm::MemoryBuffer *ContentCache::getBuffer(DiagnosticsEngine &Diag, - const SourceManager &SM, - SourceLocation Loc, - bool *Invalid) const { +const llvm::MemoryBuffer *ContentCache::getBuffer(DiagnosticsEngine &Diag, + const SourceManager &SM, + SourceLocation Loc, + bool *Invalid) const { // Lazily create the Buffer for ContentCaches that wrap files. If we already // computed it, just return what we have. if (Buffer.getPointer() || !ContentsEntry) { @@ -423,7 +423,7 @@ SourceManager::getOrCreateContentCache(const FileEntry *FileEnt, /// Create a new ContentCache for the specified memory buffer. /// This does no caching. const ContentCache * -SourceManager::createMemBufferContentCache(llvm::MemoryBuffer *Buffer, +SourceManager::createMemBufferContentCache(const llvm::MemoryBuffer *Buffer, bool DoNotFree) { // Add a new ContentCache to the MemBufferInfos list and return it. ContentCache *Entry = ContentCacheAlloc.Allocate<ContentCache>(); @@ -618,8 +618,8 @@ SourceManager::createExpansionLocImpl(const ExpansionInfo &Info, return SourceLocation::getMacroLoc(NextLocalOffset - (TokLength + 1)); } -llvm::MemoryBuffer *SourceManager::getMemoryBufferForFile(const FileEntry *File, - bool *Invalid) { +const llvm::MemoryBuffer * +SourceManager::getMemoryBufferForFile(const FileEntry *File, bool *Invalid) { const SrcMgr::ContentCache *IR = getOrCreateContentCache(File); assert(IR && "getOrCreateContentCache() cannot return NULL"); return IR->getBuffer(Diag, *this, SourceLocation(), Invalid); @@ -675,7 +675,7 @@ StringRef SourceManager::getBufferData(FileID FID, bool *Invalid) const { return "<<<<<INVALID SOURCE LOCATION>>>>>"; } - llvm::MemoryBuffer *Buf = SLoc.getFile().getContentCache()->getBuffer( + const llvm::MemoryBuffer *Buf = SLoc.getFile().getContentCache()->getBuffer( Diag, *this, SourceLocation(), &MyInvalid); if (Invalid) *Invalid = MyInvalid; @@ -1105,8 +1105,9 @@ const char *SourceManager::getCharacterData(SourceLocation SL, return "<<<<INVALID BUFFER>>>>"; } - llvm::MemoryBuffer *Buffer = Entry.getFile().getContentCache()->getBuffer( - Diag, *this, SourceLocation(), &CharDataInvalid); + const llvm::MemoryBuffer *Buffer = + Entry.getFile().getContentCache()->getBuffer( + Diag, *this, SourceLocation(), &CharDataInvalid); if (Invalid) *Invalid = CharDataInvalid; return Buffer->getBufferStart() + (CharDataInvalid? 0 : LocInfo.second); @@ -1117,7 +1118,7 @@ const char *SourceManager::getCharacterData(SourceLocation SL, unsigned SourceManager::getColumnNumber(FileID FID, unsigned FilePos, bool *Invalid) const { bool MyInvalid = false; - llvm::MemoryBuffer *MemBuf = getBuffer(FID, &MyInvalid); + const llvm::MemoryBuffer *MemBuf = getBuffer(FID, &MyInvalid); if (Invalid) *Invalid = MyInvalid; @@ -1202,7 +1203,8 @@ static void ComputeLineNumbers(DiagnosticsEngine &Diag, ContentCache *FI, llvm::BumpPtrAllocator &Alloc, const SourceManager &SM, bool &Invalid) { // Note that calling 'getBuffer()' may lazily page in the file. - MemoryBuffer *Buffer = FI->getBuffer(Diag, SM, SourceLocation(), &Invalid); + const MemoryBuffer *Buffer = + FI->getBuffer(Diag, SM, SourceLocation(), &Invalid); if (Invalid) return; @@ -1720,7 +1722,7 @@ SourceLocation SourceManager::translateLineCol(FileID FID, return FileLoc.getLocWithOffset(Size); } - llvm::MemoryBuffer *Buffer = Content->getBuffer(Diag, *this); + const llvm::MemoryBuffer *Buffer = Content->getBuffer(Diag, *this); unsigned FilePos = Content->SourceLineCache[Line - 1]; const char *Buf = Buffer->getBufferStart() + FilePos; unsigned BufLength = Buffer->getBufferSize() - FilePos; diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 46f85a107f6..a982ef89396 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -372,7 +372,7 @@ CGDebugInfo::computeChecksum(FileID FID, SmallString<32> &Checksum) const { SourceManager &SM = CGM.getContext().getSourceManager(); bool Invalid; - llvm::MemoryBuffer *MemBuffer = SM.getBuffer(FID, &Invalid); + const llvm::MemoryBuffer *MemBuffer = SM.getBuffer(FID, &Invalid); if (Invalid) return None; diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp index cab3a6bc32b..1f61dc37834 100644 --- a/clang/lib/CodeGen/CodeGenAction.cpp +++ b/clang/lib/CodeGen/CodeGenAction.cpp @@ -943,7 +943,8 @@ static void BitcodeInlineAsmDiagHandler(const llvm::SMDiagnostic &SM, Diags->Report(DiagID).AddString("cannot compile inline asm"); } -std::unique_ptr<llvm::Module> CodeGenAction::loadModule(MemoryBufferRef MBRef) { +std::unique_ptr<llvm::Module> +CodeGenAction::loadModule(MemoryBufferRef MBRef) { CompilerInstance &CI = getCompilerInstance(); SourceManager &SM = CI.getSourceManager(); @@ -1021,7 +1022,7 @@ void CodeGenAction::ExecuteAction() { bool Invalid; SourceManager &SM = CI.getSourceManager(); FileID FID = SM.getMainFileID(); - llvm::MemoryBuffer *MainFile = SM.getBuffer(FID, &Invalid); + const llvm::MemoryBuffer *MainFile = SM.getBuffer(FID, &Invalid); if (Invalid) return; diff --git a/clang/lib/Frontend/PrecompiledPreamble.cpp b/clang/lib/Frontend/PrecompiledPreamble.cpp index d6418645856..59467c3c41b 100644 --- a/clang/lib/Frontend/PrecompiledPreamble.cpp +++ b/clang/lib/Frontend/PrecompiledPreamble.cpp @@ -377,7 +377,7 @@ llvm::ErrorOr<PrecompiledPreamble> PrecompiledPreamble::Build( PrecompiledPreamble::PreambleFileHash::createForFile(File->getSize(), ModTime); } else { - llvm::MemoryBuffer *Buffer = SourceMgr.getMemoryBufferForFile(File); + const llvm::MemoryBuffer *Buffer = SourceMgr.getMemoryBufferForFile(File); FilesInPreamble[File->getName()] = PrecompiledPreamble::PreambleFileHash::createForMemoryBuffer(Buffer); } diff --git a/clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp index cb7ba73a091..b67d6095690 100644 --- a/clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp @@ -1140,7 +1140,7 @@ void EmptyLocalizationContextChecker::MethodCrawler::VisitObjCMessageExpr( } bool Invalid = false; - llvm::MemoryBuffer *BF = + const llvm::MemoryBuffer *BF = Mgr.getSourceManager().getBuffer(SLInfo.first, SL, &Invalid); if (Invalid) return; diff --git a/clang/lib/StaticAnalyzer/Core/IssueHash.cpp b/clang/lib/StaticAnalyzer/Core/IssueHash.cpp index 88d9cdab763..e7497f3fbda 100644 --- a/clang/lib/StaticAnalyzer/Core/IssueHash.cpp +++ b/clang/lib/StaticAnalyzer/Core/IssueHash.cpp @@ -120,7 +120,7 @@ static std::string GetEnclosingDeclContextSignature(const Decl *D) { return ""; } -static StringRef GetNthLineOfFile(llvm::MemoryBuffer *Buffer, int Line) { +static StringRef GetNthLineOfFile(const llvm::MemoryBuffer *Buffer, int Line) { if (!Buffer) return ""; @@ -144,7 +144,7 @@ static std::string NormalizeLine(const SourceManager &SM, FullSourceLoc &L, col++; SourceLocation StartOfLine = SM.translateLineCol(SM.getFileID(L), L.getExpansionLineNumber(), col); - llvm::MemoryBuffer *Buffer = + const llvm::MemoryBuffer *Buffer = SM.getBuffer(SM.getFileID(StartOfLine), StartOfLine); if (!Buffer) return {}; diff --git a/clang/tools/clang-import-test/clang-import-test.cpp b/clang/tools/clang-import-test/clang-import-test.cpp index 823ebed3ed9..b1078acdda9 100644 --- a/clang/tools/clang-import-test/clang-import-test.cpp +++ b/clang/tools/clang-import-test/clang-import-test.cpp @@ -102,7 +102,8 @@ private: unsigned LocColumn = SM.getSpellingColumnNumber(Loc, /*Invalid=*/nullptr) - 1; FileID FID = SM.getFileID(Loc); - llvm::MemoryBuffer *Buffer = SM.getBuffer(FID, Loc, /*Invalid=*/nullptr); + const llvm::MemoryBuffer *Buffer = + SM.getBuffer(FID, Loc, /*Invalid=*/nullptr); assert(LocData >= Buffer->getBufferStart() && LocData < Buffer->getBufferEnd()); diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp index 1ea85ec30df..7bc1c459d8b 100644 --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -4228,7 +4228,7 @@ const char *clang_getFileContents(CXTranslationUnit TU, CXFile file, const SourceManager &SM = cxtu::getASTUnit(TU)->getSourceManager(); FileID fid = SM.translateFile(static_cast<FileEntry *>(file)); bool Invalid = true; - llvm::MemoryBuffer *buf = SM.getBuffer(fid, &Invalid); + const llvm::MemoryBuffer *buf = SM.getBuffer(fid, &Invalid); if (Invalid) { if (size) *size = 0; diff --git a/llvm/include/llvm/Support/MemoryBuffer.h b/llvm/include/llvm/Support/MemoryBuffer.h index 44052697d06..fc327d2fbd7 100644 --- a/llvm/include/llvm/Support/MemoryBuffer.h +++ b/llvm/include/llvm/Support/MemoryBuffer.h @@ -264,7 +264,7 @@ class MemoryBufferRef { public: MemoryBufferRef() = default; - MemoryBufferRef(MemoryBuffer& Buffer) + MemoryBufferRef(const MemoryBuffer& Buffer) : Buffer(Buffer.getBuffer()), Identifier(Buffer.getBufferIdentifier()) {} MemoryBufferRef(StringRef Buffer, StringRef Identifier) : Buffer(Buffer), Identifier(Identifier) {} |

