[PATCH] D101236: [ASTImporter] Import definitions required for layout of [[no_unique_address]] from LLDB
Jan Kratochvil via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Apr 25 02:19:10 PDT 2021
jankratochvil updated this revision to Diff 340340.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D101236/new/
https://reviews.llvm.org/D101236
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
@@ -6323,6 +6323,33 @@
ToD->getTemplateSpecializationKind());
}
+TEST_P(ASTImporterOptionSpecificTestBase, ImportNoUniqueAddress) {
+ Decl *FromTU = getTuDecl(
+ R"(
+ struct A {};
+ struct B {
+ [[no_unique_address]] A a;
+ };
+ struct C : B {
+ char c;
+ } c;
+ )", Lang_CXX20);
+
+ // It does not fail even without the patch!
+ auto *BFromD = FirstDeclMatcher<CXXRecordDecl>().match(
+ FromTU, cxxRecordDecl(hasName("B")));
+ ASSERT_TRUE(BFromD);
+ auto *BToD = Import(BFromD, Lang_CXX20);
+ EXPECT_TRUE(BToD);
+
+ // It does not fail even without the patch!
+ auto *CFromD = FirstDeclMatcher<CXXRecordDecl>().match(
+ FromTU, cxxRecordDecl(hasName("C")));
+ ASSERT_TRUE(CFromD);
+ auto *CToD = Import(CFromD, Lang_CXX20);
+ EXPECT_TRUE(CToD);
+}
+
INSTANTIATE_TEST_CASE_P(ParameterizedTests, ASTImporterLookupTableTest,
DefaultTestValuesForRunOptions, );
Index: clang/lib/AST/ASTImporter.cpp
===================================================================
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -3673,6 +3673,28 @@
D->getInClassInitStyle()))
return ToField;
+ // FieldDecl::isZeroSize may need to check these.
+ if (const Attr *FromAttr = D->getAttr<NoUniqueAddressAttr>()) {
+ if (auto ToAttrOrErr = Importer.Import(FromAttr))
+ ToField->addAttr(*ToAttrOrErr);
+ else
+ return ToAttrOrErr.takeError();
+ RecordType *FromRT =
+ const_cast<RecordType *>(D->getType()->getAs<RecordType>());
+ // Is this field a struct? FieldDecl::isZeroSize will need its definition.
+ if (FromRT) {
+ RecordDecl *FromRD = FromRT->getDecl();
+ RecordType *ToRT =
+ const_cast<RecordType *>(ToField->getType()->getAs<RecordType>());
+ assert(ToRT && "RecordType import has different type");
+ RecordDecl *ToRD = ToRT->getDecl();
+ if (FromRD->isCompleteDefinition() && !ToRD->isCompleteDefinition()) {
+ if (Error Err = ImportDefinition(FromRD, ToRD, IDK_Basic))
+ return std::move(Err);
+ }
+ }
+ }
+
ToField->setAccess(D->getAccess());
ToField->setLexicalDeclContext(LexicalDC);
if (ToInitializer)
@@ -8445,6 +8467,8 @@
// Make sure that ImportImpl registered the imported decl.
assert(ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?");
+ // There may have been NoUniqueAddressAttr for FieldDecl::isZeroSize.
+ ToD->dropAttrs();
if (FromD->hasAttrs())
for (const Attr *FromAttr : FromD->getAttrs()) {
auto ToAttrOrErr = Import(FromAttr);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101236.340340.patch
Type: text/x-patch
Size: 2860 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210425/d323d019/attachment.bin>
More information about the cfe-commits
mailing list