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.
Unified · Split
| @@ -2867,12 +2867,15 @@ static void gen_cast(CType *type) · 2866 unmodified lines | ||
| 2867 | 2867 | lexpand(); |
| 2868 | 2868 | vpop(); |
| 2869 | 2869 | #else |
| 2870 | − /* XXX some architectures (e.g. risc-v) would like it | |
| 2871 | − better for this merely being a 32-to-64 sign or zero- | |
| 2872 | − extension. */ | |
| 2873 | − vpushi(0xffffffff); | |
| 2874 | − vtop->type.t |= VT_UNSIGNED; | |
| 2875 | − gen_op('&'); | |
| 2870 | + if (dbt & VT_UNSIGNED) { | |
| 2871 | + /* XXX some architectures (e.g. risc-v) would like it | |
| 2872 | + better for this merely being a 32-to-64 sign or zero- | |
| 2873 | + extension. */ | |
| 2874 | + vpushi(0xffffffff); | |
| 2875 | + vtop->type.t |= VT_UNSIGNED; | |
| 2876 | + gen_op('&'); | |
| 2877 | + } else { | |
| 2878 | + } | |
| 2876 | 2879 | #endif |
| 2877 | 2880 | } |
| 2878 | 2881 | /* if lvalue and single word type, nothing to do because |
| @@ -5253,7 +5256,7 @@ ST_FUNC void unary(void) · 2374 unmodified lines | ||
| 5253 | 5256 | vtop->c.f = -1.0 * 0.0; |
| 5254 | 5257 | else if (t == VT_DOUBLE) |
| 5255 | 5258 | vtop->c.d = -1.0 * 0.0; |
| 5256 | − else | |
| 5259 | + else | |
| 5257 | 5260 | vtop->c.ld = -1.0 * 0.0; |
| 5258 | 5261 | } else |
| 5259 | 5262 | vpushi(0); |
| @@ -1633,6 +1633,7 @@ void cast_test() · 1632 unmodified lines | ||
| 1633 | 1633 | unsigned b,d; |
| 1634 | 1634 | short s; |
| 1635 | 1635 | char *p = NULL; |
| 1636 | + unsigned long ul = 0x80000000UL; | |
| 1636 | 1637 | p -= 0x700000000042; |
| 1637 | 1638 | |
| 1638 | 1639 | printf("cast_test:\n"); |
| @@ -1685,6 +1686,9 @@ void cast_test() · 46 unmodified lines | ||
| 1685 | 1686 | /* from integers to pointers */ |
| 1686 | 1687 | printf("%p %p %p %p\n", |
| 1687 | 1688 | (void *)a, (void *)b, (void *)c, (void *)d); |
| 1689 | + | |
| 1690 | + /* int to int with sign set */ | |
| 1691 | + printf("0x%lx\n", (unsigned long)(int)ul); | |
| 1688 | 1692 | } |
| 1689 | 1693 | |
| 1690 | 1694 | /* initializers tests */ |