From cbb33f86e85d82f3ebe22c486e9b1bbcacb584d9 Mon Sep 17 00:00:00 2001 From: acqn Date: Tue, 28 Jul 2020 11:17:17 +0800 Subject: [PATCH] Disabled using non-int-size types to declare bit-fields. --- src/cc65/datatype.h | 30 ++++++++++++++++++++---------- src/cc65/declare.c | 7 +++++++ 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/cc65/datatype.h b/src/cc65/datatype.h index 2f2ed136e..1997b5c89 100644 --- a/src/cc65/datatype.h +++ b/src/cc65/datatype.h @@ -601,6 +601,26 @@ INLINE int IsSignSigned (const Type* T) # define IsSignSigned(T) (GetSignedness (T) == T_SIGN_SIGNED) #endif +#if defined(HAVE_INLINE) +INLINE TypeCode GetRawSizeModifier(const Type* T) +/* Get the size modifier of a raw type */ +{ + return (T->C & T_MASK_SIZE); +} +#else +# define GetRawSizeModifier(T) ((T)->C & T_MASK_SIZE) +#endif + +#if defined(HAVE_INLINE) +INLINE TypeCode GetSizeModifier (const Type* T) +/* Get the size modifier of a type */ +{ + return (GetUnderlyingTypeCode (T) & T_MASK_SIZE); +} +#else +# define GetSizeModifier(T) (GetUnderlyingTypeCode (T) & T_MASK_SIZE) +#endif + #if defined(HAVE_INLINE) INLINE TypeCode GetQualifier (const Type* T) /* Get the qualifier from the given type string */ @@ -696,16 +716,6 @@ int IsVariadicFunc (const Type* T) attribute ((const)); ** variable parameter list */ -#if defined(HAVE_INLINE) -INLINE TypeCode GetSizeModifier (const Type* T) -/* Get the size modifier of a type */ -{ - return (T->C & T_MASK_SIZE); -} -#else -# define GetSizeModifier(T) ((T)->C & T_MASK_SIZE) -#endif - FuncDesc* GetFuncDesc (const Type* T) attribute ((const)); /* Get the FuncDesc pointer from a function or pointer-to-function type */ diff --git a/src/cc65/declare.c b/src/cc65/declare.c index ba4091c3b..cb3aa0ab3 100644 --- a/src/cc65/declare.c +++ b/src/cc65/declare.c @@ -689,6 +689,13 @@ static int ParseFieldWidth (Declaration* Decl) Error ("Bit-field has invalid type '%s'", GetBasicTypeName (Decl->Type)); return -1; } + + if (SizeOf (Decl->Type) != SizeOf (type_uint)) { + /* Only int sized types may be used for bit-fields for now */ + Error ("CC65 currently only supports unsigned int bit-fields"); + return -1; + } + if (Expr.IVal < 0) { Error ("Negative width in bit-field"); return -1;