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
19481948 vpushi((1 << bits) - 1);
19491949 gen_op('&');
19501950 } else {
1951− bits = 32 - bits;
1951+ if ((vtop->type.t & VT_BTYPE) == VT_LLONG)
1952+ bits = 64 - bits;
1953+ else
1954+ bits = 32 - bits;
19521955 vpushi(bits);
19531956 gen_op(TOK_SHL);
19541957 /* result must be signed or the SAR is converted to an SHL
tests/Makefile+6−3
@@ -21,7 +21,7 @@ TESTS = \ · 20 unmodified lines
2121 BTESTS = test1b test3b btest
2222
2323 # test4 -- problem with -static
24−# asmtest -- minor differences with gcc
24+# asmtest / asmtest2 -- minor differences with gcc
2525 # btest -- works on i386 (including win32)
2626
2727 # bounds-checking is supported only on i386
@@ -173,12 +173,15 @@ asmtest.ref: asmtest.S · 145 unmodified lines
173173 $(CC) -Wa,-W -o asmtest.ref.o -c asmtest.S
174174 objdump -D asmtest.ref.o > asmtest.ref
175175
176−asmtest: asmtest.ref
176+asmtest asmtest2: asmtest.ref
177177 @echo ------------ $@ ------------
178− $(TCC) -c asmtest.S
178+ $(TCC) $(MAYBE_RUN_TCC) -c asmtest.S
179179 objdump -D asmtest.o > asmtest.out
180180 @if diff -u --ignore-matching-lines="file format" asmtest.ref asmtest.out ; then echo "ASM Auto Test OK"; fi
181181
182+# test assembler with tcc compiled by itself
183+asmtest2: MAYBE_RUN_TCC = $(RUN_TCC)
184+
182185 # Check that code generated by libtcc is binary compatible with
183186 # that generated by CC
184187 abitest-cc$(EXESUF): abitest.c $(LIBTCC)
tests/asmtest.S+2−0
@@ -696,6 +696,7 @@ int $0x10 · 695 unmodified lines
696696 inc %eax
697697 #endif
698698
699+#ifndef _WIN32
699700 ft1: ft2: ft3: ft4: ft5: ft6: ft7: ft8: ft9:
700701 xor %eax, %eax
701702 ret
@@ -708,6 +709,7 @@ ft1: ft2: ft3: ft4: ft5: ft6: ft7: ft8: ft9: · 6 unmodified lines
708709 .type ft6,@function
709710 .type ft7,%function
710711 .type ft8,"function"
712+#endif
711713
712714 pause
713715 .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