[clang] [clang] Allow delayed function instantiation at TU end if initial instantiation fails (PR #117167)

via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 26 02:46:46 PST 2024


StefanPaulet wrote:

The trace that I found was:
- return type for `dispatch` must be deduced
- `dispatch` is instantiated
- `callable()` is instantiated as part of `LocalEagerInstantiationScope` (calling `PerformPendingInstantiations`)
- `InstantiateFunctionDefinition` for `callable()` is called with `Recursive=true`
- A `GlobalEagerInstantiationScope` is created with `/*Enabled=*/ Recursive = true`
- `foo` is eagerly instantiated from `GlobalInstantiations.perform()`

The issue comes from the fact that `Sema::PerformPendingInstantiations` calls `InstantiateFunctionDefinition` with both `Recursive=true` and `AtEndOfTU=true`. I was not sure about when `Recursive` should be enabled so I did not touch it. Could you shed some light on its purpose please?

As for the diagnostics issue, I think it can be solved if I only try a second instantiation for implicit instantiations. Diagnostics for implicit instantiations only get emitted at the end of the TU. Also, implicit instantiations seem to be the only ones that cause this issue, as I haven't been able to replicate this behaviour otherwise.

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


More information about the cfe-commits mailing list