@@ -20008,16 +20008,16 @@ bool Sema::IsValueInFlagEnum(const EnumDecl *ED, const llvm::APInt &Val,
2000820008 return !(FlagMask & Val) || (AllowMask && !(FlagMask & ~Val));
2000920009}
2001020010
20011- bool Sema::ComputeBestEnumProperties(ASTContext &Context, EnumDecl *Enum,
20012- bool is_cpp, bool isPacked,
20011+ bool Sema::ComputeBestEnumProperties(ASTContext &Context, bool isPacked,
2001320012 unsigned NumNegativeBits,
2001420013 unsigned NumPositiveBits,
20015- unsigned &BestWidth, QualType &BestType,
20014+ QualType &BestType,
2001620015 QualType &BestPromotionType) {
2001720016 unsigned IntWidth = Context.getTargetInfo().getIntWidth();
2001820017 unsigned CharWidth = Context.getTargetInfo().getCharWidth();
2001920018 unsigned ShortWidth = Context.getTargetInfo().getShortWidth();
20020- bool enum_too_large = false;
20019+ bool EnumTooLarge = false;
20020+ unsigned BestWidth;
2002120021 if (NumNegativeBits) {
2002220022 // If there is a negative value, figure out the smallest integer type (of
2002320023 // int/long/longlong) that fits.
@@ -20042,7 +20042,7 @@ bool Sema::ComputeBestEnumProperties(ASTContext &Context, EnumDecl *Enum,
2004220042 BestWidth = Context.getTargetInfo().getLongLongWidth();
2004320043
2004420044 if (NumNegativeBits > BestWidth || NumPositiveBits >= BestWidth)
20045- enum_too_large = true;
20045+ EnumTooLarge = true;
2004620046 BestType = Context.LongLongTy;
2004720047 }
2004820048 }
@@ -20062,31 +20062,34 @@ bool Sema::ComputeBestEnumProperties(ASTContext &Context, EnumDecl *Enum,
2006220062 } else if (NumPositiveBits <= IntWidth) {
2006320063 BestType = Context.UnsignedIntTy;
2006420064 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;
2006820069 } else if (NumPositiveBits <=
2006920070 (BestWidth = Context.getTargetInfo().getLongWidth())) {
2007020071 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;
2007420076 } else {
2007520077 BestWidth = Context.getTargetInfo().getLongLongWidth();
2007620078 if (NumPositiveBits > BestWidth) {
2007720079 // This can happen with bit-precise integer types, but those are not
2007820080 // allowed as the type for an enumerator per C23 6.7.2.2p4 and p12.
2007920081 // FIXME: GCC uses __int128_t and __uint128_t for cases that fit within
2008020082 // a 128-bit integer, we should consider doing the same.
20081- enum_too_large = true;
20083+ EnumTooLarge = true;
2008220084 }
2008320085 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;
2008720090 }
2008820091 }
20089- return enum_too_large ;
20092+ return EnumTooLarge ;
2009020093}
2009120094
2009220095void Sema::ActOnEnumBody(SourceLocation EnumLoc, SourceRange BraceRange,
@@ -20177,10 +20180,11 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, SourceRange BraceRange,
2017720180
2017820181 BestWidth = Context.getIntWidth(BestType);
2017920182 } 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)
2018420188 Diag(Enum->getLocation(), diag::ext_enum_too_large);
2018520189 }
2018620190
0 commit comments