Merge pull request #2084 from bbbradsmith/numerical_constant_errors-int

Numerical constant errors and improvements (integer)
This commit is contained in:
Bob Andrews
2023-05-06 21:36:59 +02:00
committed by GitHub
9 changed files with 77 additions and 7 deletions

View File

@@ -0,0 +1,7 @@
/* too big for internal integer representation */
unsigned long huge = 4294967296;
int main(void)
{
return 0;
}

View File

@@ -0,0 +1,20 @@
/* Integer constant overflow warnings. */
/* Warnings as errors. */
#pragma warn(error,on)
/* Warn on const overflow */
#pragma warn(const-overflow,on)
unsigned char a = 256;
signed char b = 128;
unsigned char c = -129;
unsigned short int d = 0x00010000;
unsigned short int e = 0x80000000;
signed short int f = 32768L;
signed short int g = -32769L;
int main(void)
{
return 0;
}

View File

@@ -20,3 +20,4 @@
#define SIZEOF_LONG_32BIT
#define UNSIGNED_CHARS
#define UNSIGNED_BITFIELDS
#define INTEGER_CONSTANT_MAX_32BIT

View File

@@ -4,6 +4,14 @@
!!LICENCE!! own, freely distributeable for non-profit. read CPYRIGHT.LCC
*/
/* INTEGER_CONSTANT_MAX_32BIT
** This suppresses constants longer than 32-bit, which are now an error:
** https://github.com/cc65/cc65/pull/2084
** Because cc65's internal representation is implicitly/explicitly
** 32-bit in many places, values larger than this aren't representable,
** but also can't be checked for overflow once accepted.
*/
#include "common.h"
struct defs {
@@ -62,7 +70,12 @@ long pow2(long n) {
return s;
}
long d[39], o[39], x[39];
#ifndef INTEGER_CONSTANT_MAX_32BIT
#define CTCOUNT 39
#else
#define CTCOUNT 36
#endif
long d[CTCOUNT], o[CTCOUNT], x[CTCOUNT];
#ifndef NO_OLD_FUNC_DECL
s241(pd0)
@@ -212,13 +225,15 @@ int s241(struct defs *pd0) {
d[33] = 1073741823; o[33] = 07777777777; x[33] = 0x3fffffff;
d[34] = 1073741824; o[34] = 010000000000; x[34] = 0x40000000;
d[35] = 4294967295; o[35] = 037777777777; x[35] = 0xffffffff;
#if CTCOUNT > 36
d[36] = 4294967296; o[36] = 040000000000; x[36] = 0x100000000;
d[37] = 68719476735; o[37] = 0777777777777; x[37] = 0xfffffffff;
d[38] = 68719476736; o[38] = 01000000000000; x[38] = 0x1000000000;
#endif
/* WHEW! */
for (j=0; j<39; j++){
for (j=0; j<CTCOUNT; j++){
if ( g[j] != d[j]
|| d[j] != o[j]
|| o[j] != x[j]) {