From: Duncan P. N. Exon Smith Date: Thu, 8 Oct 2020 22:27:47 +0000 (-0400) Subject: Lex: Avoid MemoryBuffer* key in ExcludedPreprocessorDirectiveSkipMapping, NFC X-Git-Tag: llvmorg-13-init~9493 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=69feac12d0539a7cc19cbda906d46f67029486e1;p=platform%2Fupstream%2Fllvm.git Lex: Avoid MemoryBuffer* key in ExcludedPreprocessorDirectiveSkipMapping, NFC This is a prep patch for changing SourceManager to return `Optional` 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 --- diff --git a/clang/include/clang/Lex/PreprocessorExcludedConditionalDirectiveSkipMapping.h b/clang/include/clang/Lex/PreprocessorExcludedConditionalDirectiveSkipMapping.h index 893b7ba..1a0d5ed 100644 --- a/clang/include/clang/Lex/PreprocessorExcludedConditionalDirectiveSkipMapping.h +++ b/clang/include/clang/Lex/PreprocessorExcludedConditionalDirectiveSkipMapping.h @@ -23,8 +23,7 @@ using PreprocessorSkippedRangeMapping = llvm::DenseMap; /// The datastructure that holds the mapping between the active memory buffers /// and the individual skip mappings. using ExcludedPreprocessorDirectiveSkipMapping = - llvm::DenseMap; + llvm::DenseMap; } // end namespace clang diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index e4b901a..57349d4 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -380,7 +380,10 @@ Optional Preprocessor::getSkippedRangeForExcludedConditionalBlock( std::pair 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 63eab82..1c10b7d 100644 --- a/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp +++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningFilesystem.cpp @@ -252,7 +252,7 @@ llvm::ErrorOr> 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(std::move(Result)));