[PATCH] D135132: [SourceManager] Improve getFileIDLocal.

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 5 00:54:14 PDT 2022


sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.


================
Comment at: clang/lib/Basic/SourceManager.cpp:807
   }
 
   // Find the FileID that contains this.  "I" is an iterator that points to a
----------------
Just checking: we decrement GreaterIndex without a bounds check in the loop and then dereference it in the loop.

I guess this is safe because:
- in the case where it's equal to size(), it's nonzero due to a dummy entry at 0 (and unchanged in this patch)
- in the case where the cache is used, it's also nonzero (guarded)

Maybe this is worth an assertion?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135132/new/

https://reviews.llvm.org/D135132



More information about the cfe-commits mailing list