riscv: fix more sign/zero-extension problems
see the testcase. For the signed case this problably does the wrong thing, and it should break other archs. Rework once there are testcases for this.
This commit is contained in:
parent
1ada32900b
commit
509f561823
2 changed files with 14 additions and 7 deletions
3
tccgen.c
3
tccgen.c
|
@ -2867,12 +2867,15 @@ static void gen_cast(CType *type)
|
||||||
lexpand();
|
lexpand();
|
||||||
vpop();
|
vpop();
|
||||||
#else
|
#else
|
||||||
|
if (dbt & VT_UNSIGNED) {
|
||||||
/* XXX some architectures (e.g. risc-v) would like it
|
/* XXX some architectures (e.g. risc-v) would like it
|
||||||
better for this merely being a 32-to-64 sign or zero-
|
better for this merely being a 32-to-64 sign or zero-
|
||||||
extension. */
|
extension. */
|
||||||
vpushi(0xffffffff);
|
vpushi(0xffffffff);
|
||||||
vtop->type.t |= VT_UNSIGNED;
|
vtop->type.t |= VT_UNSIGNED;
|
||||||
gen_op('&');
|
gen_op('&');
|
||||||
|
} else {
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
/* if lvalue and single word type, nothing to do because
|
/* if lvalue and single word type, nothing to do because
|
||||||
|
|
|
@ -1633,6 +1633,7 @@ void cast_test()
|
||||||
unsigned b,d;
|
unsigned b,d;
|
||||||
short s;
|
short s;
|
||||||
char *p = NULL;
|
char *p = NULL;
|
||||||
|
unsigned long ul = 0x80000000UL;
|
||||||
p -= 0x700000000042;
|
p -= 0x700000000042;
|
||||||
|
|
||||||
printf("cast_test:\n");
|
printf("cast_test:\n");
|
||||||
|
@ -1685,6 +1686,9 @@ void cast_test()
|
||||||
/* from integers to pointers */
|
/* from integers to pointers */
|
||||||
printf("%p %p %p %p\n",
|
printf("%p %p %p %p\n",
|
||||||
(void *)a, (void *)b, (void *)c, (void *)d);
|
(void *)a, (void *)b, (void *)c, (void *)d);
|
||||||
|
|
||||||
|
/* int to int with sign set */
|
||||||
|
printf("0x%lx\n", (unsigned long)(int)ul);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* initializers tests */
|
/* initializers tests */
|
||||||
|
|
Loading…
Reference in a new issue