Index: clang/include/clang/Basic/SourceManager.h =================================================================== --- clang/include/clang/Basic/SourceManager.h +++ clang/include/clang/Basic/SourceManager.h @@ -145,7 +145,7 @@ /// /// This is lazily computed. The lines are owned by the SourceManager /// BumpPointerAllocator object. - LineOffsetMapping SourceLineCache; + mutable LineOffsetMapping SourceLineCache; /// Indicates whether the buffer itself was provided to override /// the actual file contents. @@ -718,7 +718,7 @@ /// These ivars serve as a cache used in the getLineNumber /// method which is used to speedup getLineNumber calls to nearby locations. mutable FileID LastLineNoFileIDQuery; - mutable SrcMgr::ContentCache *LastLineNoContentCache; + mutable const SrcMgr::ContentCache *LastLineNoContentCache; mutable unsigned LastLineNoFilePos; mutable unsigned LastLineNoResult; Index: clang/lib/Basic/SourceManager.cpp =================================================================== --- clang/lib/Basic/SourceManager.cpp +++ clang/lib/Basic/SourceManager.cpp @@ -1259,20 +1259,20 @@ #endif static LLVM_ATTRIBUTE_NOINLINE void -ComputeLineNumbers(DiagnosticsEngine &Diag, ContentCache *FI, +ComputeLineNumbers(DiagnosticsEngine &Diag, const ContentCache &FI, llvm::BumpPtrAllocator &Alloc, const SourceManager &SM, bool &Invalid); -static void ComputeLineNumbers(DiagnosticsEngine &Diag, ContentCache *FI, +static void ComputeLineNumbers(DiagnosticsEngine &Diag, const ContentCache &FI, llvm::BumpPtrAllocator &Alloc, const SourceManager &SM, bool &Invalid) { // Note that calling 'getBuffer()' may lazily page in the file. llvm::Optional Buffer = - FI->getBufferOrNone(Diag, SM.getFileManager(), SourceLocation()); + FI.getBufferOrNone(Diag, SM.getFileManager(), SourceLocation()); Invalid = !Buffer; if (Invalid) return; - FI->SourceLineCache = LineOffsetMapping::get(*Buffer, Alloc); + FI.SourceLineCache = LineOffsetMapping::get(*Buffer, Alloc); } LineOffsetMapping LineOffsetMapping::get(llvm::MemoryBufferRef Buffer, @@ -1322,7 +1322,7 @@ return 1; } - ContentCache *Content; + const ContentCache *Content; if (LastLineNoFileIDQuery == FID) Content = LastLineNoContentCache; else { @@ -1334,14 +1334,14 @@ return 1; } - Content = const_cast(Entry.getFile().getContentCache()); + Content = Entry.getFile().getContentCache(); } // If this is the first use of line information for this buffer, compute the /// SourceLineCache for it on demand. if (!Content->SourceLineCache) { bool MyInvalid = false; - ComputeLineNumbers(Diag, Content, ContentCacheAlloc, *this, MyInvalid); + ComputeLineNumbers(Diag, *Content, ContentCacheAlloc, *this, MyInvalid); if (Invalid) *Invalid = MyInvalid; if (MyInvalid) @@ -1685,8 +1685,7 @@ if (Line == 1 && Col == 1) return FileLoc; - ContentCache *Content - = const_cast(Entry.getFile().getContentCache()); + const ContentCache *Content = Entry.getFile().getContentCache(); if (!Content) return SourceLocation(); @@ -1694,7 +1693,7 @@ // SourceLineCache for it on demand. if (!Content->SourceLineCache) { bool MyInvalid = false; - ComputeLineNumbers(Diag, Content, ContentCacheAlloc, *this, MyInvalid); + ComputeLineNumbers(Diag, *Content, ContentCacheAlloc, *this, MyInvalid); if (MyInvalid) return SourceLocation(); } Index: clang/lib/Lex/ScratchBuffer.cpp =================================================================== --- clang/lib/Lex/ScratchBuffer.cpp +++ clang/lib/Lex/ScratchBuffer.cpp @@ -37,10 +37,10 @@ else { // Clear out the source line cache if it's already been computed. // FIXME: Allow this to be incrementally extended. - auto *ContentCache = const_cast( - SourceMgr.getSLocEntry(SourceMgr.getFileID(BufferStartLoc)) - .getFile().getContentCache()); - ContentCache->SourceLineCache = SrcMgr::LineOffsetMapping(); + SourceMgr.getSLocEntry(SourceMgr.getFileID(BufferStartLoc)) + .getFile() + .getContentCache() + ->SourceLineCache = SrcMgr::LineOffsetMapping(); } // Prefix the token with a \n, so that it looks like it is the first thing on