[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
This commit is contained in:
Balázs Kéri 2021-03-23 09:10:22 +01:00
parent 960a767368
commit 3cde27bc56
2 changed files with 25 additions and 0 deletions

View File

@ -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<Type>(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<VariableArrayType>(ToCapturedVLAType));
LexicalDC->addDeclInternal(ToField);
return ToField;
}

View File

@ -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<FieldDecl>().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, );