[PATCH] D130847: [clang] SourceManager: fix isOffsetInFileID for the case of a fake SLocEntry

Ivan Murashko via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 2 04:45:57 PDT 2022

ivanmurashko added a comment.

In D130847#3690977 <https://reviews.llvm.org/D130847#3690977>, @aaron.ballman wrote:


> Given that this code is on the hot path, should it be the caller's responsibility to have already validated the `FileID` that's passed in so that the fake entry can never be returned?

That is a good point. The crash that I am trying to fix uses incorrectly assigned `SourceManager::LastFileIDLookup`, see SourceManager::getFileID <https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/SourceManager.h#L1112>. It's worth avoiding the incorrect cache value assignment. I could determine the place at the code where the assignment was made and updated the patch accordingly.

@aaron.ballman, could you look at the update. Is it reasonable?

Note: the change introduces a check that similar to one made previously <https://reviews.llvm.org/rG7dc4f33c77acd90b3217b94e50965bbcefbcd55f> for the rest of the search procedure

Comment at: clang/include/clang/Basic/SourceManager.h:1112-1113
     // If our one-entry cache covers this offset, just return it.
     if (isOffsetInFileID(LastFileIDLookup, SLocOffset))
       return LastFileIDLookup;
nit: There is the place when `isOffsetInFileID` produces a wrong result at my case

  rG LLVM Github Monorepo



More information about the cfe-commits mailing list