From ed15cddacd145c74e4600af50f6616ba59ca0d8d Mon Sep 17 00:00:00 2001 From: grischka Date: Thu, 13 Oct 2016 19:21:43 +0200 Subject: tccgen: 32bits: fix PTR +/- long long Previously in order to perform a ll+ll operation tcc was trying to 'lexpand' PTR in gen_opl which did not work well. The case: int printf(const char *, ...); char t[] = "012345678"; int main(void) { char *data = t; unsigned long long r = 4; unsigned a = 5; unsigned long long b = 12; *(unsigned*)(data + r) += a - b; printf("data %s\n", data); return 0; } --- tccgen.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tccgen.c') diff --git a/tccgen.c b/tccgen.c index ba5c23e..5d1bbc0 100644 --- a/tccgen.c +++ b/tccgen.c @@ -133,6 +133,21 @@ ST_FUNC void check_vstack(void) tcc_error("internal compiler error: vstack leak (%d)", vtop - pvtop); } +/* ------------------------------------------------------------------------- */ +/* vstack debugging aid */ + +#if 0 +void pv (const char *lbl, int a, int b) +{ + int i; + for (i = a; i < a + b; ++i) { + SValue *p = &vtop[-i]; + printf("%s vtop[-%d] : type.t:%04x r:%04x r2:%04x c.i:%d\n", + lbl, i, p->type.t, p->r, p->r2, (int)p->c.i); + } +} +#endif + /* ------------------------------------------------------------------------- */ /* symbol allocator */ static Sym *__sym_malloc(void) @@ -1212,6 +1227,7 @@ static void gen_opl(int op) case '*': case '+': case '-': + //pv("gen_opl A",0,2); t = vtop->type.t; vswap(); lexpand(); @@ -1226,6 +1242,7 @@ static void gen_opl(int op) vtop[-3] = tmp; vswap(); /* stack: H1 H2 L1 L2 */ + //pv("gen_opl B",0,4); if (op == '*') { vpushv(vtop - 1); vpushv(vtop - 1); @@ -1760,6 +1777,11 @@ ST_FUNC void gen_op(int op) vswap(); swap(&t1, &t2); } +#if PTR_SIZE == 4 + if ((vtop[0].type.t & VT_BTYPE) == VT_LLONG) + /* XXX: truncate here because gen_opl can't handle ptr + long long */ + gen_cast(&int_type); +#endif type1 = vtop[-1].type; type1.t &= ~VT_ARRAY; if (vtop[-1].type.t & VT_VLA) -- cgit v1.3.1