Skip to content

Commit 159cc6b

Browse files
committed
Revert "Implement [[msvc::no_unique_address]] (llvm#65675)"
This reverts commit 4a55d42. Reverting because this breaks sphinx documentation, and even with it fixed the format of the attribute makes the no_unique_address documentation show up twice.
1 parent 9779a73 commit 159cc6b

File tree

9 files changed

+16
-489
lines changed

9 files changed

+16
-489
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,24 +1798,11 @@ def ArmMveStrictPolymorphism : TypeAttr, TargetSpecificAttr<TargetARM> {
17981798
let Documentation = [ArmMveStrictPolymorphismDocs];
17991799
}
18001800

1801-
def NoUniqueAddress : InheritableAttr {
1802-
let Subjects = SubjectList<[NonBitField], ErrorDiag>;
1803-
// No spellings because instances of this attribute are created by
1804-
// MSNoUniqueAddress and ItaniumNoUniqueAddress
1805-
let Spellings = [];
1806-
let Documentation = [NoUniqueAddressDocs];
1807-
}
1808-
1809-
def MSNoUniqueAddress : InheritableAttr, TargetSpecificAttr<TargetMicrosoftCXXABI> {
1810-
let Subjects = SubjectList<[NonBitField], ErrorDiag>;
1811-
let Spellings = [CXX11<"msvc", "no_unique_address", 201803>];
1812-
let Documentation = [NoUniqueAddressDocs];
1813-
}
1814-
1815-
def ItaniumNoUniqueAddress : InheritableAttr, TargetSpecificAttr<TargetItaniumCXXABI> {
1816-
let Subjects = SubjectList<[NonBitField], ErrorDiag>;
1801+
def NoUniqueAddress : InheritableAttr, TargetSpecificAttr<TargetItaniumCXXABI> {
18171802
let Spellings = [CXX11<"", "no_unique_address", 201803>];
1803+
let Subjects = SubjectList<[NonBitField], ErrorDiag>;
18181804
let Documentation = [NoUniqueAddressDocs];
1805+
let SimpleHandler = 1;
18191806
}
18201807

18211808
def ReturnsTwice : InheritableAttr {

clang/include/clang/Basic/AttrDocs.td

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,10 +1405,6 @@ Example usage:
14051405

14061406
``[[no_unique_address]]`` is a standard C++20 attribute. Clang supports its use
14071407
in C++11 onwards.
1408-
1409-
On MSVC targets, ``[[no_unique_address]]`` is ignored; use
1410-
``[[msvc::no_unique_address]]`` instead. Currently there is no guarantee of ABI
1411-
compatibility or stability.
14121408
}];
14131409
}
14141410

clang/lib/AST/Decl.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4507,14 +4507,9 @@ bool FieldDecl::isZeroSize(const ASTContext &Ctx) const {
45074507

45084508
// Otherwise, [...] the circumstances under which the object has zero size
45094509
// are implementation-defined.
4510-
if (!Ctx.getTargetInfo().getCXXABI().isMicrosoft())
4511-
return true;
4512-
4513-
// MS ABI: has nonzero size if it is a class type with class type fields,
4514-
// whether or not they have nonzero size
4515-
return !llvm::any_of(CXXRD->fields(), [](const FieldDecl *Field) {
4516-
return Field->getType()->getAs<RecordType>();
4517-
});
4510+
// FIXME: This might be Itanium ABI specific; we don't yet know what the MS
4511+
// ABI will do.
4512+
return true;
45184513
}
45194514

45204515
bool FieldDecl::isPotentiallyOverlapping() const {

clang/lib/AST/RecordLayoutBuilder.cpp

Lines changed: 8 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2545,10 +2545,7 @@ struct MicrosoftRecordLayoutBuilder {
25452545
CharUnits Alignment;
25462546
};
25472547
typedef llvm::DenseMap<const CXXRecordDecl *, CharUnits> BaseOffsetsMapTy;
2548-
MicrosoftRecordLayoutBuilder(const ASTContext &Context,
2549-
EmptySubobjectMap *EmptySubobjects)
2550-
: Context(Context), EmptySubobjects(EmptySubobjects) {}
2551-
2548+
MicrosoftRecordLayoutBuilder(const ASTContext &Context) : Context(Context) {}
25522549
private:
25532550
MicrosoftRecordLayoutBuilder(const MicrosoftRecordLayoutBuilder &) = delete;
25542551
void operator=(const MicrosoftRecordLayoutBuilder &) = delete;
@@ -2598,8 +2595,6 @@ struct MicrosoftRecordLayoutBuilder {
25982595
llvm::SmallPtrSetImpl<const CXXRecordDecl *> &HasVtorDispSet,
25992596
const CXXRecordDecl *RD) const;
26002597
const ASTContext &Context;
2601-
EmptySubobjectMap *EmptySubobjects;
2602-
26032598
/// The size of the record being laid out.
26042599
CharUnits Size;
26052600
/// The non-virtual size of the record layout.
@@ -2913,7 +2908,8 @@ static bool recordUsesEBO(const RecordDecl *RD) {
29132908
}
29142909

29152910
void MicrosoftRecordLayoutBuilder::layoutNonVirtualBase(
2916-
const CXXRecordDecl *RD, const CXXRecordDecl *BaseDecl,
2911+
const CXXRecordDecl *RD,
2912+
const CXXRecordDecl *BaseDecl,
29172913
const ASTRecordLayout &BaseLayout,
29182914
const ASTRecordLayout *&PreviousBaseLayout) {
29192915
// Insert padding between two bases if the left first one is zero sized or
@@ -2946,7 +2942,6 @@ void MicrosoftRecordLayoutBuilder::layoutNonVirtualBase(
29462942
}
29472943
Bases.insert(std::make_pair(BaseDecl, BaseOffset));
29482944
Size += BaseLayout.getNonVirtualSize();
2949-
DataSize = Size;
29502945
PreviousBaseLayout = &BaseLayout;
29512946
}
29522947

@@ -2964,43 +2959,15 @@ void MicrosoftRecordLayoutBuilder::layoutField(const FieldDecl *FD) {
29642959
LastFieldIsNonZeroWidthBitfield = false;
29652960
ElementInfo Info = getAdjustedElementInfo(FD);
29662961
Alignment = std::max(Alignment, Info.Alignment);
2967-
2968-
const CXXRecordDecl *FieldClass = FD->getType()->getAsCXXRecordDecl();
2969-
bool IsOverlappingEmptyField = FD->isPotentiallyOverlapping() &&
2970-
FieldClass->isEmpty() &&
2971-
FieldClass->fields().empty();
2972-
CharUnits FieldOffset = CharUnits::Zero();
2973-
2974-
if (UseExternalLayout) {
2962+
CharUnits FieldOffset;
2963+
if (UseExternalLayout)
29752964
FieldOffset =
29762965
Context.toCharUnitsFromBits(External.getExternalFieldOffset(FD));
2977-
} else if (IsUnion) {
2966+
else if (IsUnion)
29782967
FieldOffset = CharUnits::Zero();
2979-
} else if (EmptySubobjects) {
2980-
if (!IsOverlappingEmptyField)
2981-
FieldOffset = DataSize.alignTo(Info.Alignment);
2982-
2983-
while (!EmptySubobjects->CanPlaceFieldAtOffset(FD, FieldOffset)) {
2984-
const CXXRecordDecl *ParentClass = cast<CXXRecordDecl>(FD->getParent());
2985-
bool HasBases = ParentClass && (!ParentClass->bases().empty() ||
2986-
!ParentClass->vbases().empty());
2987-
if (FieldOffset == CharUnits::Zero() && DataSize != CharUnits::Zero() &&
2988-
HasBases) {
2989-
// MSVC appears to only do this when there are base classes;
2990-
// otherwise it overlaps no_unique_address fields in non-zero offsets.
2991-
FieldOffset = DataSize.alignTo(Info.Alignment);
2992-
} else {
2993-
FieldOffset += Info.Alignment;
2994-
}
2995-
}
2996-
} else {
2968+
else
29972969
FieldOffset = Size.alignTo(Info.Alignment);
2998-
}
29992970
placeFieldAtOffset(FieldOffset);
3000-
3001-
if (!IsOverlappingEmptyField)
3002-
DataSize = std::max(DataSize, FieldOffset + Info.Size);
3003-
30042971
Size = std::max(Size, FieldOffset + Info.Size);
30052972
}
30062973

@@ -3046,7 +3013,6 @@ void MicrosoftRecordLayoutBuilder::layoutBitField(const FieldDecl *FD) {
30463013
Alignment = std::max(Alignment, Info.Alignment);
30473014
RemainingBitsInField = Context.toBits(Info.Size) - Width;
30483015
}
3049-
DataSize = Size;
30503016
}
30513017

30523018
void
@@ -3072,7 +3038,6 @@ MicrosoftRecordLayoutBuilder::layoutZeroWidthBitField(const FieldDecl *FD) {
30723038
Size = FieldOffset;
30733039
Alignment = std::max(Alignment, Info.Alignment);
30743040
}
3075-
DataSize = Size;
30763041
}
30773042

30783043
void MicrosoftRecordLayoutBuilder::injectVBPtr(const CXXRecordDecl *RD) {
@@ -3339,9 +3304,8 @@ ASTContext::getASTRecordLayout(const RecordDecl *D) const {
33393304
const ASTRecordLayout *NewEntry = nullptr;
33403305

33413306
if (isMsLayout(*this)) {
3307+
MicrosoftRecordLayoutBuilder Builder(*this);
33423308
if (const auto *RD = dyn_cast<CXXRecordDecl>(D)) {
3343-
EmptySubobjectMap EmptySubobjects(*this, RD);
3344-
MicrosoftRecordLayoutBuilder Builder(*this, &EmptySubobjects);
33453309
Builder.cxxLayout(RD);
33463310
NewEntry = new (*this) ASTRecordLayout(
33473311
*this, Builder.Size, Builder.Alignment, Builder.Alignment,
@@ -3353,7 +3317,6 @@ ASTContext::getASTRecordLayout(const RecordDecl *D) const {
33533317
Builder.EndsWithZeroSizedObject, Builder.LeadsWithZeroSizedBase,
33543318
Builder.Bases, Builder.VBases);
33553319
} else {
3356-
MicrosoftRecordLayoutBuilder Builder(*this, /*EmptySubobjects=*/nullptr);
33573320
Builder.layout(D);
33583321
NewEntry = new (*this) ASTRecordLayout(
33593322
*this, Builder.Size, Builder.Alignment, Builder.Alignment,

clang/lib/Parse/ParseDeclCXX.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4374,8 +4374,7 @@ static bool IsBuiltInOrStandardCXX11Attribute(IdentifierInfo *AttrName,
43744374
case ParsedAttr::AT_Deprecated:
43754375
case ParsedAttr::AT_FallThrough:
43764376
case ParsedAttr::AT_CXX11NoReturn:
4377-
case ParsedAttr::AT_MSNoUniqueAddress:
4378-
case ParsedAttr::AT_ItaniumNoUniqueAddress:
4377+
case ParsedAttr::AT_NoUniqueAddress:
43794378
case ParsedAttr::AT_Likely:
43804379
case ParsedAttr::AT_Unlikely:
43814380
return true;

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8372,10 +8372,6 @@ static void handleNoMergeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
83728372
D->addAttr(NoMergeAttr::Create(S.Context, AL));
83738373
}
83748374

8375-
static void handleNoUniqueAddressAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
8376-
D->addAttr(NoUniqueAddressAttr::Create(S.Context, AL));
8377-
}
8378-
83798375
static void handleSYCLKernelAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
83808376
// The 'sycl_kernel' attribute applies only to function templates.
83818377
const auto *FD = cast<FunctionDecl>(D);
@@ -9281,12 +9277,6 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const ParsedAttr &AL,
92819277
case ParsedAttr::AT_NoMerge:
92829278
handleNoMergeAttr(S, D, AL);
92839279
break;
9284-
case ParsedAttr::AT_MSNoUniqueAddress:
9285-
handleNoUniqueAddressAttr(S, D, AL);
9286-
break;
9287-
case ParsedAttr::AT_ItaniumNoUniqueAddress:
9288-
handleNoUniqueAddressAttr(S, D, AL);
9289-
break;
92909280

92919281
case ParsedAttr::AT_AvailableOnlyInDefaultEvalMethod:
92929282
handleAvailableOnlyInDefaultEvalMethod(S, D, AL);

0 commit comments

Comments
 (0)