[clang] [ASTWriter] Detect more non-affecting FileIDs to reduce source location duplication (PR #112015)

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 4 05:09:15 PST 2024


ilya-biryukov wrote:

> Did you mean _"mark it as affecting"_ / _"not mark it as **non**-affecting"_ instead of _"**not** mark it as affecting"_?

Yes, sorry, that was a mistake on my part.

> Can you expand on that? Why doesn't it work properly if you stop writing those input files as well?

Because `ClangScanDeps` relies on the information from those `InputFIle` to determine which module map files the code depends on, the relevant code is here: https://github.com/llvm/llvm-project/blob/a15bf88d532ad2e81d7c54c480707f6c7d8bbeab/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp#L599

If we stop producing those input files, it should not affect the compiler in any way, but clang-scan-deps will be broken (some tests will fail, including the ones that check the final commands can compile the underlying modules)

> This is unexpected and I think it breaks the correctness of clang-scan-deps. I think we might need to take your patch a bit further and make it so that `ASTWriter::WriteInputFiles()` doesn't care whether the SLocEntry associated with the file through `Module::DefinitionLoc` is loaded or local.

Hm, that would actually make the final outputs much more predictable, so I like this approach. Let me try to prototype it and get back to you.
The only downside is more `InputFile` entries being reported, but I bet they are a very small fraction of the serialized AST, so it should not really matter. 

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


More information about the cfe-commits mailing list