mirror of
https://github.com/mirror/tinycc.git
synced 2025-01-25 06:00:11 +08:00
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; }
This commit is contained in:
parent
8986bc8af4
commit
ed15cddacd
22
tccgen.c
22
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)
|
||||
|
15
tests/tests2/87_ptr_longlong_arith32.c
Normal file
15
tests/tests2/87_ptr_longlong_arith32.c
Normal file
@ -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;
|
||||
}
|
1
tests/tests2/87_ptr_longlong_arith32.expect
Normal file
1
tests/tests2/87_ptr_longlong_arith32.expect
Normal file
@ -0,0 +1 @@
|
||||
data = "0123-5678"
|
Loading…
Reference in New Issue
Block a user