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

Jan Svoboda via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 25 10:07:23 PDT 2023


jansvoboda11 wrote:

The "Index/annotate-module.m" test fails with this patch. For run line 29, the previous input is:
```
Punctuation: "#" [1:1 - 1:2] inclusion directive=Module/Sub2.h (/Users/Jan/Code/upstream-llvm/clang/test/Index/../Modules/Inputs/Module.framework/Headers/Sub2.h)
Identifier: "include" [1:2 - 1:9] inclusion directive=Module/Sub2.h (/Users/Jan/Code/upstream-llvm/clang/test/Index/../Modules/Inputs/Module.framework/Headers/Sub2.h)
Punctuation: "<" [1:10 - 1:11] inclusion directive=Module/Sub2.h (/Users/Jan/Code/upstream-llvm/clang/test/Index/../Modules/Inputs/Module.framework/Headers/Sub2.h)
Identifier: "Module" [1:11 - 1:17] inclusion directive=Module/Sub2.h (/Users/Jan/Code/upstream-llvm/clang/test/Index/../Modules/Inputs/Module.framework/Headers/Sub2.h)
Punctuation: "/" [1:17 - 1:18] inclusion directive=Module/Sub2.h (/Users/Jan/Code/upstream-llvm/clang/test/Index/../Modules/Inputs/Module.framework/Headers/Sub2.h)
Identifier: "Sub2" [1:18 - 1:22] inclusion directive=Module/Sub2.h (/Users/Jan/Code/upstream-llvm/clang/test/Index/../Modules/Inputs/Module.framework/Headers/Sub2.h)
Punctuation: "." [1:22 - 1:23] inclusion directive=Module/Sub2.h (/Users/Jan/Code/upstream-llvm/clang/test/Index/../Modules/Inputs/Module.framework/Headers/Sub2.h)
Identifier: "h" [1:23 - 1:24] inclusion directive=Module/Sub2.h (/Users/Jan/Code/upstream-llvm/clang/test/Index/../Modules/Inputs/Module.framework/Headers/Sub2.h)
Punctuation: ">" [1:24 - 1:25] inclusion directive=Module/Sub2.h (/Users/Jan/Code/upstream-llvm/clang/test/Index/../Modules/Inputs/Module.framework/Headers/Sub2.h)
Keyword: "int" [2:1 - 2:4] VarDecl=Module_Sub:2:6
Punctuation: "*" [2:5 - 2:6] VarDecl=Module_Sub:2:6
Identifier: "Module_Sub" [2:6 - 2:16] VarDecl=Module_Sub:2:6
Punctuation: ";" [2:16 - 2:17]
...
```
while the current output is:
```
Punctuation: "#" [1:1 - 1:2] preprocessing directive=
Identifier: "include" [1:2 - 1:9] preprocessing directive=
Punctuation: "<" [1:10 - 1:11] preprocessing directive=
Identifier: "Module" [1:11 - 1:17] preprocessing directive=
Punctuation: "/" [1:17 - 1:18] preprocessing directive=
Identifier: "Sub2" [1:18 - 1:22] preprocessing directive=
Punctuation: "." [1:22 - 1:23] preprocessing directive=
Identifier: "h" [1:23 - 1:24] preprocessing directive=
Punctuation: ">" [1:24 - 1:25] preprocessing directive=
Keyword: "int" [2:1 - 2:4] VarDecl=Module_Sub:2:6
Punctuation: "*" [2:5 - 2:6] VarDecl=Module_Sub:2:6
Identifier: "Module_Sub" [2:6 - 2:16] VarDecl=Module_Sub:2:6
Punctuation: ";" [2:16 - 2:17]
...
```

This seems to be the stack trace where things go wrong:
```
clang_annotateTokens()
  PreprocessingRecord::getPreprocessedEntitiesInRange(Slow)
    ASTReader::findPreprocessedEntitiesInRange()
      ASTReader::findPreprocessedEntity()
        SourceManager::isBeforeInTranslationUnit()
          SourceManager::isInTheSameTranslationUnit()
            MoveUpIncludeHierarchy()
              SourceManager::getDecomposedIncludedLoc()
```

Here's my current understanding:
* previously:
  * `ModuleFile` gets created with **untranslated** `IncludeLoc`
  * built-in buffer is preloaded and inherits the **untranslated** `IncludeLoc`
  * `ModuleFile::IncludeLoc` gets translated
  * `SourceManager::getDecomposedIncludedLoc()` reports the incorrect `IncludeLoc` for the built-in buffer
* currently:
  * `ModuleFile` gets created with **untranslated** `IncludeLoc`
  * `ModuleFile::IncludeLoc` gets translated
  * built-in buffer is loaded on-demand and inherits the **translated** `IncludeLoc`
  * `SourceManager::getDecomposedIncludedLoc()` reports the correct `IncludeLoc`

I need to dig a bit deeper to figure out what exactly needs fixing here.

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


More information about the cfe-commits mailing list