Skip to content

Commit cc2452c

Browse files
committed
Sigh, let's appease MSVC's refusal to acknowledge designated initializers
1 parent 48637e2 commit cc2452c

File tree

5 files changed

+138
-102
lines changed

5 files changed

+138
-102
lines changed

clang/include/clang/AST/ExprCXX.h

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2234,15 +2234,42 @@ enum class CXXNewInitializationStyle {
22342234
Braces
22352235
};
22362236

2237+
enum class TypeAwareAllocation { Yes, No };
2238+
2239+
inline TypeAwareAllocation typeAwareAllocation(bool IsTypeAware) {
2240+
return IsTypeAware ? TypeAwareAllocation::Yes : TypeAwareAllocation::No;
2241+
}
2242+
2243+
enum class AlignedAllocation { Yes, No };
2244+
2245+
inline AlignedAllocation alignedAllocation(bool IsAligned) {
2246+
return IsAligned ? AlignedAllocation::Yes : AlignedAllocation::No;
2247+
}
2248+
2249+
enum class SizedDeallocation { Yes, No };
2250+
2251+
inline SizedDeallocation sizedDeallocation(bool IsSized) {
2252+
return IsSized ? SizedDeallocation::Yes : SizedDeallocation::No;
2253+
}
2254+
22372255
struct ImplicitAllocationParameters {
2238-
bool PassTypeIdentity;
2239-
bool PassAlignment;
2256+
TypeAwareAllocation PassTypeIdentity;
2257+
AlignedAllocation PassAlignment;
2258+
bool passTypeIdentity() const {
2259+
return PassTypeIdentity == TypeAwareAllocation::Yes;
2260+
}
2261+
bool passAlignment() const { return PassAlignment == AlignedAllocation::Yes; }
22402262
};
22412263

22422264
struct ImplicitDeallocationParameters {
2243-
bool PassTypeIdentity;
2244-
bool PassAlignment;
2245-
bool PassSize;
2265+
TypeAwareAllocation PassTypeIdentity;
2266+
AlignedAllocation PassAlignment;
2267+
SizedDeallocation PassSize;
2268+
bool passTypeIdentity() const {
2269+
return PassTypeIdentity == TypeAwareAllocation::Yes;
2270+
}
2271+
bool passAlignment() const { return PassAlignment == AlignedAllocation::Yes; }
2272+
bool passSize() const { return PassSize == SizedDeallocation::Yes; }
22462273
};
22472274

22482275
/// Represents a new-expression for memory allocation and constructor
@@ -2465,8 +2492,8 @@ class CXXNewExpr final
24652492
/// Provides the full set of information about expected implicit
24662493
/// parameters in this call
24672494
ImplicitAllocationParameters implicitAllocationParameters() const {
2468-
return ImplicitAllocationParameters{.PassTypeIdentity = passTypeIdentity(),
2469-
.PassAlignment = passAlignment()};
2495+
return ImplicitAllocationParameters{typeAwareAllocation(passTypeIdentity()),
2496+
alignedAllocation(passAlignment())};
24702497
}
24712498

24722499
using arg_iterator = ExprIterator;

clang/lib/AST/ExprCXX.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,8 @@ CXXNewExpr::CXXNewExpr(bool IsGlobalNew, FunctionDecl *OperatorNew,
247247

248248
CXXNewExprBits.IsGlobalNew = IsGlobalNew;
249249
CXXNewExprBits.IsArray = ArraySize.has_value();
250-
CXXNewExprBits.ShouldPassAlignment = IAP.PassAlignment;
251-
CXXNewExprBits.ShouldPassTypeIdentity = IAP.PassTypeIdentity;
250+
CXXNewExprBits.ShouldPassAlignment = IAP.passAlignment();
251+
CXXNewExprBits.ShouldPassTypeIdentity = IAP.passTypeIdentity();
252252
CXXNewExprBits.UsualArrayDeleteWantsSize = UsualArrayDeleteWantsSize;
253253
CXXNewExprBits.HasInitializer = Initializer != nullptr;
254254
CXXNewExprBits.StoredInitializationStyle =

clang/lib/Sema/SemaCoroutine.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,10 +1112,9 @@ static bool findDeleteForPromise(Sema &S, SourceLocation Loc, QualType PromiseTy
11121112
// The deallocation function's name is looked up by searching for it in the
11131113
// scope of the promise type. If nothing is found, a search is performed in
11141114
// the global scope.
1115-
ImplicitDeallocationParameters IDP = {.PassTypeIdentity =
1116-
S.AllowTypeAwareAllocators(),
1117-
.PassAlignment = Overaligned,
1118-
.PassSize = true};
1115+
ImplicitDeallocationParameters IDP = {
1116+
typeAwareAllocation(S.AllowTypeAwareAllocators()),
1117+
alignedAllocation(Overaligned), SizedDeallocation::Yes};
11191118
if (S.FindDeallocationFunction(Loc, PointeeRD, DeleteName, OperatorDelete,
11201119
PromiseType, IDP, /*Diagnose*/ true))
11211120
return false;
@@ -1133,7 +1132,8 @@ static bool findDeleteForPromise(Sema &S, SourceLocation Loc, QualType PromiseTy
11331132
// Sema::FindUsualDeallocationFunction will try to find the one with two
11341133
// parameters first. It will return the deallocation function with one
11351134
// parameter if failed.
1136-
IDP.PassSize = CanProvideSize;
1135+
IDP.PassSize =
1136+
CanProvideSize ? SizedDeallocation::Yes : SizedDeallocation::No;
11371137
OperatorDelete =
11381138
S.FindUsualDeallocationFunction(PromiseType, Loc, IDP, DeleteName);
11391139

@@ -1426,8 +1426,8 @@ bool CoroutineStmtBuilder::makeNewAndDeleteExpr() {
14261426
// Helper function to indicate whether the last lookup found the aligned
14271427
// allocation function.
14281428
ImplicitAllocationParameters IAP = {
1429-
.PassTypeIdentity = S.AllowTypeAwareAllocators(),
1430-
.PassAlignment = S.getLangOpts().CoroAlignedAllocation != 0};
1429+
typeAwareAllocation(S.AllowTypeAwareAllocators()),
1430+
alignedAllocation(S.getLangOpts().CoroAlignedAllocation)};
14311431
auto LookupAllocationFunction =
14321432
[&](Sema::AllocationFunctionScope NewScope = Sema::AFS_Both,
14331433
bool WithoutPlacementArgs = false, bool ForceNonAligned = false) {
@@ -1442,9 +1442,9 @@ bool CoroutineStmtBuilder::makeNewAndDeleteExpr() {
14421442
if (NewScope == Sema::AFS_Both)
14431443
NewScope = PromiseContainsNew ? Sema::AFS_Class : Sema::AFS_Global;
14441444

1445-
IAP = {.PassTypeIdentity = S.AllowTypeAwareAllocators(),
1446-
.PassAlignment =
1447-
!ForceNonAligned && S.getLangOpts().CoroAlignedAllocation};
1445+
IAP = {typeAwareAllocation(S.AllowTypeAwareAllocators()),
1446+
alignedAllocation(!ForceNonAligned &&
1447+
S.getLangOpts().CoroAlignedAllocation)};
14481448

14491449
FunctionDecl *UnusedResult = nullptr;
14501450

@@ -1478,7 +1478,7 @@ bool CoroutineStmtBuilder::makeNewAndDeleteExpr() {
14781478
// std::size_t as the first argument, and the requested alignment as
14791479
// an argument of type std:align_val_t as the second argument.
14801480
if (!OperatorNew ||
1481-
(S.getLangOpts().CoroAlignedAllocation && !IAP.PassAlignment))
1481+
(S.getLangOpts().CoroAlignedAllocation && !IAP.passAlignment()))
14821482
LookupAllocationFunction(/*NewScope*/ Sema::AFS_Class,
14831483
/*WithoutPlacementArgs*/ true);
14841484
}
@@ -1503,7 +1503,7 @@ bool CoroutineStmtBuilder::makeNewAndDeleteExpr() {
15031503
// Helper variable to emit warnings.
15041504
bool FoundNonAlignedInPromise = false;
15051505
if (PromiseContainsNew && S.getLangOpts().CoroAlignedAllocation)
1506-
if (!OperatorNew || !IAP.PassAlignment) {
1506+
if (!OperatorNew || !IAP.passAlignment()) {
15071507
FoundNonAlignedInPromise = OperatorNew;
15081508

15091509
LookupAllocationFunction(/*NewScope*/ Sema::AFS_Class,
@@ -1598,7 +1598,7 @@ bool CoroutineStmtBuilder::makeNewAndDeleteExpr() {
15981598
return false;
15991599

16001600
SmallVector<Expr *, 3> NewArgs;
1601-
if (IAP.PassTypeIdentity) {
1601+
if (IAP.passTypeIdentity()) {
16021602
std::optional<QualType> SpecializedTypeIdentity =
16031603
S.instantiateSpecializedTypeIdentity(PromiseType);
16041604
if (!SpecializedTypeIdentity)
@@ -1612,7 +1612,7 @@ bool CoroutineStmtBuilder::makeNewAndDeleteExpr() {
16121612
NewArgs.push_back(TypeIdentity.get());
16131613
}
16141614
NewArgs.push_back(FrameSize);
1615-
if (S.getLangOpts().CoroAlignedAllocation && IAP.PassAlignment)
1615+
if (S.getLangOpts().CoroAlignedAllocation && IAP.passAlignment())
16161616
NewArgs.push_back(FrameAlignment);
16171617

16181618
if (OperatorNew->getNumParams() > NewArgs.size())

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9714,10 +9714,9 @@ bool Sema::ShouldDeleteSpecialMember(CXXMethodDecl *MD,
97149714
QualType DeallocType = Context.getRecordType(RD);
97159715
DeclarationName Name =
97169716
Context.DeclarationNames.getCXXOperatorName(OO_Delete);
9717-
ImplicitDeallocationParameters IDP = {.PassTypeIdentity =
9718-
AllowTypeAwareAllocators(),
9719-
.PassAlignment = false,
9720-
.PassSize = false};
9717+
ImplicitDeallocationParameters IDP = {
9718+
typeAwareAllocation(AllowTypeAwareAllocators()), AlignedAllocation::No,
9719+
SizedDeallocation::No};
97219720
if (FindDeallocationFunction(MD->getLocation(), MD->getParent(), Name,
97229721
OperatorDelete, DeallocType, IDP,
97239722
/*Diagnose*/ false)) {

0 commit comments

Comments
 (0)