From 0f412b6beb1319255834b7062c000a1295140e4b Mon Sep 17 00:00:00 2001 From: acqn Date: Mon, 27 Jul 2020 18:25:28 +0800 Subject: [PATCH] Small fixes according to PR review. --- src/cc65/datatype.c | 10 ++++++++-- src/cc65/declare.c | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/cc65/datatype.c b/src/cc65/datatype.c index 3f2725659..4da9a8727 100644 --- a/src/cc65/datatype.c +++ b/src/cc65/datatype.c @@ -278,7 +278,8 @@ long GetIntegerTypeMin (const Type* Type) /* Get the smallest possible value of the integer type */ { if (IsSignSigned (Type)) { - return (long)(0xFFFFFFFF << (CHAR_BITS * SizeOf (Type) - 1U)); + /* The smallest possible signed value of N-byte integer is -pow(2, 8*N-1) */ + return (long)((unsigned long)(-1L) << (CHAR_BITS * SizeOf (Type) - 1U)); } else { return 0; } @@ -290,9 +291,14 @@ unsigned long GetIntegerTypeMax (const Type* Type) /* Get the largest possible value of the integer type */ { if (IsSignSigned (Type)) { + /* Min signed value of N-byte integer is pow(2, 8*N-1) - 1 */ return (1UL << (CHAR_BITS * SizeOf (Type) - 1U)) - 1UL; } else { - return (1UL << (CHAR_BITS * SizeOf (Type))) - 1UL; + /* Max signed value of N-byte integer is pow(2, 8*N) - 1. However, + ** workaround is needed as in ISO C it is UB if the shift count is + ** equal to the bit width of the left operand type. + */ + return (1UL << 1U << (CHAR_BITS * SizeOf (Type) - 1U)) - 1UL; } } diff --git a/src/cc65/declare.c b/src/cc65/declare.c index 49e233a56..ba4091c3b 100644 --- a/src/cc65/declare.c +++ b/src/cc65/declare.c @@ -686,7 +686,7 @@ static int ParseFieldWidth (Declaration* Decl) ConstAbsIntExpr (hie1, &Expr); if (!IsClassInt (Decl->Type)) { /* Only integer types may be used for bit-fields */ - Error ("Bit-field has invalid type ''"); + Error ("Bit-field has invalid type '%s'", GetBasicTypeName (Decl->Type)); return -1; } if (Expr.IVal < 0) {