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) diff --git a/tests/tests2/87_ptr_longlong_arith32.c b/tests/tests2/87_ptr_longlong_arith32.c new file mode 100644 index 0000000..bf07915 --- /dev/null +++ b/tests/tests2/87_ptr_longlong_arith32.c @@ -0,0 +1,15 @@ +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; +} diff --git a/tests/tests2/87_ptr_longlong_arith32.expect b/tests/tests2/87_ptr_longlong_arith32.expect new file mode 100644 index 0000000..f91e4b4 --- /dev/null +++ b/tests/tests2/87_ptr_longlong_arith32.expect @@ -0,0 +1 @@ +data = "0123-5678"