This is an archive of the discontinued LLVM Phabricator instance.

[clang][AST] Add support for DecompositionDecl to ASTImporter.
ClosedPublic

Authored by balazske on Jul 2 2021, 8:53 AM.

Details

Summary

BindingDecl was added recently but the related DecompositionDecl is needed
to make C++17 structured bindings importable.
Import of BindingDecl was changed to avoid infinite import loop.

Diff Detail

Event Timeline

balazske created this revision.Jul 2 2021, 8:53 AM
balazske requested review of this revision.Jul 2 2021, 8:53 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 2 2021, 8:53 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
martong added inline comments.Jul 5 2021, 8:59 AM
clang/lib/AST/ASTImporter.cpp
2305–2309

So, we moved the import of the binding before importing the decomposition decl to avoid an infinite recursion. But why can't we have an infinit recursion this way?

Perhaps, it would be useful to have a test case that triggered the infinity in case of the original order of the import calls.

shafik added inline comments.Jul 8 2021, 5:23 PM
clang/lib/AST/ASTImporter.cpp
2305–2309

Yes, I agree, I would also like to understand better why this avoids the infinite recursion problem, a test case would be helpful as well as an explanation of the steps that leads us to the problem.

balazske added inline comments.Jul 9 2021, 12:01 AM
clang/lib/AST/ASTImporter.cpp
2305–2309

With the import at original place, in VisitVarDecl the bindings (which are BindingDecl) are imported before create of the DecompositionDecl instance, and in VisitBindingDecl the decomposition (a DecompositionDecl that is VarDecl) is imported before create of the BindingDecl instance. This causes the recursion with the most simple import of a DecompositionDecl. This is triggered by the existing simple test (actually I discovered the problem at the test failure). If the decomposition is imported after create of the BindingDecl the same BindingDecl is not imported again because it already exists.

martong accepted this revision.Jul 22 2021, 1:02 AM
martong added inline comments.
clang/lib/AST/ASTImporter.cpp
2305–2309

Ok, thanks.

This revision is now accepted and ready to land.Jul 22 2021, 1:02 AM
This revision was landed with ongoing or failed builds.Jul 22 2021, 3:58 AM
This revision was automatically updated to reflect the committed changes.