This is an archive of the discontinued LLVM Phabricator instance.

[clang][AST] Set correct DeclContext in ASTImporter lookup table for template params.
ClosedPublic

Authored by balazske on Jun 7 2021, 1:13 AM.

Details

Summary

Template parameters are created in ASTImporter with the translation unit as DeclContext.
The DeclContext is later updated (by the create function of template classes).
ASTImporterLookupTable was not updated after these changes of the DC. The patch
adds update of the DeclContext in ASTImporterLookupTable.

Diff Detail

Event Timeline

balazske created this revision.Jun 7 2021, 1:13 AM
balazske requested review of this revision.Jun 7 2021, 1:13 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 7 2021, 1:13 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
shafik added inline comments.Jun 7 2021, 7:00 PM
clang/lib/AST/ASTImporter.cpp
6049

Is this case covered in the tests?

balazske updated this revision to Diff 350906.Jun 9 2021, 8:19 AM

Add test for deduction guides.

balazske marked an inline comment as done.Jun 9 2021, 8:21 AM
balazske added inline comments.
clang/lib/AST/ASTImporter.cpp
6049

This test was left out but added now. But test CTADImplicit does fail if the import of FunctionTemplateDecl is handled similarly as the other cases.

balazske marked an inline comment as done.Jun 9 2021, 8:23 AM
balazske added inline comments.
clang/unittests/AST/ASTImporterTest.cpp
4482

This should not have been reformatted.

balazske updated this revision to Diff 351082.Jun 10 2021, 12:57 AM

Added AST dump without clang-format into test code.

martong added inline comments.Jun 14 2021, 5:17 AM
clang/lib/AST/ASTImporter.cpp
6005–6006

Do you think that the alternative approach that is used with TypedefNameDecl could work here?

// Do not import the DeclContext, we will import it once the TypedefNameDecl
// is created.
if (Error Err = ImportDeclParts(D, Name, ToD, Loc))
  return std::move(Err);

With that perhaps we could avoid the hassle with the update. Could you please investigate that?

6055

typo: is is -> it is

balazske added inline comments.Jun 14 2021, 9:04 AM
clang/lib/AST/ASTImporter.cpp
6005–6006

The problem is not with the DC of the FunctionTemplateDecl, it is with the template parameters. It looks not safe to pass nullptr as DeclContext for these, this is only possible if the import is done. (Probably the solution in TypedefNameDecl is not perfect: If something exists already in the "To TU" that was not imported, specially a namespace that contains a typedef with same name, it may not be found before the import.)

martong accepted this revision.Jun 15 2021, 5:28 AM

Ok, looks good to me! Thanks!

This revision is now accepted and ready to land.Jun 15 2021, 5:28 AM
balazske updated this revision to Diff 352625.Jun 16 2021, 11:59 PM

Fixed typo error in comment.

balazske marked an inline comment as done.Jun 17 2021, 12:01 AM
This revision was landed with ongoing or failed builds.Jun 17 2021, 2:09 AM
This revision was automatically updated to reflect the committed changes.