Index: clang/include/clang/AST/TypeLoc.h =================================================================== --- clang/include/clang/AST/TypeLoc.h +++ clang/include/clang/AST/TypeLoc.h @@ -619,16 +619,16 @@ if (needsExtraLocalData()) return static_cast(getWrittenBuiltinSpecs().Width); else - return TSW_unspecified; + return TypeSpecifierWidth::Unspecified; } bool hasWrittenWidthSpec() const { - return getWrittenWidthSpec() != TSW_unspecified; + return getWrittenWidthSpec() != TypeSpecifierWidth::Unspecified; } void setWrittenWidthSpec(TypeSpecifierWidth written) { if (needsExtraLocalData()) - getWrittenBuiltinSpecs().Width = written; + getWrittenBuiltinSpecs().Width = static_cast(written); } TypeSpecifierType getWrittenTypeSpec() const; @@ -659,7 +659,7 @@ if (needsExtraLocalData()) { WrittenBuiltinSpecs &wbs = getWrittenBuiltinSpecs(); wbs.Sign = TSS_unspecified; - wbs.Width = TSW_unspecified; + wbs.Width = static_cast(TypeSpecifierWidth::Unspecified); wbs.Type = TST_unspecified; wbs.ModeAttr = false; } Index: clang/include/clang/Basic/Specifiers.h =================================================================== --- clang/include/clang/Basic/Specifiers.h +++ clang/include/clang/Basic/Specifiers.h @@ -37,11 +37,11 @@ }; /// Specifies the width of a type, e.g., short, long, or long long. - enum TypeSpecifierWidth { - TSW_unspecified, - TSW_short, - TSW_long, - TSW_longlong + enum class TypeSpecifierWidth : unsigned char { + Unspecified, + Short, + Long, + LongLong }; /// Specifies the signedness of a type, e.g., signed or unsigned. @@ -106,7 +106,7 @@ static_assert(TST_error < 1 << 6, "Type bitfield not wide enough for TST"); /*DeclSpec::TST*/ unsigned Type : 6; /*DeclSpec::TSS*/ unsigned Sign : 2; - /*DeclSpec::TSW*/ unsigned Width : 2; + unsigned Width : 2; unsigned ModeAttr : 1; }; Index: clang/include/clang/Sema/DeclSpec.h =================================================================== --- clang/include/clang/Sema/DeclSpec.h +++ clang/include/clang/Sema/DeclSpec.h @@ -249,13 +249,6 @@ static const TSCS TSCS_thread_local = clang::TSCS_thread_local; static const TSCS TSCS__Thread_local = clang::TSCS__Thread_local; - // Import type specifier width enumeration and constants. - typedef TypeSpecifierWidth TSW; - static const TSW TSW_unspecified = clang::TSW_unspecified; - static const TSW TSW_short = clang::TSW_short; - static const TSW TSW_long = clang::TSW_long; - static const TSW TSW_longlong = clang::TSW_longlong; - enum TSC { TSC_unspecified, TSC_imaginary, @@ -342,7 +335,7 @@ unsigned SCS_extern_in_linkage_spec : 1; // type-specifier - /*TSW*/unsigned TypeSpecWidth : 2; + unsigned TypeSpecWidth : 2; /*TSC*/unsigned TypeSpecComplex : 2; /*TSS*/unsigned TypeSpecSign : 2; /*TST*/unsigned TypeSpecType : 6; @@ -434,17 +427,17 @@ DeclSpec(AttributeFactory &attrFactory) : StorageClassSpec(SCS_unspecified), ThreadStorageClassSpec(TSCS_unspecified), - SCS_extern_in_linkage_spec(false), TypeSpecWidth(TSW_unspecified), + SCS_extern_in_linkage_spec(false), + TypeSpecWidth(static_cast(TypeSpecifierWidth::Unspecified)), TypeSpecComplex(TSC_unspecified), TypeSpecSign(TSS_unspecified), TypeSpecType(TST_unspecified), TypeAltiVecVector(false), TypeAltiVecPixel(false), TypeAltiVecBool(false), TypeSpecOwned(false), TypeSpecPipe(false), TypeSpecSat(false), ConstrainedAuto(false), - TypeQualifiers(TQ_unspecified), - FS_inline_specified(false), FS_forceinline_specified(false), - FS_virtual_specified(false), FS_noreturn_specified(false), - Friend_specified(false), ConstexprSpecifier(CSK_unspecified), - FS_explicit_specifier(), Attrs(attrFactory), writtenBS(), - ObjCQualifiers(nullptr) {} + TypeQualifiers(TQ_unspecified), FS_inline_specified(false), + FS_forceinline_specified(false), FS_virtual_specified(false), + FS_noreturn_specified(false), Friend_specified(false), + ConstexprSpecifier(CSK_unspecified), FS_explicit_specifier(), + Attrs(attrFactory), writtenBS(), ObjCQualifiers(nullptr) {} // storage-class-specifier SCS getStorageClassSpec() const { return (SCS)StorageClassSpec; } @@ -476,7 +469,9 @@ } // type-specifier - TSW getTypeSpecWidth() const { return (TSW)TypeSpecWidth; } + TypeSpecifierWidth getTypeSpecWidth() const { + return static_cast(TypeSpecWidth); + } TSC getTypeSpecComplex() const { return (TSC)TypeSpecComplex; } TSS getTypeSpecSign() const { return (TSS)TypeSpecSign; } TST getTypeSpecType() const { return (TST)TypeSpecType; } @@ -542,7 +537,7 @@ static const char *getSpecifierName(DeclSpec::TQ Q); static const char *getSpecifierName(DeclSpec::TSS S); static const char *getSpecifierName(DeclSpec::TSC C); - static const char *getSpecifierName(DeclSpec::TSW W); + static const char *getSpecifierName(TypeSpecifierWidth W); static const char *getSpecifierName(DeclSpec::SCS S); static const char *getSpecifierName(DeclSpec::TSCS S); static const char *getSpecifierName(ConstexprSpecKind C); @@ -626,7 +621,7 @@ /// Return true if any type-specifier has been found. bool hasTypeSpecifier() const { return getTypeSpecType() != DeclSpec::TST_unspecified || - getTypeSpecWidth() != DeclSpec::TSW_unspecified || + getTypeSpecWidth() != TypeSpecifierWidth::Unspecified || getTypeSpecComplex() != DeclSpec::TSC_unspecified || getTypeSpecSign() != DeclSpec::TSS_unspecified; } @@ -659,8 +654,9 @@ const PrintingPolicy &Policy); bool SetStorageClassSpecThread(TSCS TSC, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID); - bool SetTypeSpecWidth(TSW W, SourceLocation Loc, const char *&PrevSpec, - unsigned &DiagID, const PrintingPolicy &Policy); + bool SetTypeSpecWidth(TypeSpecifierWidth W, SourceLocation Loc, + const char *&PrevSpec, unsigned &DiagID, + const PrintingPolicy &Policy); bool SetTypeSpecComplex(TSC C, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID); bool SetTypeSpecSign(TSS S, SourceLocation Loc, const char *&PrevSpec, Index: clang/lib/Parse/ParseDecl.cpp =================================================================== --- clang/lib/Parse/ParseDecl.cpp +++ clang/lib/Parse/ParseDecl.cpp @@ -3689,20 +3689,20 @@ // type-specifier case tok::kw_short: - isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_short, Loc, PrevSpec, + isInvalid = DS.SetTypeSpecWidth(TypeSpecifierWidth::Short, Loc, PrevSpec, DiagID, Policy); break; case tok::kw_long: - if (DS.getTypeSpecWidth() != DeclSpec::TSW_long) - isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_long, Loc, PrevSpec, + if (DS.getTypeSpecWidth() != TypeSpecifierWidth::Long) + isInvalid = DS.SetTypeSpecWidth(TypeSpecifierWidth::Long, Loc, PrevSpec, DiagID, Policy); else - isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_longlong, Loc, PrevSpec, - DiagID, Policy); + isInvalid = DS.SetTypeSpecWidth(TypeSpecifierWidth::LongLong, Loc, + PrevSpec, DiagID, Policy); break; case tok::kw___int64: - isInvalid = DS.SetTypeSpecWidth(DeclSpec::TSW_longlong, Loc, PrevSpec, - DiagID, Policy); + isInvalid = DS.SetTypeSpecWidth(TypeSpecifierWidth::LongLong, Loc, + PrevSpec, DiagID, Policy); break; case tok::kw_signed: isInvalid = DS.SetTypeSpecSign(DeclSpec::TSS_signed, Loc, PrevSpec, Index: clang/lib/Parse/ParseExprCXX.cpp =================================================================== --- clang/lib/Parse/ParseExprCXX.cpp +++ clang/lib/Parse/ParseExprCXX.cpp @@ -2184,13 +2184,16 @@ // builtin types case tok::kw_short: - DS.SetTypeSpecWidth(DeclSpec::TSW_short, Loc, PrevSpec, DiagID, Policy); + DS.SetTypeSpecWidth(TypeSpecifierWidth::Short, Loc, PrevSpec, DiagID, + Policy); break; case tok::kw_long: - DS.SetTypeSpecWidth(DeclSpec::TSW_long, Loc, PrevSpec, DiagID, Policy); + DS.SetTypeSpecWidth(TypeSpecifierWidth::Long, Loc, PrevSpec, DiagID, + Policy); break; case tok::kw___int64: - DS.SetTypeSpecWidth(DeclSpec::TSW_longlong, Loc, PrevSpec, DiagID, Policy); + DS.SetTypeSpecWidth(TypeSpecifierWidth::LongLong, Loc, PrevSpec, DiagID, + Policy); break; case tok::kw_signed: DS.SetTypeSpecSign(DeclSpec::TSS_signed, Loc, PrevSpec, DiagID); Index: clang/lib/Sema/DeclSpec.cpp =================================================================== --- clang/lib/Sema/DeclSpec.cpp +++ clang/lib/Sema/DeclSpec.cpp @@ -502,12 +502,16 @@ llvm_unreachable("Unknown typespec!"); } -const char *DeclSpec::getSpecifierName(TSW W) { +const char *DeclSpec::getSpecifierName(TypeSpecifierWidth W) { switch (W) { - case TSW_unspecified: return "unspecified"; - case TSW_short: return "short"; - case TSW_long: return "long"; - case TSW_longlong: return "long long"; + case TypeSpecifierWidth::Unspecified: + return "unspecified"; + case TypeSpecifierWidth::Short: + return "short"; + case TypeSpecifierWidth::Long: + return "long"; + case TypeSpecifierWidth::LongLong: + return "long long"; } llvm_unreachable("Unknown typespec!"); } @@ -678,18 +682,21 @@ /// These methods set the specified attribute of the DeclSpec, but return true /// and ignore the request if invalid (e.g. "extern" then "auto" is /// specified). -bool DeclSpec::SetTypeSpecWidth(TSW W, SourceLocation Loc, - const char *&PrevSpec, - unsigned &DiagID, +bool DeclSpec::SetTypeSpecWidth(TypeSpecifierWidth W, SourceLocation Loc, + const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy) { // Overwrite TSWRange.Begin only if TypeSpecWidth was unspecified, so that // for 'long long' we will keep the source location of the first 'long'. - if (TypeSpecWidth == TSW_unspecified) + if (static_cast(TypeSpecWidth) == + TypeSpecifierWidth::Unspecified) TSWRange.setBegin(Loc); // Allow turning long -> long long. - else if (W != TSW_longlong || TypeSpecWidth != TSW_long) - return BadSpecifier(W, (TSW)TypeSpecWidth, PrevSpec, DiagID); - TypeSpecWidth = W; + else if (W != TypeSpecifierWidth::LongLong || + static_cast(TypeSpecWidth) != + TypeSpecifierWidth::Long) + return BadSpecifier(W, static_cast(TypeSpecWidth), + PrevSpec, DiagID); + TypeSpecWidth = static_cast(W); // Remember location of the last 'long' TSWRange.setEnd(Loc); return false; @@ -1090,7 +1097,7 @@ void DeclSpec::SaveWrittenBuiltinSpecs() { writtenBS.Sign = getTypeSpecSign(); - writtenBS.Width = getTypeSpecWidth(); + writtenBS.Width = static_cast(getTypeSpecWidth()); writtenBS.Type = getTypeSpecType(); // Search the list of attributes for the presence of a mode attribute. writtenBS.ModeAttr = getAttributes().hasAttribute(ParsedAttr::AT_Mode); @@ -1111,9 +1118,9 @@ // If decltype(auto) is used, no other type specifiers are permitted. if (TypeSpecType == TST_decltype_auto && - (TypeSpecWidth != TSW_unspecified || - TypeSpecComplex != TSC_unspecified || - TypeSpecSign != TSS_unspecified || + (static_cast(TypeSpecWidth) != + TypeSpecifierWidth::Unspecified || + TypeSpecComplex != TSC_unspecified || TypeSpecSign != TSS_unspecified || TypeAltiVecVector || TypeAltiVecPixel || TypeAltiVecBool || TypeQualifiers)) { const unsigned NumLocs = 9; @@ -1132,7 +1139,7 @@ Hints[I] = FixItHint::CreateRemoval(ExtraLocs[I]); } } - TypeSpecWidth = TSW_unspecified; + TypeSpecWidth = static_cast(TypeSpecifierWidth::Unspecified); TypeSpecComplex = TSC_unspecified; TypeSpecSign = TSS_unspecified; TypeAltiVecVector = TypeAltiVecPixel = TypeAltiVecBool = false; @@ -1166,13 +1173,18 @@ S.Diag(TSTLoc, diag::err_invalid_vector_bool_int128_decl_spec); // Only 'short' and 'long long' are valid with vector bool. (PIM 2.1) - if ((TypeSpecWidth != TSW_unspecified) && (TypeSpecWidth != TSW_short) && - (TypeSpecWidth != TSW_longlong)) + if ((static_cast(TypeSpecWidth) != + TypeSpecifierWidth::Unspecified) && + (static_cast(TypeSpecWidth) != + TypeSpecifierWidth::Short) && + (static_cast(TypeSpecWidth) != + TypeSpecifierWidth::LongLong)) S.Diag(TSWRange.getBegin(), diag::err_invalid_vector_bool_decl_spec) - << getSpecifierName((TSW)TypeSpecWidth); + << getSpecifierName(static_cast(TypeSpecWidth)); // vector bool long long requires VSX support or ZVector. - if ((TypeSpecWidth == TSW_longlong) && + if ((static_cast(TypeSpecWidth) == + TypeSpecifierWidth::LongLong) && (!S.Context.getTargetInfo().hasFeature("vsx")) && (!S.Context.getTargetInfo().hasFeature("power8-vector")) && !S.getLangOpts().ZVector) @@ -1180,12 +1192,17 @@ // Elements of vector bool are interpreted as unsigned. (PIM 2.1) if ((TypeSpecType == TST_char) || (TypeSpecType == TST_int) || - (TypeSpecType == TST_int128) || (TypeSpecWidth != TSW_unspecified)) + (TypeSpecType == TST_int128) || + (static_cast(TypeSpecWidth) != + TypeSpecifierWidth::Unspecified)) TypeSpecSign = TSS_unsigned; } else if (TypeSpecType == TST_double) { // vector long double and vector long long double are never allowed. // vector double is OK for Power7 and later, and ZVector. - if (TypeSpecWidth == TSW_long || TypeSpecWidth == TSW_longlong) + if (static_cast(TypeSpecWidth) == + TypeSpecifierWidth::Long || + static_cast(TypeSpecWidth) == + TypeSpecifierWidth::LongLong) S.Diag(TSWRange.getBegin(), diag::err_invalid_vector_long_double_decl_spec); else if (!S.Context.getTargetInfo().hasFeature("vsx") && @@ -1197,7 +1214,8 @@ if (S.getLangOpts().ZVector && !S.Context.getTargetInfo().hasFeature("arch12")) S.Diag(TSTLoc, diag::err_invalid_vector_float_decl_spec); - } else if (TypeSpecWidth == TSW_long) { + } else if (static_cast(TypeSpecWidth) == + TypeSpecifierWidth::Long) { // vector long is unsupported for ZVector and deprecated for AltiVec. // It has also been historically deprecated on AIX (as an alias for // "vector int" in both 32-bit and 64-bit modes). It was then made @@ -1217,7 +1235,7 @@ //TODO: perform validation TypeSpecType = TST_int; TypeSpecSign = TSS_unsigned; - TypeSpecWidth = TSW_short; + TypeSpecWidth = static_cast(TypeSpecifierWidth::Short); TypeSpecOwned = false; } } @@ -1240,14 +1258,17 @@ } // Validate the width of the type. - switch (TypeSpecWidth) { - case TSW_unspecified: break; - case TSW_short: // short int - case TSW_longlong: // long long int + switch (static_cast(TypeSpecWidth)) { + case TypeSpecifierWidth::Unspecified: + break; + case TypeSpecifierWidth::Short: // short int + case TypeSpecifierWidth::LongLong: // long long int if (TypeSpecType == TST_unspecified) TypeSpecType = TST_int; // short -> short int, long long -> long long int. else if (!(TypeSpecType == TST_int || - (IsFixedPointType && TypeSpecWidth != TSW_longlong))) { + (IsFixedPointType && + static_cast(TypeSpecWidth) != + TypeSpecifierWidth::LongLong))) { S.Diag(TSWRange.getBegin(), diag::err_invalid_width_spec) << (int)TypeSpecWidth << getSpecifierName((TST)TypeSpecType, Policy); TypeSpecType = TST_int; @@ -1255,7 +1276,7 @@ TypeSpecOwned = false; } break; - case TSW_long: // long double, long int + case TypeSpecifierWidth::Long: // long double, long int if (TypeSpecType == TST_unspecified) TypeSpecType = TST_int; // long -> long int. else if (TypeSpecType != TST_int && TypeSpecType != TST_double && Index: clang/lib/Sema/SemaType.cpp =================================================================== --- clang/lib/Sema/SemaType.cpp +++ clang/lib/Sema/SemaType.cpp @@ -1403,10 +1403,16 @@ case DeclSpec::TST_int: { if (DS.getTypeSpecSign() != DeclSpec::TSS_unsigned) { switch (DS.getTypeSpecWidth()) { - case DeclSpec::TSW_unspecified: Result = Context.IntTy; break; - case DeclSpec::TSW_short: Result = Context.ShortTy; break; - case DeclSpec::TSW_long: Result = Context.LongTy; break; - case DeclSpec::TSW_longlong: + case TypeSpecifierWidth::Unspecified: + Result = Context.IntTy; + break; + case TypeSpecifierWidth::Short: + Result = Context.ShortTy; + break; + case TypeSpecifierWidth::Long: + Result = Context.LongTy; + break; + case TypeSpecifierWidth::LongLong: Result = Context.LongLongTy; // 'long long' is a C99 or C++11 feature. @@ -1422,10 +1428,16 @@ } } else { switch (DS.getTypeSpecWidth()) { - case DeclSpec::TSW_unspecified: Result = Context.UnsignedIntTy; break; - case DeclSpec::TSW_short: Result = Context.UnsignedShortTy; break; - case DeclSpec::TSW_long: Result = Context.UnsignedLongTy; break; - case DeclSpec::TSW_longlong: + case TypeSpecifierWidth::Unspecified: + Result = Context.UnsignedIntTy; + break; + case TypeSpecifierWidth::Short: + Result = Context.UnsignedShortTy; + break; + case TypeSpecifierWidth::Long: + Result = Context.UnsignedLongTy; + break; + case TypeSpecifierWidth::LongLong: Result = Context.UnsignedLongLongTy; // 'long long' is a C99 or C++11 feature. @@ -1456,17 +1468,17 @@ } case DeclSpec::TST_accum: { switch (DS.getTypeSpecWidth()) { - case DeclSpec::TSW_short: - Result = Context.ShortAccumTy; - break; - case DeclSpec::TSW_unspecified: - Result = Context.AccumTy; - break; - case DeclSpec::TSW_long: - Result = Context.LongAccumTy; - break; - case DeclSpec::TSW_longlong: - llvm_unreachable("Unable to specify long long as _Accum width"); + case TypeSpecifierWidth::Short: + Result = Context.ShortAccumTy; + break; + case TypeSpecifierWidth::Unspecified: + Result = Context.AccumTy; + break; + case TypeSpecifierWidth::Long: + Result = Context.LongAccumTy; + break; + case TypeSpecifierWidth::LongLong: + llvm_unreachable("Unable to specify long long as _Accum width"); } if (DS.getTypeSpecSign() == DeclSpec::TSS_unsigned) @@ -1479,17 +1491,17 @@ } case DeclSpec::TST_fract: { switch (DS.getTypeSpecWidth()) { - case DeclSpec::TSW_short: - Result = Context.ShortFractTy; - break; - case DeclSpec::TSW_unspecified: - Result = Context.FractTy; - break; - case DeclSpec::TSW_long: - Result = Context.LongFractTy; - break; - case DeclSpec::TSW_longlong: - llvm_unreachable("Unable to specify long long as _Fract width"); + case TypeSpecifierWidth::Short: + Result = Context.ShortFractTy; + break; + case TypeSpecifierWidth::Unspecified: + Result = Context.FractTy; + break; + case TypeSpecifierWidth::Long: + Result = Context.LongFractTy; + break; + case TypeSpecifierWidth::LongLong: + llvm_unreachable("Unable to specify long long as _Fract width"); } if (DS.getTypeSpecSign() == DeclSpec::TSS_unsigned) @@ -1529,7 +1541,7 @@ break; case DeclSpec::TST_float: Result = Context.FloatTy; break; case DeclSpec::TST_double: - if (DS.getTypeSpecWidth() == DeclSpec::TSW_long) + if (DS.getTypeSpecWidth() == TypeSpecifierWidth::Long) Result = Context.LongDoubleTy; else Result = Context.DoubleTy; @@ -5869,7 +5881,7 @@ // Try to have a meaningful source location. if (TL.getWrittenSignSpec() != TSS_unspecified) TL.expandBuiltinRange(DS.getTypeSpecSignLoc()); - if (TL.getWrittenWidthSpec() != TSW_unspecified) + if (TL.getWrittenWidthSpec() != TypeSpecifierWidth::Unspecified) TL.expandBuiltinRange(DS.getTypeSpecWidthRange()); } } Index: clang/lib/Serialization/ASTReader.cpp =================================================================== --- clang/lib/Serialization/ASTReader.cpp +++ clang/lib/Serialization/ASTReader.cpp @@ -6473,7 +6473,7 @@ if (TL.needsExtraLocalData()) { TL.setWrittenTypeSpec(static_cast(Reader.readInt())); TL.setWrittenSignSpec(static_cast(Reader.readInt())); - TL.setWrittenWidthSpec(static_cast(Reader.readInt())); + TL.setWrittenWidthSpec(static_cast(Reader.readInt())); TL.setModeAttr(Reader.readInt()); } } Index: clang/lib/Serialization/ASTWriter.cpp =================================================================== --- clang/lib/Serialization/ASTWriter.cpp +++ clang/lib/Serialization/ASTWriter.cpp @@ -199,7 +199,7 @@ if (TL.needsExtraLocalData()) { Record.push_back(TL.getWrittenTypeSpec()); Record.push_back(TL.getWrittenSignSpec()); - Record.push_back(TL.getWrittenWidthSpec()); + Record.push_back(static_cast(TL.getWrittenWidthSpec())); Record.push_back(TL.hasModeAttr()); } }