tccgen: fix long long -> char/short cast
This was causing assembler bugs in a tcc compiled by itself at i386-asm.c:352 when ExprValue.v was changed to uint64_t: if (op->e.v == (int8_t)op->e.v) op->type |= OP_IM8S; A general test case: #include <stdio.h> int main(int argc, char **argv) { long long ll = 4000; int i = (char)ll; printf("%d\n", i); return 0; } Output was "4000", now "-96". Also: add "asmtest2" as asmtest with tcc compiled by itself
This commit is contained in:
parent
f350487e1e
commit
c2ad11ac70
3 changed files with 12 additions and 4 deletions
5
tccgen.c
5
tccgen.c
|
@ -1948,7 +1948,10 @@ static void force_charshort_cast(int t)
|
||||||
vpushi((1 << bits) - 1);
|
vpushi((1 << bits) - 1);
|
||||||
gen_op('&');
|
gen_op('&');
|
||||||
} else {
|
} else {
|
||||||
bits = 32 - bits;
|
if ((vtop->type.t & VT_BTYPE) == VT_LLONG)
|
||||||
|
bits = 64 - bits;
|
||||||
|
else
|
||||||
|
bits = 32 - bits;
|
||||||
vpushi(bits);
|
vpushi(bits);
|
||||||
gen_op(TOK_SHL);
|
gen_op(TOK_SHL);
|
||||||
/* result must be signed or the SAR is converted to an SHL
|
/* result must be signed or the SAR is converted to an SHL
|
||||||
|
|
|
@ -21,7 +21,7 @@ TESTS = \
|
||||||
BTESTS = test1b test3b btest
|
BTESTS = test1b test3b btest
|
||||||
|
|
||||||
# test4 -- problem with -static
|
# test4 -- problem with -static
|
||||||
# asmtest -- minor differences with gcc
|
# asmtest / asmtest2 -- minor differences with gcc
|
||||||
# btest -- works on i386 (including win32)
|
# btest -- works on i386 (including win32)
|
||||||
|
|
||||||
# bounds-checking is supported only on i386
|
# bounds-checking is supported only on i386
|
||||||
|
@ -173,12 +173,15 @@ asmtest.ref: asmtest.S
|
||||||
$(CC) -Wa,-W -o asmtest.ref.o -c asmtest.S
|
$(CC) -Wa,-W -o asmtest.ref.o -c asmtest.S
|
||||||
objdump -D asmtest.ref.o > asmtest.ref
|
objdump -D asmtest.ref.o > asmtest.ref
|
||||||
|
|
||||||
asmtest: asmtest.ref
|
asmtest asmtest2: asmtest.ref
|
||||||
@echo ------------ $@ ------------
|
@echo ------------ $@ ------------
|
||||||
$(TCC) -c asmtest.S
|
$(TCC) $(MAYBE_RUN_TCC) -c asmtest.S
|
||||||
objdump -D asmtest.o > asmtest.out
|
objdump -D asmtest.o > asmtest.out
|
||||||
@if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
|
@if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
|
||||||
|
|
||||||
|
# test assembler with tcc compiled by itself
|
||||||
|
asmtest2: MAYBE_RUN_TCC = $(RUN_TCC)
|
||||||
|
|
||||||
# Check that code generated by libtcc is binary compatible with
|
# Check that code generated by libtcc is binary compatible with
|
||||||
# that generated by CC
|
# that generated by CC
|
||||||
abitest-cc$(EXESUF): abitest.c $(LIBTCC)
|
abitest-cc$(EXESUF): abitest.c $(LIBTCC)
|
||||||
|
|
|
@ -696,6 +696,7 @@ int $0x10
|
||||||
inc %eax
|
inc %eax
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
ft1: ft2: ft3: ft4: ft5: ft6: ft7: ft8: ft9:
|
ft1: ft2: ft3: ft4: ft5: ft6: ft7: ft8: ft9:
|
||||||
xor %eax, %eax
|
xor %eax, %eax
|
||||||
ret
|
ret
|
||||||
|
@ -708,6 +709,7 @@ ft1: ft2: ft3: ft4: ft5: ft6: ft7: ft8: ft9:
|
||||||
.type ft6,@function
|
.type ft6,@function
|
||||||
.type ft7,%function
|
.type ft7,%function
|
||||||
.type ft8,"function"
|
.type ft8,"function"
|
||||||
|
#endif
|
||||||
|
|
||||||
pause
|
pause
|
||||||
.rept 6
|
.rept 6
|
||||||
|
|
Loading…
Reference in a new issue