[clang] 69feac1 - Lex: Avoid MemoryBuffer* key in ExcludedPreprocessorDirectiveSkipMapping, NFC
Duncan P. N. Exon Smith via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 12 14:39:19 PDT 2020
Author: Duncan P. N. Exon Smith
Date: 2020-10-12T17:39:01-04:00
New Revision: 69feac12d0539a7cc19cbda906d46f67029486e1
URL: https://github.com/llvm/llvm-project/commit/69feac12d0539a7cc19cbda906d46f67029486e1
DIFF: https://github.com/llvm/llvm-project/commit/69feac12d0539a7cc19cbda906d46f67029486e1.diff
LOG: Lex: Avoid MemoryBuffer* key in ExcludedPreprocessorDirectiveSkipMapping, NFC
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
Added:
Modified:
clang/include/clang/Lex/PreprocessorExcludedConditionalDirectiveSkipMapping.h
clang/lib/Lex/PPDirectives.cpp
clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Lex/PreprocessorExcludedConditionalDirectiveSkipMapping.h b/clang/include/clang/Lex/PreprocessorExcludedConditionalDirectiveSkipMapping.h
index 893b7ba7a9f5..1a0d5ed57b28 100644
--- a/clang/include/clang/Lex/PreprocessorExcludedConditionalDirectiveSkipMapping.h
+++ b/clang/include/clang/Lex/PreprocessorExcludedConditionalDirectiveSkipMapping.h
@@ -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
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index e4b901a950ae..57349d4a439d 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -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;
diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
index 63eab82820cc..1c10b7d727a5 100644
--- a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
+++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp
@@ -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)));
More information about the cfe-commits
mailing list