mes: Identify 64-bit bug when compiled with MesCC.

* src/math.c (divide): Add divide-by-zero error.
(modulo): Likewise.
* module/mes/guile.scm (%compiler): New variable.
* module/mescc/M1.scm (mesc?): New variable.
(hex2:immediate8): Use it to avoid divide-by-zero error.
* HACKING (Bugs): Add it.
This commit is contained in:
Jan Nieuwenhuizen 2019-05-27 21:33:20 +02:00
parent 952b92dfec
commit a22e5d3acc
No known key found for this signature in database
GPG key ID: F3C1A0D9C1D65273
4 changed files with 26 additions and 7 deletions

View file

@ -151,6 +151,13 @@ actual: -./,),(-*,(
** mes+mescc: parse tcc.c->tcc.E works, compile tcc.E -> tcc.M1 segfaults. ** mes+mescc: parse tcc.c->tcc.E works, compile tcc.E -> tcc.M1 segfaults.
time GUILE_LOAD_PATH=/home/janneke/src/nyacc/module:$GUILE_LOAD_PATH ../mes/scripts/mescc -E -o tcc.E -I . -I ../mes/lib -I ../mes/include -D 'CONFIG_TCCDIR="usr/lib/tcc"' -D 'CONFIG_TCC_CRTPREFIX="usr/lib:{B}/lib:."' -D 'CONFIG_TCC_ELFINTERP="/gnu/store/70jxsnpffkl7fdb7qv398n8yi1a3w5nx-glibc-2.26.105-g0890d5379c/lib/ld-linux.so.2"' -D 'CONFIG_TCC_LIBPATHS="/home/janneke/src/tinycc/usr/lib:{B}/lib:."' -D 'CONFIG_TCC_SYSINCLUDEPATHS="../mes/include:usr/include:{B}/include"' -D CONFIG_USE_LIBGCC=1 -D 'TCC_LIBGCC="/home/janneke/src/tinycc/usr/lib/libc+tcc-gcc.mlibc-o"' -D CONFIG_TCC_STATIC=1 -D ONE_SOURCE=yes -D TCC_TARGET_I386=1 -D BOOTSTRAP=1 tcc.c time GUILE_LOAD_PATH=/home/janneke/src/nyacc/module:$GUILE_LOAD_PATH ../mes/scripts/mescc -E -o tcc.E -I . -I ../mes/lib -I ../mes/include -D 'CONFIG_TCCDIR="usr/lib/tcc"' -D 'CONFIG_TCC_CRTPREFIX="usr/lib:{B}/lib:."' -D 'CONFIG_TCC_ELFINTERP="/gnu/store/70jxsnpffkl7fdb7qv398n8yi1a3w5nx-glibc-2.26.105-g0890d5379c/lib/ld-linux.so.2"' -D 'CONFIG_TCC_LIBPATHS="/home/janneke/src/tinycc/usr/lib:{B}/lib:."' -D 'CONFIG_TCC_SYSINCLUDEPATHS="../mes/include:usr/include:{B}/include"' -D CONFIG_USE_LIBGCC=1 -D 'TCC_LIBGCC="/home/janneke/src/tinycc/usr/lib/libc+tcc-gcc.mlibc-o"' -D CONFIG_TCC_STATIC=1 -D ONE_SOURCE=yes -D TCC_TARGET_I386=1 -D BOOTSTRAP=1 tcc.c
time GUILE_LOAD_PATH=/home/janneke/src/nyacc/module:$GUILE_LOAD_PATH MES_ARENA=200000000 ../mes/scripts/mescc -c -o tcc.M1 tcc.E time GUILE_LOAD_PATH=/home/janneke/src/nyacc/module:$GUILE_LOAD_PATH MES_ARENA=200000000 ../mes/scripts/mescc -c -o tcc.M1 tcc.E
** mescc: 64 bit compiled mes loses top 4 bytes
*** 64 bit mescc-compiled mes:
#x100000000 => 0
(modulo 1 #x100000000) => divide-by-zero
*** 64 bit gcc-compiled mes:
#x100000000 => 0
(modulo 1 #x100000000) => 1
** mescc: 7n-struct-struct-array.c: struct file f = {"first.h"}; ** mescc: 7n-struct-struct-array.c: struct file f = {"first.h"};
** test/match.test ("nyacc-simple"): hygiene problem in match ** test/match.test ("nyacc-simple"): hygiene problem in match
* OLD: Booting from LISP-1.5 into Mes * OLD: Booting from LISP-1.5 into Mes

View file

@ -45,6 +45,7 @@
core:write-error core:write-error
core:write-port core:write-port
core:type core:type
%compiler
equal2? equal2?
pmatch-car pmatch-car
pmatch-cdr pmatch-cdr
@ -83,6 +84,8 @@
(define <cell:symbol> 11) (define <cell:symbol> 11)
(define <cell:vector> 15) (define <cell:vector> 15)
(define %compiler "gnuc")
(define (core:type x) (define (core:type x)
(cond ((guile:keyword? x) <cell:keyword>) (cond ((guile:keyword? x) <cell:keyword>)
((guile:number? x) <cell:number>) ((guile:number? x) <cell:number>)

View file

@ -81,13 +81,16 @@
(if hex? (string-append "%0x" (dec->hex o)) (if hex? (string-append "%0x" (dec->hex o))
(string-append "%" (number->string o)))) (string-append "%" (number->string o))))
(define mesc? (string=? %compiler "mesc"))
(define (hex2:immediate8 o) (define (hex2:immediate8 o)
(if hex? (string-append "%0x" (dec->hex (modulo o #x100000000)) ;; FIXME: #x100000000 => 0 divide-by-zero when compiled with 64 bit mesc
(if hex? (string-append "%0x" (dec->hex (if mesc? 0 (modulo o #x100000000)))
" %0x" (if (< o 0) "-1" " %0x" (if (< o 0) "-1"
(dec->hex (quotient o #x100000000)))) (dec->hex (if mesc? o (quotient o #x100000000)))))
(string-append "%" (number->string (dec->hex (modulo o #x100000000))) (string-append "%" (number->string (dec->hex (if mesc? 0 (modulo o #x100000000))))
" %" (if (< o 0) "-1" " %" (if (< o 0) "-1"
(number->string (dec->hex (quotient o #x100000000))))))) (number->string (dec->hex (if mesc? o (quotient o #x100000000))))))))
(define* (display-join o #:optional (sep "")) (define* (display-join o #:optional (sep ""))
(let loop ((o o)) (let loop ((o o))

View file

@ -128,9 +128,12 @@ divide (SCM x) ///((name . "/") (arity . n))
while (x != cell_nil) while (x != cell_nil)
{ {
assert_number ("divide", CAR (x)); assert_number ("divide", CAR (x));
long y = VALUE (CAR (x));
if (y == 0)
error (cstring_to_symbol ("divide-by-zero"), x);
if (!n) if (!n)
break; break;
n /= VALUE (car (x)); n /= y;
x = cdr (x); x = cdr (x);
} }
return MAKE_NUMBER (n); return MAKE_NUMBER (n);
@ -142,9 +145,12 @@ modulo (SCM a, SCM b)
assert_number ("modulo", a); assert_number ("modulo", a);
assert_number ("modulo", b); assert_number ("modulo", b);
long x = VALUE (a); long x = VALUE (a);
long y = VALUE (b);
if (y == 0)
error (cstring_to_symbol ("divide-by-zero"), a);
while (x < 0) while (x < 0)
x += VALUE (b); x += y;
x = x ? x % VALUE (b) : 0; x = x ? x % y : 0;
return MAKE_NUMBER (x); return MAKE_NUMBER (x);
} }