[PATCH] D65481: NFCI: Simplify SourceManager::translateFile by removing code path that should never be taken

Alex Lorenz via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 30 15:31:39 PDT 2019


arphaman created this revision.
arphaman added reviewers: rsmith, bruno, Bigcheese.
Herald added subscribers: dexonsmith, jkorous.
Herald added a project: clang.

I noticed that `SourceManager::translateFile` has code that doesn't really make sense. In particular, if it fails to find a `FileID` by comparing `FileEntry *` values, it tries to look through files that have the same filename, to see if they have a matching inode to try to find the right `FileID`. However, the inode comparison seem redundant, as Clang's `FileManager` already deduplicates `FileEntry *` values by inode. Thus the comparisons between inodes should never actually succeed, and the comparison between `FileEntry *` values should be sufficient here.

This observation is supported by the code coverage report that shows that we never actually reach the case where the INODE comparison succeeds:
http://lab.llvm.org:8080/coverage/coverage-reports/clang/coverage/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/lib/Basic/SourceManager.cpp.html#L1595


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65481

Files:
  clang/lib/Basic/SourceManager.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65481.212454.patch
Type: text/x-patch
Size: 6085 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190730/bb913a7a/attachment.bin>


More information about the cfe-commits mailing list