This revision was automatically updated to reflect the committed changes. Closed by commit rG54c1bcab9010: clang/Basic: Stop using SourceManager::getBuffer, NFC (authored by dexonsmith). Herald added a project: clang.
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D89394/new/ https://reviews.llvm.org/D89394 Files: clang/include/clang/Basic/SourceManager.h clang/lib/Basic/Diagnostic.cpp clang/lib/Basic/SourceLocation.cpp clang/lib/Basic/SourceManager.cpp Index: clang/lib/Basic/SourceManager.cpp =================================================================== --- clang/lib/Basic/SourceManager.cpp +++ clang/lib/Basic/SourceManager.cpp @@ -1228,12 +1228,11 @@ /// this is significantly cheaper to compute than the line number. unsigned SourceManager::getColumnNumber(FileID FID, unsigned FilePos, bool *Invalid) const { - bool MyInvalid = false; - const llvm::MemoryBuffer *MemBuf = getBuffer(FID, &MyInvalid); + llvm::Optional<llvm::MemoryBufferRef> MemBuf = getBufferOrNone(FID); if (Invalid) - *Invalid = MyInvalid; + *Invalid = !MemBuf; - if (MyInvalid) + if (!MemBuf) return 1; // It is okay to request a position just past the end of the buffer. @@ -1509,7 +1508,10 @@ bool *Invalid) const { if (isInvalid(Loc, Invalid)) return "<invalid loc>"; - return getBuffer(getFileID(Loc), Invalid)->getBufferIdentifier(); + auto B = getBufferOrNone(getFileID(Loc)); + if (Invalid) + *Invalid = !B; + return B ? B->getBufferIdentifier() : "<invalid buffer>"; } /// getPresumedLoc - This method returns the "presumed" location of a @@ -2047,8 +2049,8 @@ // If we arrived here, the location is either in a built-ins buffer or // associated with global inline asm. PR5662 and PR22576 are examples. - StringRef LB = getBuffer(LOffs.first)->getBufferIdentifier(); - StringRef RB = getBuffer(ROffs.first)->getBufferIdentifier(); + StringRef LB = getBufferOrFake(LOffs.first).getBufferIdentifier(); + StringRef RB = getBufferOrFake(ROffs.first).getBufferIdentifier(); bool LIsBuiltins = LB == "<built-in>"; bool RIsBuiltins = RB == "<built-in>"; // Sort built-in before non-built-in. Index: clang/lib/Basic/SourceLocation.cpp =================================================================== --- clang/lib/Basic/SourceLocation.cpp +++ clang/lib/Basic/SourceLocation.cpp @@ -245,7 +245,7 @@ StringRef FullSourceLoc::getBufferData(bool *Invalid) const { assert(isValid()); - return SrcMgr->getBuffer(SrcMgr->getFileID(*this), Invalid)->getBuffer(); + return SrcMgr->getBufferData(SrcMgr->getFileID(*this), Invalid); } std::pair<FileID, unsigned> FullSourceLoc::getDecomposedLoc() const { Index: clang/lib/Basic/Diagnostic.cpp =================================================================== --- clang/lib/Basic/Diagnostic.cpp +++ clang/lib/Basic/Diagnostic.cpp @@ -265,7 +265,8 @@ PrintedOuterHeading = true; llvm::errs() << "File " << &File << " <FileID " << ID.getHashValue() - << ">: " << SrcMgr.getBuffer(ID)->getBufferIdentifier(); + << ">: " << SrcMgr.getBufferOrFake(ID).getBufferIdentifier(); + if (F.second.Parent) { std::pair<FileID, unsigned> Decomp = SrcMgr.getDecomposedIncludedLoc(ID); Index: clang/include/clang/Basic/SourceManager.h =================================================================== --- clang/include/clang/Basic/SourceManager.h +++ clang/include/clang/Basic/SourceManager.h @@ -980,6 +980,17 @@ Diag, getFileManager(), Loc); } + /// Return the buffer for the specified FileID. + /// + /// If there is an error opening this buffer the first time, this + /// manufactures a temporary buffer and returns it. + llvm::MemoryBufferRef + getBufferOrFake(FileID FID, SourceLocation Loc = SourceLocation()) const { + if (auto B = getBufferOrNone(FID, Loc)) + return *B; + return getFakeBufferForRecovery()->getMemBufferRef(); + } + /// Return the buffer for the specified FileID. /// /// If there is an error opening this buffer the first time, this
Index: clang/lib/Basic/SourceManager.cpp =================================================================== --- clang/lib/Basic/SourceManager.cpp +++ clang/lib/Basic/SourceManager.cpp @@ -1228,12 +1228,11 @@ /// this is significantly cheaper to compute than the line number. unsigned SourceManager::getColumnNumber(FileID FID, unsigned FilePos, bool *Invalid) const { - bool MyInvalid = false; - const llvm::MemoryBuffer *MemBuf = getBuffer(FID, &MyInvalid); + llvm::Optional<llvm::MemoryBufferRef> MemBuf = getBufferOrNone(FID); if (Invalid) - *Invalid = MyInvalid; + *Invalid = !MemBuf; - if (MyInvalid) + if (!MemBuf) return 1; // It is okay to request a position just past the end of the buffer. @@ -1509,7 +1508,10 @@ bool *Invalid) const { if (isInvalid(Loc, Invalid)) return "<invalid loc>"; - return getBuffer(getFileID(Loc), Invalid)->getBufferIdentifier(); + auto B = getBufferOrNone(getFileID(Loc)); + if (Invalid) + *Invalid = !B; + return B ? B->getBufferIdentifier() : "<invalid buffer>"; } /// getPresumedLoc - This method returns the "presumed" location of a @@ -2047,8 +2049,8 @@ // If we arrived here, the location is either in a built-ins buffer or // associated with global inline asm. PR5662 and PR22576 are examples. - StringRef LB = getBuffer(LOffs.first)->getBufferIdentifier(); - StringRef RB = getBuffer(ROffs.first)->getBufferIdentifier(); + StringRef LB = getBufferOrFake(LOffs.first).getBufferIdentifier(); + StringRef RB = getBufferOrFake(ROffs.first).getBufferIdentifier(); bool LIsBuiltins = LB == "<built-in>"; bool RIsBuiltins = RB == "<built-in>"; // Sort built-in before non-built-in. Index: clang/lib/Basic/SourceLocation.cpp =================================================================== --- clang/lib/Basic/SourceLocation.cpp +++ clang/lib/Basic/SourceLocation.cpp @@ -245,7 +245,7 @@ StringRef FullSourceLoc::getBufferData(bool *Invalid) const { assert(isValid()); - return SrcMgr->getBuffer(SrcMgr->getFileID(*this), Invalid)->getBuffer(); + return SrcMgr->getBufferData(SrcMgr->getFileID(*this), Invalid); } std::pair<FileID, unsigned> FullSourceLoc::getDecomposedLoc() const { Index: clang/lib/Basic/Diagnostic.cpp =================================================================== --- clang/lib/Basic/Diagnostic.cpp +++ clang/lib/Basic/Diagnostic.cpp @@ -265,7 +265,8 @@ PrintedOuterHeading = true; llvm::errs() << "File " << &File << " <FileID " << ID.getHashValue() - << ">: " << SrcMgr.getBuffer(ID)->getBufferIdentifier(); + << ">: " << SrcMgr.getBufferOrFake(ID).getBufferIdentifier(); + if (F.second.Parent) { std::pair<FileID, unsigned> Decomp = SrcMgr.getDecomposedIncludedLoc(ID); Index: clang/include/clang/Basic/SourceManager.h =================================================================== --- clang/include/clang/Basic/SourceManager.h +++ clang/include/clang/Basic/SourceManager.h @@ -980,6 +980,17 @@ Diag, getFileManager(), Loc); } + /// Return the buffer for the specified FileID. + /// + /// If there is an error opening this buffer the first time, this + /// manufactures a temporary buffer and returns it. + llvm::MemoryBufferRef + getBufferOrFake(FileID FID, SourceLocation Loc = SourceLocation()) const { + if (auto B = getBufferOrNone(FID, Loc)) + return *B; + return getFakeBufferForRecovery()->getMemBufferRef(); + } + /// Return the buffer for the specified FileID. /// /// If there is an error opening this buffer the first time, this
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits