[PATCH] D105354: [clang][AST] Add support for DecompositionDecl to ASTImporter.
Balázs Kéri via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 22 03:58:09 PDT 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG41adc09b2211: [clang][AST] Add support for DecompositionDecl to ASTImporter. (authored by balazske).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D105354/new/
https://reviews.llvm.org/D105354
Files:
clang/lib/AST/ASTImporter.cpp
clang/unittests/AST/ASTImporterTest.cpp
Index: clang/unittests/AST/ASTImporterTest.cpp
===================================================================
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -3725,6 +3725,32 @@
VerifyImport("y3");
}
+TEST_P(ImportVariables, ImportDecompositionDeclArray) {
+ Decl *From, *To;
+ std::tie(From, To) = getImportedDecl(
+ R"(
+ void declToImport() {
+ int a[2] = {1,2};
+ auto [x1,y1] = a;
+ };
+ )",
+ Lang_CXX17, "", Lang_CXX17);
+
+ TranslationUnitDecl *FromTU = From->getTranslationUnitDecl();
+ auto *FromDecomp =
+ FirstDeclMatcher<DecompositionDecl>().match(FromTU, decompositionDecl());
+ auto *ToDecomp = Import(FromDecomp, Lang_CXX17);
+ EXPECT_TRUE(ToDecomp);
+
+ ArrayRef<BindingDecl *> FromB = FromDecomp->bindings();
+ ArrayRef<BindingDecl *> ToB = ToDecomp->bindings();
+ EXPECT_EQ(FromB.size(), ToB.size());
+ for (unsigned int I = 0; I < FromB.size(); ++I) {
+ auto *ToBI = Import(FromB[I], Lang_CXX17);
+ EXPECT_EQ(ToBI, ToB[I]);
+ }
+}
+
struct ImportClasses : ASTImporterOptionSpecificTestBase {};
TEST_P(ImportClasses, ImportDefinitionWhenProtoIsInNestedToContext) {
Index: clang/lib/AST/ASTImporter.cpp
===================================================================
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -2302,6 +2302,11 @@
if (ToND)
return ToND;
+ BindingDecl *ToD;
+ if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, Loc,
+ Name.getAsIdentifierInfo()))
+ return ToD;
+
Error Err = Error::success();
QualType ToType = importChecked(Err, D->getType());
Expr *ToBinding = importChecked(Err, D->getBinding());
@@ -2309,11 +2314,6 @@
if (Err)
return std::move(Err);
- BindingDecl *ToD;
- if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, Loc,
- Name.getAsIdentifierInfo()))
- return ToD;
-
ToD->setBinding(ToType, ToBinding);
ToD->setDecomposedDecl(ToDecomposedDecl);
addDeclToContexts(D, ToD);
@@ -4098,14 +4098,26 @@
if (Err)
return std::move(Err);
- // Create the imported variable.
VarDecl *ToVar;
- if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC,
- ToInnerLocStart, Loc,
- Name.getAsIdentifierInfo(),
- ToType, ToTypeSourceInfo,
- D->getStorageClass()))
- return ToVar;
+ if (auto *FromDecomp = dyn_cast<DecompositionDecl>(D)) {
+ SmallVector<BindingDecl *> Bindings(FromDecomp->bindings().size());
+ if (Error Err =
+ ImportArrayChecked(FromDecomp->bindings(), Bindings.begin()))
+ return std::move(Err);
+ DecompositionDecl *ToDecomp;
+ if (GetImportedOrCreateDecl(
+ ToDecomp, FromDecomp, Importer.getToContext(), DC, ToInnerLocStart,
+ Loc, ToType, ToTypeSourceInfo, D->getStorageClass(), Bindings))
+ return ToDecomp;
+ ToVar = ToDecomp;
+ } else {
+ // Create the imported variable.
+ if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC,
+ ToInnerLocStart, Loc,
+ Name.getAsIdentifierInfo(), ToType,
+ ToTypeSourceInfo, D->getStorageClass()))
+ return ToVar;
+ }
ToVar->setTSCSpec(D->getTSCSpec());
ToVar->setQualifierInfo(ToQualifierLoc);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105354.360759.patch
Type: text/x-patch
Size: 3499 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210722/3c841aee/attachment.bin>
More information about the cfe-commits
mailing list