@@ -20008,16 +20008,16 @@ bool Sema::IsValueInFlagEnum(const EnumDecl *ED, const llvm::APInt &Val,
20008
20008
return !(FlagMask & Val) || (AllowMask && !(FlagMask & ~Val));
20009
20009
}
20010
20010
20011
- bool Sema::ComputeBestEnumProperties(ASTContext &Context, EnumDecl *Enum,
20012
- bool is_cpp, bool isPacked,
20011
+ bool Sema::ComputeBestEnumProperties(ASTContext &Context, bool isPacked,
20013
20012
unsigned NumNegativeBits,
20014
20013
unsigned NumPositiveBits,
20015
- unsigned &BestWidth, QualType &BestType,
20014
+ QualType &BestType,
20016
20015
QualType &BestPromotionType) {
20017
20016
unsigned IntWidth = Context.getTargetInfo().getIntWidth();
20018
20017
unsigned CharWidth = Context.getTargetInfo().getCharWidth();
20019
20018
unsigned ShortWidth = Context.getTargetInfo().getShortWidth();
20020
- bool enum_too_large = false;
20019
+ bool EnumTooLarge = false;
20020
+ unsigned BestWidth;
20021
20021
if (NumNegativeBits) {
20022
20022
// If there is a negative value, figure out the smallest integer type (of
20023
20023
// int/long/longlong) that fits.
@@ -20042,7 +20042,7 @@ bool Sema::ComputeBestEnumProperties(ASTContext &Context, EnumDecl *Enum,
20042
20042
BestWidth = Context.getTargetInfo().getLongLongWidth();
20043
20043
20044
20044
if (NumNegativeBits > BestWidth || NumPositiveBits >= BestWidth)
20045
- enum_too_large = true;
20045
+ EnumTooLarge = true;
20046
20046
BestType = Context.LongLongTy;
20047
20047
}
20048
20048
}
@@ -20062,31 +20062,34 @@ bool Sema::ComputeBestEnumProperties(ASTContext &Context, EnumDecl *Enum,
20062
20062
} else if (NumPositiveBits <= IntWidth) {
20063
20063
BestType = Context.UnsignedIntTy;
20064
20064
BestWidth = IntWidth;
20065
- BestPromotionType = (NumPositiveBits == BestWidth || !is_cpp)
20066
- ? Context.UnsignedIntTy
20067
- : Context.IntTy;
20065
+ BestPromotionType =
20066
+ (NumPositiveBits == BestWidth || !Context.getLangOpts().CPlusPlus)
20067
+ ? Context.UnsignedIntTy
20068
+ : Context.IntTy;
20068
20069
} else if (NumPositiveBits <=
20069
20070
(BestWidth = Context.getTargetInfo().getLongWidth())) {
20070
20071
BestType = Context.UnsignedLongTy;
20071
- BestPromotionType = (NumPositiveBits == BestWidth || !is_cpp)
20072
- ? Context.UnsignedLongTy
20073
- : Context.LongTy;
20072
+ BestPromotionType =
20073
+ (NumPositiveBits == BestWidth || !Context.getLangOpts().CPlusPlus)
20074
+ ? Context.UnsignedLongTy
20075
+ : Context.LongTy;
20074
20076
} else {
20075
20077
BestWidth = Context.getTargetInfo().getLongLongWidth();
20076
20078
if (NumPositiveBits > BestWidth) {
20077
20079
// This can happen with bit-precise integer types, but those are not
20078
20080
// allowed as the type for an enumerator per C23 6.7.2.2p4 and p12.
20079
20081
// FIXME: GCC uses __int128_t and __uint128_t for cases that fit within
20080
20082
// a 128-bit integer, we should consider doing the same.
20081
- enum_too_large = true;
20083
+ EnumTooLarge = true;
20082
20084
}
20083
20085
BestType = Context.UnsignedLongLongTy;
20084
- BestPromotionType = (NumPositiveBits == BestWidth || !is_cpp)
20085
- ? Context.UnsignedLongLongTy
20086
- : Context.LongLongTy;
20086
+ BestPromotionType =
20087
+ (NumPositiveBits == BestWidth || !Context.getLangOpts().CPlusPlus)
20088
+ ? Context.UnsignedLongLongTy
20089
+ : Context.LongLongTy;
20087
20090
}
20088
20091
}
20089
- return enum_too_large ;
20092
+ return EnumTooLarge ;
20090
20093
}
20091
20094
20092
20095
void Sema::ActOnEnumBody(SourceLocation EnumLoc, SourceRange BraceRange,
@@ -20177,10 +20180,11 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, SourceRange BraceRange,
20177
20180
20178
20181
BestWidth = Context.getIntWidth(BestType);
20179
20182
} else {
20180
- bool enum_too_large = ComputeBestEnumProperties(
20181
- Context, Enum, getLangOpts().CPlusPlus, Packed, NumNegativeBits,
20182
- NumPositiveBits, BestWidth, BestType, BestPromotionType);
20183
- if (enum_too_large)
20183
+ bool EnumTooLarge =
20184
+ ComputeBestEnumProperties(Context, Packed, NumNegativeBits,
20185
+ NumPositiveBits, BestType, BestPromotionType);
20186
+ BestWidth = Context.getIntWidth(BestType);
20187
+ if (EnumTooLarge)
20184
20188
Diag(Enum->getLocation(), diag::ext_enum_too_large);
20185
20189
}
20186
20190
0 commit comments