From c2ad11ac70b9ae2010eb63d5eaf77ede0168ca41 Mon Sep 17 00:00:00 2001 From: grischka Date: Sun, 2 Oct 2016 01:38:22 +0200 Subject: 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 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 --- tccgen.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'tccgen.c') diff --git a/tccgen.c b/tccgen.c index 2376848..398e165 100644 --- a/tccgen.c +++ b/tccgen.c @@ -1948,7 +1948,10 @@ static void force_charshort_cast(int t) vpushi((1 << bits) - 1); gen_op('&'); } else { - bits = 32 - bits; + if ((vtop->type.t & VT_BTYPE) == VT_LLONG) + bits = 64 - bits; + else + bits = 32 - bits; vpushi(bits); gen_op(TOK_SHL); /* result must be signed or the SAR is converted to an SHL -- cgit v1.3.1