[clang] [clang][modules] Remove preloaded SLocEntries from PCM files (PR #66962)

Jan Svoboda via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 2 15:10:28 PDT 2023


jansvoboda11 wrote:

Since I moved up the special-casing of built-ins buffer up in my last commit, it was happening before we got chance to walk up from `FileID(3)` to `FileID(2)`, meaning it wasn't kicking in. I think we need to sink the special-casing into `isInTheSameTranslationUnit()` and apply it to whatever `FileID` we end up with after not finding the common ancestor without assuming they are in different TUs entirely.

Also, it seems that the code previously assumed that two `SourceLocations` are in the same TU iff they have the same common ancestor. There are at least two counter-examples to this:
* The built-ins buffer doesn't have any ancestor, but still is part of the TU.
* With implicit modules (or lazy loaded explicit modules), all top-level SLocEntries loaded from PCM files have their include location adjusted to the import statement, so they became part of the importer SLocEntry tree and are all considered to be part of the importing TU.

I started tracking the SLocEntries allocated for each AST file and use that to cut off the include chain walk in order to stay in the same TU we started in. This basically make sure we don't skip the special case for loaded built-ins buffers.

https://github.com/llvm/llvm-project/pull/66962


More information about the cfe-commits mailing list