[clang] b03ae74 - clang/Lex: Stop using SourceManager::getBuffer

Duncan P. N. Exon Smith via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 19 17:28:38 PDT 2020


Author: Duncan P. N. Exon Smith
Date: 2020-10-19T20:27:56-04:00
New Revision: b03ae74319f19c3b86982638671d00205a91d263

URL: https://github.com/llvm/llvm-project/commit/b03ae74319f19c3b86982638671d00205a91d263
DIFF: https://github.com/llvm/llvm-project/commit/b03ae74319f19c3b86982638671d00205a91d263.diff

LOG: clang/Lex: Stop using SourceManager::getBuffer

Update clang/lib/Lex to stop relying on a `MemoryBuffer*`, using the
`MemoryBufferRef` from `getBufferOrNone` since both locations had logic
for checking validity of the buffer. There's potentially a functionality
change, since the logic was wrong (it checked for `nullptr`, which was
never returned by the old API), but if that was reachable the new
behaviour should be better.

Differential Revision: https://reviews.llvm.org/D89402

Added: 
    

Modified: 
    clang/lib/Lex/ModuleMap.cpp
    clang/lib/Lex/PPDirectives.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index 12da5a85da37..c47a3a0f14c4 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -3004,7 +3004,7 @@ bool ModuleMap::parseModuleMapFile(const FileEntry *File, bool IsSystem,
   }
 
   assert(Target && "Missing target information");
-  const llvm::MemoryBuffer *Buffer = SourceMgr.getBuffer(ID);
+  llvm::Optional<llvm::MemoryBufferRef> Buffer = SourceMgr.getBufferOrNone(ID);
   if (!Buffer)
     return ParsedModuleMap[File] = true;
   assert((!Offset || *Offset <= Buffer->getBufferSize()) &&

diff  --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 57349d4a439d..62724d467eac 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -379,7 +379,8 @@ Optional<unsigned> Preprocessor::getSkippedRangeForExcludedConditionalBlock(
 
   std::pair<FileID, unsigned> HashFileOffset =
       SourceMgr.getDecomposedLoc(HashLoc);
-  const llvm::MemoryBuffer *Buf = SourceMgr.getBuffer(HashFileOffset.first);
+  Optional<llvm::MemoryBufferRef> Buf =
+      SourceMgr.getBufferOrNone(HashFileOffset.first);
   if (!Buf)
     return None;
   auto It =


        


More information about the cfe-commits mailing list