[clang] e6aa065 - [NFC, Refactor] Modernize the TypeSpecifierWidth enum (Specifiers.h) to a scoped enum
via cfe-commits
cfe-commits at lists.llvm.org
Sun Nov 15 09:16:48 PST 2020
Author: faisalv
Date: 2020-11-15T11:13:57-06:00
New Revision: e6aa06545b123292be283af7c414daead23cf9ab
URL: https://github.com/llvm/llvm-project/commit/e6aa06545b123292be283af7c414daead23cf9ab
DIFF: https://github.com/llvm/llvm-project/commit/e6aa06545b123292be283af7c414daead23cf9ab.diff
LOG: [NFC, Refactor] Modernize the TypeSpecifierWidth enum (Specifiers.h) to a scoped enum
Reviewed here: https://reviews.llvm.org/D91409 by Aaron.
Highlights of the review:
- avoid an underlying type for enums
- avoid enum bit fields (MSVC packing anomalies) and favor static_casts to unsigned bit-fields
Patch by Thorsten Schuett <schuett at gmail.com> w some minor fixes in SemaType.cpp where a couple asserts had to be repaired to deal with lack of implicit coversion to int.
Thanks Thorsten!
Added:
Modified:
clang/include/clang/AST/TypeLoc.h
clang/include/clang/Basic/Specifiers.h
clang/include/clang/Sema/DeclSpec.h
clang/lib/Parse/ParseDecl.cpp
clang/lib/Parse/ParseExprCXX.cpp
clang/lib/Sema/DeclSpec.cpp
clang/lib/Sema/SemaType.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/TypeLoc.h b/clang/include/clang/AST/TypeLoc.h
index 72cc8ef098e7..4d3d4a94cbf3 100644
--- a/clang/include/clang/AST/TypeLoc.h
+++ b/clang/include/clang/AST/TypeLoc.h
@@ -619,16 +619,16 @@ class BuiltinTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
if (needsExtraLocalData())
return static_cast<TypeSpecifierWidth>(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<unsigned>(written);
}
TypeSpecifierType getWrittenTypeSpec() const;
@@ -659,7 +659,7 @@ class BuiltinTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
if (needsExtraLocalData()) {
WrittenBuiltinSpecs &wbs = getWrittenBuiltinSpecs();
wbs.Sign = TSS_unspecified;
- wbs.Width = TSW_unspecified;
+ wbs.Width = static_cast<unsigned>(TypeSpecifierWidth::Unspecified);
wbs.Type = TST_unspecified;
wbs.ModeAttr = false;
}
diff --git a/clang/include/clang/Basic/Specifiers.h b/clang/include/clang/Basic/Specifiers.h
index 2834dea20d00..cdd67a688283 100644
--- a/clang/include/clang/Basic/Specifiers.h
+++ b/clang/include/clang/Basic/Specifiers.h
@@ -37,12 +37,7 @@ namespace clang {
};
/// 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 { Unspecified, Short, Long, LongLong };
/// Specifies the signedness of a type, e.g., signed or unsigned.
enum TypeSpecifierSign {
@@ -106,7 +101,7 @@ namespace clang {
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;
+ /*TypeSpecifierWidth*/ unsigned Width : 2;
unsigned ModeAttr : 1;
};
diff --git a/clang/include/clang/Sema/DeclSpec.h b/clang/include/clang/Sema/DeclSpec.h
index 0598d0d61b15..290384b13df1 100644
--- a/clang/include/clang/Sema/DeclSpec.h
+++ b/clang/include/clang/Sema/DeclSpec.h
@@ -249,13 +249,6 @@ class DeclSpec {
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 @@ class DeclSpec {
unsigned SCS_extern_in_linkage_spec : 1;
// type-specifier
- /*TSW*/unsigned TypeSpecWidth : 2;
+ /*TypeSpecifierWidth*/ unsigned TypeSpecWidth : 2;
/*TSC*/unsigned TypeSpecComplex : 2;
/*TSS*/unsigned TypeSpecSign : 2;
/*TST*/unsigned TypeSpecType : 6;
@@ -434,17 +427,17 @@ class DeclSpec {
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<unsigned>(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 @@ class DeclSpec {
}
// type-specifier
- TSW getTypeSpecWidth() const { return (TSW)TypeSpecWidth; }
+ TypeSpecifierWidth getTypeSpecWidth() const {
+ return static_cast<TypeSpecifierWidth>(TypeSpecWidth);
+ }
TSC getTypeSpecComplex() const { return (TSC)TypeSpecComplex; }
TSS getTypeSpecSign() const { return (TSS)TypeSpecSign; }
TST getTypeSpecType() const { return (TST)TypeSpecType; }
@@ -542,7 +537,7 @@ class DeclSpec {
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 @@ class DeclSpec {
/// 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 @@ class DeclSpec {
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,
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index 0a19c0bc243d..22d38f07faec 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -3690,20 +3690,20 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS,
// 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,
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index 99dd6275527b..2d28660930bf 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -2184,13 +2184,16 @@ void Parser::ParseCXXSimpleTypeSpecifier(DeclSpec &DS) {
// 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);
diff --git a/clang/lib/Sema/DeclSpec.cpp b/clang/lib/Sema/DeclSpec.cpp
index 8831cb5af55a..012479356122 100644
--- a/clang/lib/Sema/DeclSpec.cpp
+++ b/clang/lib/Sema/DeclSpec.cpp
@@ -502,12 +502,16 @@ const char *DeclSpec::getSpecifierName(DeclSpec::TSCS S) {
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,18 @@ bool DeclSpec::SetStorageClassSpecThread(TSCS TSC, SourceLocation Loc,
/// 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 (getTypeSpecWidth() == 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 ||
+ getTypeSpecWidth() != TypeSpecifierWidth::Long)
+ return BadSpecifier(W, getTypeSpecWidth(), PrevSpec, DiagID);
+ TypeSpecWidth = static_cast<unsigned>(W);
// Remember location of the last 'long'
TSWRange.setEnd(Loc);
return false;
@@ -1090,7 +1094,7 @@ bool DeclSpec::SetConstexprSpec(ConstexprSpecKind ConstexprKind,
void DeclSpec::SaveWrittenBuiltinSpecs() {
writtenBS.Sign = getTypeSpecSign();
- writtenBS.Width = getTypeSpecWidth();
+ writtenBS.Width = TypeSpecWidth;
writtenBS.Type = getTypeSpecType();
// Search the list of attributes for the presence of a mode attribute.
writtenBS.ModeAttr = getAttributes().hasAttribute(ParsedAttr::AT_Mode);
@@ -1111,9 +1115,8 @@ void DeclSpec::Finish(Sema &S, const PrintingPolicy &Policy) {
// 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 ||
+ (getTypeSpecWidth() != TypeSpecifierWidth::Unspecified ||
+ TypeSpecComplex != TSC_unspecified || TypeSpecSign != TSS_unspecified ||
TypeAltiVecVector || TypeAltiVecPixel || TypeAltiVecBool ||
TypeQualifiers)) {
const unsigned NumLocs = 9;
@@ -1132,7 +1135,7 @@ void DeclSpec::Finish(Sema &S, const PrintingPolicy &Policy) {
Hints[I] = FixItHint::CreateRemoval(ExtraLocs[I]);
}
}
- TypeSpecWidth = TSW_unspecified;
+ TypeSpecWidth = static_cast<unsigned>(TypeSpecifierWidth::Unspecified);
TypeSpecComplex = TSC_unspecified;
TypeSpecSign = TSS_unspecified;
TypeAltiVecVector = TypeAltiVecPixel = TypeAltiVecBool = false;
@@ -1166,13 +1169,14 @@ void DeclSpec::Finish(Sema &S, const PrintingPolicy &Policy) {
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 ((getTypeSpecWidth() != TypeSpecifierWidth::Unspecified) &&
+ (getTypeSpecWidth() != TypeSpecifierWidth::Short) &&
+ (getTypeSpecWidth() != TypeSpecifierWidth::LongLong))
S.Diag(TSWRange.getBegin(), diag::err_invalid_vector_bool_decl_spec)
- << getSpecifierName((TSW)TypeSpecWidth);
+ << getSpecifierName(getTypeSpecWidth());
// vector bool long long requires VSX support or ZVector.
- if ((TypeSpecWidth == TSW_longlong) &&
+ if ((getTypeSpecWidth() == TypeSpecifierWidth::LongLong) &&
(!S.Context.getTargetInfo().hasFeature("vsx")) &&
(!S.Context.getTargetInfo().hasFeature("power8-vector")) &&
!S.getLangOpts().ZVector)
@@ -1180,12 +1184,14 @@ void DeclSpec::Finish(Sema &S, const PrintingPolicy &Policy) {
// 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) ||
+ (getTypeSpecWidth() != 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 (getTypeSpecWidth() == TypeSpecifierWidth::Long ||
+ getTypeSpecWidth() == TypeSpecifierWidth::LongLong)
S.Diag(TSWRange.getBegin(),
diag::err_invalid_vector_long_double_decl_spec);
else if (!S.Context.getTargetInfo().hasFeature("vsx") &&
@@ -1197,7 +1203,7 @@ void DeclSpec::Finish(Sema &S, const PrintingPolicy &Policy) {
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 (getTypeSpecWidth() == 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 +1223,7 @@ void DeclSpec::Finish(Sema &S, const PrintingPolicy &Policy) {
//TODO: perform validation
TypeSpecType = TST_int;
TypeSpecSign = TSS_unsigned;
- TypeSpecWidth = TSW_short;
+ TypeSpecWidth = static_cast<unsigned>(TypeSpecifierWidth::Short);
TypeSpecOwned = false;
}
}
@@ -1240,14 +1246,16 @@ void DeclSpec::Finish(Sema &S, const PrintingPolicy &Policy) {
}
// Validate the width of the type.
- switch (TypeSpecWidth) {
- case TSW_unspecified: break;
- case TSW_short: // short int
- case TSW_longlong: // long long int
+ switch (getTypeSpecWidth()) {
+ 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 &&
+ getTypeSpecWidth() != TypeSpecifierWidth::LongLong))) {
S.Diag(TSWRange.getBegin(), diag::err_invalid_width_spec)
<< (int)TypeSpecWidth << getSpecifierName((TST)TypeSpecType, Policy);
TypeSpecType = TST_int;
@@ -1255,7 +1263,7 @@ void DeclSpec::Finish(Sema &S, const PrintingPolicy &Policy) {
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 &&
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 7f18dc77762f..e978fa9bfe0a 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -1403,10 +1403,16 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) {
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 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) {
}
} 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 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) {
}
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 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) {
}
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 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) {
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;
@@ -1568,8 +1580,9 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) {
// If the type is deprecated or unavailable, diagnose it.
S.DiagnoseUseOfDecl(D, DS.getTypeSpecTypeNameLoc());
- assert(DS.getTypeSpecWidth() == 0 && DS.getTypeSpecComplex() == 0 &&
- DS.getTypeSpecSign() == 0 && "No qualifiers on tag names!");
+ assert(DS.getTypeSpecWidth() == TypeSpecifierWidth::Unspecified &&
+ DS.getTypeSpecComplex() == 0 && DS.getTypeSpecSign() == 0 &&
+ "No qualifiers on tag names!");
// TypeQuals handled by caller.
Result = Context.getTypeDeclType(D);
@@ -1582,7 +1595,8 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) {
break;
}
case DeclSpec::TST_typename: {
- assert(DS.getTypeSpecWidth() == 0 && DS.getTypeSpecComplex() == 0 &&
+ assert(DS.getTypeSpecWidth() == TypeSpecifierWidth::Unspecified &&
+ DS.getTypeSpecComplex() == 0 &&
DS.getTypeSpecSign() == 0 &&
"Can't handle qualifiers on typedef names yet!");
Result = S.GetTypeFromParser(DS.getRepAsType());
@@ -5869,7 +5883,7 @@ namespace {
// 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());
}
}
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index 600454399f68..0aa70e325acf 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -6458,7 +6458,7 @@ void TypeLocReader::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) {
if (TL.needsExtraLocalData()) {
TL.setWrittenTypeSpec(static_cast<DeclSpec::TST>(Reader.readInt()));
TL.setWrittenSignSpec(static_cast<DeclSpec::TSS>(Reader.readInt()));
- TL.setWrittenWidthSpec(static_cast<DeclSpec::TSW>(Reader.readInt()));
+ TL.setWrittenWidthSpec(static_cast<TypeSpecifierWidth>(Reader.readInt()));
TL.setModeAttr(Reader.readInt());
}
}
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp
index e9994cbc9d72..88d68c400d2a 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -199,7 +199,7 @@ void TypeLocWriter::VisitBuiltinTypeLoc(BuiltinTypeLoc TL) {
if (TL.needsExtraLocalData()) {
Record.push_back(TL.getWrittenTypeSpec());
Record.push_back(TL.getWrittenSignSpec());
- Record.push_back(TL.getWrittenWidthSpec());
+ Record.push_back(static_cast<uint64_t>(TL.getWrittenWidthSpec()));
Record.push_back(TL.hasModeAttr());
}
}
More information about the cfe-commits
mailing list