Hi development team,
I found a bug in tcc version 0.9.26 (x86-64 Win64) under Windows.
Integer division of the smallest or biggest 64-bit value by the
smallest or biggest 32-bit value does not work correct.
You can see that with the attached example program (tcc_err2.c).
If I do compile tcc_err2.c with tcc and execute it I get the following:
C:\seed7\src>tcc -o tcc_err2.exe tcc_err2.c
C:\seed7\src>tcc_err2
sizeof(long): 4
sizeof(long long): 8
Using long long.
-9223372036854775808LL / -2147483649LL = 0 expected:
4294967294
-9223372036854775808LL / -2147483648LL = 0 expected:
4294967296
9223372036854775807LL / -2147483649LL = 0 expected:
-4294967294
9223372036854775807LL / -2147483648LL = 0 expected:
-4294967295
-9223372036854775808LL % -2147483649LL = -9223372036854775808 expected:
-2
-9223372036854775808LL % -2147483648LL = -9223372036854775808 expected:
0
9223372036854775807LL % -2147483649LL = 9223372036854775807 expected:
1
9223372036854775807LL % -2147483648LL = 9223372036854775807 expected:
2147483647
If I compile tcc_err2.c with gcc and execute it everything is okay:
C:\seed7\src>gcc -o tcc_err2.exe tcc_err2.c
C:\seed7\src>tcc_err2
sizeof(long): 4
sizeof(long long): 8
Using long long.
-9223372036854775808LL / -2147483649LL = 4294967294 expected:
4294967294
-9223372036854775808LL / -2147483648LL = 4294967296 expected:
4294967296
9223372036854775807LL / -2147483649LL = -4294967294 expected:
-4294967294
9223372036854775807LL / -2147483648LL = -4294967295 expected:
-4294967295
-9223372036854775808LL % -2147483649LL = -2 expected:
-2
-9223372036854775808LL % -2147483648LL = 0 expected:
0
9223372036854775807LL % -2147483649LL = 1 expected:
1
9223372036854775807LL % -2147483648LL = 2147483647 expected:
2147483647
I home thet it is possible to fix this bug.
Regards
Thomas Mertes
--
Seed7 Homepage: http://seed7.sourceforge.net
Seed7 - The extensible programming language: User defined statements
and operators, abstract data types, templates without special
syntax, OO with interfaces and multiple dispatch, statically typed,
interpreted or compiled, portable, runs under linux/unix/windows.
#include "stdio.h"
#if ULONG_MAX > 4294967295U
typedef long intType;
#define INT_SUFFIX(num) num ## L
#define SUFFIX "L"
#define INTTYPE_FORMAT "l"
#define MESSAGE "Using long.\n"
#else
typedef long long intType;
#define INT_SUFFIX(num) num ## LL
#define SUFFIX "LL"
#define INTTYPE_FORMAT "ll"
#define MESSAGE "Using long long.\n"
#endif
#define F_D(width) "%" #width INTTYPE_FORMAT "d"
#if 0
/* Allow the compiler to compute the division. */
#define intExpr(num) (num)
#else
/* The division will (probably) be done at runtime. */
intType intExpr (intType number) { return number; }
#endif
int main (int argc, char **argv)
{
printf("sizeof(long): %lu\n", sizeof(long));
printf("sizeof(long long): %lu\n", sizeof(long long));
printf(MESSAGE);
printf("-9223372036854775808" SUFFIX " / -2147483649" SUFFIX " = " F_D(20) "
expected: 4294967294\n",
intExpr(INT_SUFFIX(-9223372036854775807)-1) / INT_SUFFIX(-2147483649));
printf("-9223372036854775808" SUFFIX " / -2147483648" SUFFIX " = " F_D(20) "
expected: 4294967296\n",
intExpr(INT_SUFFIX(-9223372036854775807)-1) / INT_SUFFIX(-2147483648));
printf(" 9223372036854775807" SUFFIX " / -2147483649" SUFFIX " = " F_D(20) "
expected: -4294967294\n",
intExpr(INT_SUFFIX( 9223372036854775807)) /
INT_SUFFIX(-2147483649));
printf(" 9223372036854775807" SUFFIX " / -2147483648" SUFFIX " = " F_D(20) "
expected: -4294967295\n",
intExpr(INT_SUFFIX( 9223372036854775807)) /
INT_SUFFIX(-2147483648));
printf("-9223372036854775808" SUFFIX " %% -2147483649" SUFFIX " = " F_D(20) "
expected: -2\n",
intExpr(INT_SUFFIX(-9223372036854775807)-1) % INT_SUFFIX(-2147483649));
printf("-9223372036854775808" SUFFIX " %% -2147483648" SUFFIX " = " F_D(20) "
expected: 0\n",
intExpr(INT_SUFFIX(-9223372036854775807)-1) % INT_SUFFIX(-2147483648));
printf(" 9223372036854775807" SUFFIX " %% -2147483649" SUFFIX " = " F_D(20) "
expected: 1\n",
intExpr(INT_SUFFIX( 9223372036854775807)) %
INT_SUFFIX(-2147483649));
printf(" 9223372036854775807" SUFFIX " %% -2147483648" SUFFIX " = " F_D(20) "
expected: 2147483647\n",
intExpr(INT_SUFFIX( 9223372036854775807)) %
INT_SUFFIX(-2147483648));
return 0;
}
_______________________________________________
Tinycc-devel mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/tinycc-devel