Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion clang/include/clang/AST/ASTImporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 0 additions & 4 deletions clang/include/clang/AST/DeclCXX.h
Original file line number Diff line number Diff line change
Expand Up @@ -1188,10 +1188,6 @@ class CXXRecordDecl : public RecordDecl {
///
/// \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; }
Expand Down
30 changes: 9 additions & 21 deletions clang/lib/AST/ASTImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4179,12 +4179,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);
ToField->setImplicit(D->isImplicit());
Expand Down Expand Up @@ -9399,19 +9393,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;
Expand Down Expand Up @@ -9545,8 +9526,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);
Expand Down
23 changes: 0 additions & 23 deletions clang/unittests/AST/ASTImporterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9376,29 +9376,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 = Import(FromD, Lang_CXX20);
EXPECT_TRUE(ToD->isEmpty());
for (auto *FD : ToD->fields())
EXPECT_EQ(true, FD->hasAttr<NoUniqueAddressAttr>());
}

TEST_P(ASTImporterOptionSpecificTestBase, ImportExistingTypedefToRecord) {
const char *Code =
R"(
Expand Down
Loading