[clang] [Serialization] Fix lazy template loading (PR #133057)

Jonas Hahnfeld via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 27 02:45:02 PST 2025


hahnjo wrote:

> I could allocate some time to debugging this, and here's what I got.

Thanks for trying all that!

> It looks like it happens as you suspected ("`D->hasExternalLexicalStorage()` returns `false` and we skip the call to `CompleteType`").

Ok, at least the understanding of the problem is progressing.

> I tried changing that condition to `getExternalSource() && !D->getDefinition()`, but it doesn't help - I'm still getting the same assertion:

Too bad, that would have been too easy I guess... Now I wonder if we maybe need to change the order of operations, ie first complete the redecl chain, then notice that we can get the definition externally, and then actually go and do that. Conceptually something like
```c++
  // Complete the redecl chain (if necessary).
  D = D->getMostRecentDecl();

  if (D->hasExternalLexicalStorage() && !D->getDefinition())
    getExternalSource()->CompleteType(const_cast<RecordDecl*>(D));
```

Not sure if that changes anything (at least it doesn't fail Clang tests when applied to current `master` on its own), but as I said earlier "redecl chains are a bit black magic for me". But if we are getting close to getting a sharable reproducer, I will be able to have a look myself.

> Please let me know, if you have any more ideas I could try.

Only if you have more time to spare, the second part of point 4. above, ie which of the commits is the culprit: Is it a single one and everything is fine if you just exclude / revert that one?

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


More information about the cfe-commits mailing list