This is an archive of the discontinued LLVM Phabricator instance.

[ASTImporter] Make the Import() return value consistent with the map of imported decls when merging ClassTemplateSpecializationDecls
ClosedPublic

Authored by teemperor on Nov 24 2020, 2:24 AM.

Details

Summary

When importing a ClassTemplateSpecializationDecl definition into a TU with a matching
ClassTemplateSpecializationDecl definition and a more recent forward decl, the ASTImporter
currently will call MapImported() for the definitions, but will return the forward declaration
from the ASTImporter::Import() call.

This is triggering some assertions in LLDB when we try to fully import some DeclContexts
before we delete the 'From' AST. The returned 'To' Decl before this patch is just the most recent
forward decl but that's not the Decl with the definition to which the ASTImporter will import
the child declarations.

This patch just changes that the ASTImporter returns the definition that the imported Decl was
merged with instead of the found forward declaration.

Diff Detail

Event Timeline

teemperor created this revision.Nov 24 2020, 2:24 AM
teemperor requested review of this revision.Nov 24 2020, 2:24 AM

Can be triggered in LLDB by running something like this twice in LLDB expr --top-level -- template<typename T> struct TL; template<> struct TL<int>; template<typename T> struct TL { int m; }; template<> struct TL<int> { int m; };

martong accepted this revision.Nov 24 2020, 8:44 AM

LGTM! And thanks for the pro unittest!

This revision is now accepted and ready to land.Nov 24 2020, 8:44 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 24 2020, 2:46 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Great catch!