Revert "[clang][ASTImport] Add support for import of empty records"

This reverts commit 21cd04c46f.
This commit is contained in:
Pavel Kosov 2023-03-20 18:20:41 +03:00
parent dc521b9a10
commit fa326c2191
4 changed files with 9 additions and 49 deletions

View File

@ -258,7 +258,6 @@ class TypeSourceInfo;
FoundDeclsTy findDeclsInToCtx(DeclContext *DC, DeclarationName Name);
void AddToLookupTable(Decl *ToD);
llvm::Error ImportAttrs(Decl *ToD, Decl *FromD);
protected:
/// Can be overwritten by subclasses to implement their own import logic.

View File

@ -1165,10 +1165,6 @@ public:
///
/// \note This does NOT include a check for union-ness.
bool isEmpty() const { return data().Empty; }
/// Marks this record as empty. This is used by DWARFASTParserClang
/// when parsing records with empty fields having [[no_unique_address]]
/// attribute
void markEmpty() { data().Empty = true; }
void setInitMethod(bool Val) { data().HasInitMethod = Val; }
bool hasInitMethod() const { return data().HasInitMethod; }

View File

@ -3895,12 +3895,6 @@ ExpectedDecl ASTNodeImporter::VisitFieldDecl(FieldDecl *D) {
D->getInClassInitStyle()))
return ToField;
// We need [[no_unqiue_address]] attributes to be added to FieldDecl, before
// we add fields in CXXRecordDecl::addedMember, otherwise record will be
// marked as having non-zero size.
Err = Importer.ImportAttrs(ToField, D);
if (Err)
return std::move(Err);
ToField->setAccess(D->getAccess());
ToField->setLexicalDeclContext(LexicalDC);
if (ToInitializer)
@ -8987,19 +8981,6 @@ TranslationUnitDecl *ASTImporter::GetFromTU(Decl *ToD) {
return FromDPos->second->getTranslationUnitDecl();
}
Error ASTImporter::ImportAttrs(Decl *ToD, Decl *FromD) {
if (!FromD->hasAttrs() || ToD->hasAttrs())
return Error::success();
for (const Attr *FromAttr : FromD->getAttrs()) {
auto ToAttrOrErr = Import(FromAttr);
if (ToAttrOrErr)
ToD->addAttr(*ToAttrOrErr);
else
return ToAttrOrErr.takeError();
}
return Error::success();
}
Expected<Decl *> ASTImporter::Import(Decl *FromD) {
if (!FromD)
return nullptr;
@ -9134,8 +9115,15 @@ Expected<Decl *> ASTImporter::Import(Decl *FromD) {
// Make sure that ImportImpl registered the imported decl.
assert(ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?");
if (auto Error = ImportAttrs(ToD, FromD))
return std::move(Error);
if (FromD->hasAttrs())
for (const Attr *FromAttr : FromD->getAttrs()) {
auto ToAttrOrErr = Import(FromAttr);
if (ToAttrOrErr)
ToD->addAttr(*ToAttrOrErr);
else
return ToAttrOrErr.takeError();
}
// Notify subclasses.
Imported(FromD, ToD);

View File

@ -8478,29 +8478,6 @@ TEST_P(ASTImporterOptionSpecificTestBase, VaListCpp) {
ToVaList->getUnderlyingType(), ToBuiltinVaList->getUnderlyingType()));
}
TEST_P(ASTImporterOptionSpecificTestBase,
ImportDefinitionOfEmptyClassWithNoUniqueAddressField) {
Decl *FromTU = getTuDecl(
R"(
struct B {};
struct A { B b; };
)",
Lang_CXX20);
CXXRecordDecl *FromD = FirstDeclMatcher<CXXRecordDecl>().match(
FromTU, cxxRecordDecl(hasName("A")));
for (auto *FD : FromD->fields())
FD->addAttr(clang::NoUniqueAddressAttr::Create(FromD->getASTContext(),
clang::SourceRange()));
FromD->markEmpty();
CXXRecordDecl *ToD = cast<CXXRecordDecl>(Import(FromD, Lang_CXX20));
EXPECT_EQ(true, ToD->isEmpty());
for (auto *FD : ToD->fields())
EXPECT_EQ(true, FD->hasAttr<NoUniqueAddressAttr>());
}
INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest,
DefaultTestValuesForRunOptions);