From 3cde27bc563ce82ba081be5b650bec523df2c928 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= <1.int32@gmail.com> Date: Tue, 23 Mar 2021 09:10:22 +0100 Subject: [PATCH] [clang][ASTImporter] Import "CapturedVLAType" in FieldDecl. Update ASTImporter to import value of FieldDecl::getCapturedVLAType. Reviewed By: shafik, martong Differential Revision: https://reviews.llvm.org/D99062 --- clang/lib/AST/ASTImporter.cpp | 6 ++++++ clang/unittests/AST/ASTImporterTest.cpp | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index f9b1910552ee..c4f36b50db9d 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -3632,6 +3632,10 @@ ExpectedDecl ASTNodeImporter::VisitFieldDecl(FieldDecl *D) { auto ToInitializer = importChecked(Err, D->getInClassInitializer()); if (Err) return std::move(Err); + const Type *ToCapturedVLAType = nullptr; + if (Error Err = Importer.importInto( + ToCapturedVLAType, cast_or_null(D->getCapturedVLAType()))) + return std::move(Err); FieldDecl *ToField; if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC, @@ -3645,6 +3649,8 @@ ExpectedDecl ASTNodeImporter::VisitFieldDecl(FieldDecl *D) { if (ToInitializer) ToField->setInClassInitializer(ToInitializer); ToField->setImplicit(D->isImplicit()); + if (ToCapturedVLAType) + ToField->setCapturedVLAType(cast(ToCapturedVLAType)); LexicalDC->addDeclInternal(ToField); return ToField; } diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index 9458fc226580..94cec2c140e1 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -6261,6 +6261,25 @@ TEST_P(ASTImporterOptionSpecificTestBase, EXPECT_TRUE(To2); } +TEST_P(ASTImporterOptionSpecificTestBase, ImportOfCapturedVLAType) { + Decl *FromTU = getTuDecl( + R"( + void declToImport(int N) { + int VLA[N]; + [&VLA] {}; // FieldDecl inside the lambda. + } + )", + Lang_CXX14); + auto *FromFD = FirstDeclMatcher().match(FromTU, fieldDecl()); + ASSERT_TRUE(FromFD); + ASSERT_TRUE(FromFD->hasCapturedVLAType()); + + auto *ToFD = Import(FromFD, Lang_CXX14); + EXPECT_TRUE(ToFD); + EXPECT_TRUE(ToFD->hasCapturedVLAType()); + EXPECT_NE(FromFD->getCapturedVLAType(), ToFD->getCapturedVLAType()); +} + INSTANTIATE_TEST_CASE_P(ParameterizedTests, ASTImporterLookupTableTest, DefaultTestValuesForRunOptions, );