We saw the same assertion failure mentioned here
https://bugs.llvm.org/show_bug.cgi?id=42063 in our internal tests.
The failure happens in the same circumstance as D47898 and D66814 where
uniqueing of DICompositeTypes causes Mapper::mapValue to be called on
GlobalValues(G) from a not-yet-linked module(M). The following type-mapping for
G may not complete correctly (fail to unique types etc. depending on the
the complexity of the types) because IRLinker::computeTypeMapping is not done for M
in this path.
D47898 and D66814 fixed some type-mapping issue after Mapper::mapValue
is called on G. However, it seems it did not handle some complex cases. I
think we should delay linking globals like G until its owing module is
linked. In this way, we could save unnecessary type mapping and prune
these corner cases. It is also supposed to reduce the total number of structs
ending up in the combined module.
Also tested the patch with clang self-host regularLTO/ThinLTO build, things look
good as well.