Skip to content

Commit 69feac1

Browse files
committed
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
1 parent ac73caf commit 69feac1

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

clang/include/clang/Lex/PreprocessorExcludedConditionalDirectiveSkipMapping.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ using PreprocessorSkippedRangeMapping = llvm::DenseMap<unsigned, unsigned>;
2323
/// The datastructure that holds the mapping between the active memory buffers
2424
/// and the individual skip mappings.
2525
using ExcludedPreprocessorDirectiveSkipMapping =
26-
llvm::DenseMap<const llvm::MemoryBuffer *,
27-
const PreprocessorSkippedRangeMapping *>;
26+
llvm::DenseMap<const char *, const PreprocessorSkippedRangeMapping *>;
2827

2928
} // end namespace clang
3029

clang/lib/Lex/PPDirectives.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,10 @@ Optional<unsigned> Preprocessor::getSkippedRangeForExcludedConditionalBlock(
380380
std::pair<FileID, unsigned> HashFileOffset =
381381
SourceMgr.getDecomposedLoc(HashLoc);
382382
const llvm::MemoryBuffer *Buf = SourceMgr.getBuffer(HashFileOffset.first);
383-
auto It = ExcludedConditionalDirectiveSkipMappings->find(Buf);
383+
if (!Buf)
384+
return None;
385+
auto It =
386+
ExcludedConditionalDirectiveSkipMappings->find(Buf->getBufferStart());
384387
if (It == ExcludedConditionalDirectiveSkipMappings->end())
385388
return None;
386389

clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ llvm::ErrorOr<std::unique_ptr<llvm::vfs::File>> MinimizedVFSFile::create(
252252
/*RequiresNullTerminator=*/false),
253253
*Entry->getStatus());
254254
if (!Entry->getPPSkippedRangeMapping().empty() && PPSkipMappings)
255-
(*PPSkipMappings)[Result->Buffer.get()] =
255+
(*PPSkipMappings)[Result->Buffer->getBufferStart()] =
256256
&Entry->getPPSkippedRangeMapping();
257257
return llvm::ErrorOr<std::unique_ptr<llvm::vfs::File>>(
258258
std::unique_ptr<llvm::vfs::File>(std::move(Result)));

0 commit comments

Comments
 (0)