[clang][ASTImporter] Improve import of InjectedClassNameType.
authorBalázs Kéri <1.int32@gmail.com>
Wed, 1 Mar 2023 07:42:32 +0000 (08:42 +0100)
committerBalázs Kéri <1.int32@gmail.com>
Wed, 1 Mar 2023 08:26:10 +0000 (09:26 +0100)
commitfeba03340cf3a1690e75ede75ca4603acb9dc2a6
treec74f9d504357ba47ab6f77152c944ee220103f78
parent55fd1a05b977ed540f6c58edda04a37cd78e430e
[clang][ASTImporter] Improve import of InjectedClassNameType.

During AST import multiple different InjectedClassNameType objects
could be created for a single class template. This can cause problems
and failed assertions when these types are compared and found to be
not the same (because the instance is different and there is no
canonical type).
The import of this type does not use the factory method in ASTContext,
probably because the preconditions are not fulfilled at that state.
The fix tries to make the code in ASTImporter work more like the code
in ASTContext::getInjectedClassNameType. If a type is stored at the
Decl or previous Decl object, it is reused instead of creating a new
one. This avoids crash at least a part of the cases.

Reviewed By: gamesh411, donat.nagy, vabridgers

Differential Revision: https://reviews.llvm.org/D140562
clang/lib/AST/ASTImporter.cpp
clang/unittests/AST/ASTImporterTest.cpp