Lex: Avoid MemoryBuffer* key in ExcludedPreprocessorDirectiveSkipMapping, NFC
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Thu, 8 Oct 2020 22:27:47 +0000 (18:27 -0400)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Mon, 12 Oct 2020 21:39:01 +0000 (17:39 -0400)
This is a prep patch for changing SourceManager to return
`Optional<MemoryBufferRef>` instead of `MemoryBuffer`. With that change the
address of the MemoryBuffer will be gone, so instead use the start of the
buffer as the key for this map.

No functionality change intended, as it's expected that the pointer identity
matches between the buffers and the buffer data.

Radar-Id: rdar://70139990
Differential Revision: https://reviews.llvm.org/D89136

clang/include/clang/Lex/PreprocessorExcludedConditionalDirectiveSkipMapping.h
clang/lib/Lex/PPDirectives.cpp
clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp

index 893b7ba..1a0d5ed 100644 (file)
@@ -23,8 +23,7 @@ using PreprocessorSkippedRangeMapping = llvm::DenseMap<unsigned, unsigned>;
 /// The datastructure that holds the mapping between the active memory buffers
 /// and the individual skip mappings.
 using ExcludedPreprocessorDirectiveSkipMapping =
-    llvm::DenseMap<const llvm::MemoryBuffer *,
-                   const PreprocessorSkippedRangeMapping *>;
+    llvm::DenseMap<const char *, const PreprocessorSkippedRangeMapping *>;
 
 } // end namespace clang
 
index e4b901a..57349d4 100644 (file)
@@ -380,7 +380,10 @@ Optional<unsigned> Preprocessor::getSkippedRangeForExcludedConditionalBlock(
   std::pair<FileID, unsigned> HashFileOffset =
       SourceMgr.getDecomposedLoc(HashLoc);
   const llvm::MemoryBuffer *Buf = SourceMgr.getBuffer(HashFileOffset.first);
-  auto It = ExcludedConditionalDirectiveSkipMappings->find(Buf);
+  if (!Buf)
+    return None;
+  auto It =
+      ExcludedConditionalDirectiveSkipMappings->find(Buf->getBufferStart());
   if (It == ExcludedConditionalDirectiveSkipMappings->end())
     return None;
 
index 63eab82..1c10b7d 100644 (file)
@@ -252,7 +252,7 @@ llvm::ErrorOr<std::unique_ptr<llvm::vfs::File>> MinimizedVFSFile::create(
                                        /*RequiresNullTerminator=*/false),
       *Entry->getStatus());
   if (!Entry->getPPSkippedRangeMapping().empty() && PPSkipMappings)
-    (*PPSkipMappings)[Result->Buffer.get()] =
+    (*PPSkipMappings)[Result->Buffer->getBufferStart()] =
         &Entry->getPPSkippedRangeMapping();
   return llvm::ErrorOr<std::unique_ptr<llvm::vfs::File>>(
       std::unique_ptr<llvm::vfs::File>(std::move(Result)));