@@ -20036,87 +20036,6 @@ bool Sema::IsValueInFlagEnum(const EnumDecl *ED, const llvm::APInt &Val,
2003620036 return !(FlagMask & Val) || (AllowMask && !(FlagMask & ~Val));
2003720037}
2003820038
20039- bool Sema::ComputeBestEnumProperties(ASTContext &Context, EnumDecl *Enum,
20040- bool is_cpp, bool isPacked,
20041- unsigned NumNegativeBits,
20042- unsigned NumPositiveBits,
20043- unsigned &BestWidth, QualType &BestType,
20044- QualType &BestPromotionType) {
20045- unsigned IntWidth = Context.getTargetInfo().getIntWidth();
20046- unsigned CharWidth = Context.getTargetInfo().getCharWidth();
20047- unsigned ShortWidth = Context.getTargetInfo().getShortWidth();
20048- bool enum_too_large = false;
20049- if (NumNegativeBits) {
20050- // If there is a negative value, figure out the smallest integer type (of
20051- // int/long/longlong) that fits.
20052- // If it's packed, check also if it fits a char or a short.
20053- if (isPacked && NumNegativeBits <= CharWidth &&
20054- NumPositiveBits < CharWidth) {
20055- BestType = Context.SignedCharTy;
20056- BestWidth = CharWidth;
20057- } else if (isPacked && NumNegativeBits <= ShortWidth &&
20058- NumPositiveBits < ShortWidth) {
20059- BestType = Context.ShortTy;
20060- BestWidth = ShortWidth;
20061- } else if (NumNegativeBits <= IntWidth && NumPositiveBits < IntWidth) {
20062- BestType = Context.IntTy;
20063- BestWidth = IntWidth;
20064- } else {
20065- BestWidth = Context.getTargetInfo().getLongWidth();
20066-
20067- if (NumNegativeBits <= BestWidth && NumPositiveBits < BestWidth) {
20068- BestType = Context.LongTy;
20069- } else {
20070- BestWidth = Context.getTargetInfo().getLongLongWidth();
20071-
20072- if (NumNegativeBits > BestWidth || NumPositiveBits >= BestWidth)
20073- enum_too_large = true;
20074- BestType = Context.LongLongTy;
20075- }
20076- }
20077- BestPromotionType = (BestWidth <= IntWidth ? Context.IntTy : BestType);
20078- } else {
20079- // If there is no negative value, figure out the smallest type that fits
20080- // all of the enumerator values.
20081- // If it's packed, check also if it fits a char or a short.
20082- if (isPacked && NumPositiveBits <= CharWidth) {
20083- BestType = Context.UnsignedCharTy;
20084- BestPromotionType = Context.IntTy;
20085- BestWidth = CharWidth;
20086- } else if (isPacked && NumPositiveBits <= ShortWidth) {
20087- BestType = Context.UnsignedShortTy;
20088- BestPromotionType = Context.IntTy;
20089- BestWidth = ShortWidth;
20090- } else if (NumPositiveBits <= IntWidth) {
20091- BestType = Context.UnsignedIntTy;
20092- BestWidth = IntWidth;
20093- BestPromotionType = (NumPositiveBits == BestWidth || !is_cpp)
20094- ? Context.UnsignedIntTy
20095- : Context.IntTy;
20096- } else if (NumPositiveBits <=
20097- (BestWidth = Context.getTargetInfo().getLongWidth())) {
20098- BestType = Context.UnsignedLongTy;
20099- BestPromotionType = (NumPositiveBits == BestWidth || !is_cpp)
20100- ? Context.UnsignedLongTy
20101- : Context.LongTy;
20102- } else {
20103- BestWidth = Context.getTargetInfo().getLongLongWidth();
20104- if (NumPositiveBits > BestWidth) {
20105- // This can happen with bit-precise integer types, but those are not
20106- // allowed as the type for an enumerator per C23 6.7.2.2p4 and p12.
20107- // FIXME: GCC uses __int128_t and __uint128_t for cases that fit within
20108- // a 128-bit integer, we should consider doing the same.
20109- enum_too_large = true;
20110- }
20111- BestType = Context.UnsignedLongLongTy;
20112- BestPromotionType = (NumPositiveBits == BestWidth || !is_cpp)
20113- ? Context.UnsignedLongLongTy
20114- : Context.LongLongTy;
20115- }
20116- }
20117- return enum_too_large;
20118- }
20119-
2012020039void Sema::ActOnEnumBody(SourceLocation EnumLoc, SourceRange BraceRange,
2012120040 Decl *EnumDeclX, ArrayRef<Decl *> Elements, Scope *S,
2012220041 const ParsedAttributesView &Attrs) {
0 commit comments