Fixed CHECK failures on certain usage of incomplete enums.

This commit is contained in:
acqn
2020-08-22 05:56:33 +08:00
committed by Oliver Schmidt
parent 1957dc7a5c
commit 43cb092a68
2 changed files with 15 additions and 3 deletions

View File

@@ -686,7 +686,10 @@ const Type* GetUnderlyingType (const Type* Type)
Internal ("Enum tag type error in GetUnderlyingTypeCode"); Internal ("Enum tag type error in GetUnderlyingTypeCode");
} }
return ((SymEntry*)Type->A.P)->V.E.Type; /* If incomplete enum type is used, just return its raw type */
if (((SymEntry*)Type->A.P)->V.E.Type != 0) {
return ((SymEntry*)Type->A.P)->V.E.Type;
}
} }
return Type; return Type;
@@ -1246,9 +1249,14 @@ Type* IntPromotion (Type* T)
** to unsigned int. ** to unsigned int.
*/ */
return IsSignUnsigned (T) ? type_uint : type_int; return IsSignUnsigned (T) ? type_uint : type_int;
} else { } else if (!IsIncompleteESUType (T)) {
/* Otherwise, the type is not smaller than int, so leave it alone. */ /* The type is a complete type not smaller than int, so leave it alone. */
return T; return T;
} else {
/* Otherwise, this is an incomplete enum, and there is expceted to be an error already.
** Assume int to avoid further errors.
*/
return type_int;
} }
} }

View File

@@ -142,6 +142,10 @@ void LoadExpr (unsigned Flags, struct ExprDesc* Expr)
BitFieldFullWidthFlags |= CF_UNSIGNED; BitFieldFullWidthFlags |= CF_UNSIGNED;
} }
} else if ((Flags & CF_TYPEMASK) == 0) { } else if ((Flags & CF_TYPEMASK) == 0) {
/* If Expr is an incomplete ESY type, bail out */
if (IsIncompleteESUType (Expr->Type)) {
return;
}
Flags |= TypeOf (Expr->Type); Flags |= TypeOf (Expr->Type);
} }