History

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".

grischka committed 10 years ago

Commit c2ad11a1 parent f3504873 files · +12 −4Browse files

Unified · Split

3 files
  1. tccgen.c +4 −1
  2. tests/Makefile +6 −3
  3. tests/asmtest.S +2 −0
tccgen.c+4−1
@@ -1948,7 +1948,10 @@ static void force_charshort_cast(int t) · 1947 unmodified lines
1948 vpushi((1 << bits) - 1);1948 vpushi((1 << bits) - 1);
1949 gen_op('&');1949 gen_op('&');
1950 } else {1950 } else {
1951 bits = 32 - bits;1951 if ((vtop->type.t & VT_BTYPE) == VT_LLONG)
1952 bits = 64 - bits;
1953 else
1954 bits = 32 - bits;
1952 vpushi(bits);1955 vpushi(bits);
1953 gen_op(TOK_SHL);1956 gen_op(TOK_SHL);
1954 /* result must be signed or the SAR is converted to an SHL1957 /* result must be signed or the SAR is converted to an SHL
tests/Makefile+6−3
@@ -21,7 +21,7 @@ TESTS = \ · 20 unmodified lines
21BTESTS = test1b test3b btest21BTESTS = test1b test3b btest
22 22
23# test4 -- problem with -static23# test4 -- problem with -static
24# asmtest -- minor differences with gcc24# asmtest / asmtest2 -- minor differences with gcc
25# btest -- works on i386 (including win32)25# btest -- works on i386 (including win32)
26 26
27# bounds-checking is supported only on i38627# bounds-checking is supported only on i386
@@ -173,12 +173,15 @@ asmtest.ref: asmtest.S · 145 unmodified lines
173 $(CC) -Wa,-W -o asmtest.ref.o -c asmtest.S173 $(CC) -Wa,-W -o asmtest.ref.o -c asmtest.S
174 objdump -D asmtest.ref.o > asmtest.ref174 objdump -D asmtest.ref.o > asmtest.ref
175 175
176asmtest: asmtest.ref176asmtest asmtest2: asmtest.ref
177 @echo ------------ $@ ------------177 @echo ------------ $@ ------------
178 $(TCC) -c asmtest.S178 $(TCC) $(MAYBE_RUN_TCC) -c asmtest.S
179 objdump -D asmtest.o > asmtest.out179 objdump -D asmtest.o > asmtest.out
180 @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi180 @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
181 181
182# test assembler with tcc compiled by itself
183asmtest2: MAYBE_RUN_TCC = $(RUN_TCC)
184
182# Check that code generated by libtcc is binary compatible with185# Check that code generated by libtcc is binary compatible with
183# that generated by CC186# that generated by CC
184abitest-cc$(EXESUF): abitest.c $(LIBTCC)187abitest-cc$(EXESUF): abitest.c $(LIBTCC)
tests/asmtest.S+2−0
@@ -696,6 +696,7 @@ int $0x10 · 695 unmodified lines
696 inc %eax696 inc %eax
697#endif697#endif
698 698
699#ifndef _WIN32
699ft1: ft2: ft3: ft4: ft5: ft6: ft7: ft8: ft9:700ft1: ft2: ft3: ft4: ft5: ft6: ft7: ft8: ft9:
700 xor %eax, %eax701 xor %eax, %eax
701 ret702 ret
@@ -708,6 +709,7 @@ ft1: ft2: ft3: ft4: ft5: ft6: ft7: ft8: ft9: · 6 unmodified lines
708.type ft6,@function709.type ft6,@function
709.type ft7,%function710.type ft7,%function
710.type ft8,"function"711.type ft8,"function"
712#endif
711 713
712 pause714 pause
713.rept 6715.rept 6

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t