From 509f5618230b10fae31cd00fee1d96d48874b736 Mon Sep 17 00:00:00 2001 From: Michael Matz Date: Mon, 22 Jul 2019 06:45:03 +0200 Subject: [PATCH] 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. --- tccgen.c | 17 ++++++++++------- tests/tcctest.c | 4 ++++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/tccgen.c b/tccgen.c index 4a7080c1..16f3c084 100644 --- a/tccgen.c +++ b/tccgen.c @@ -2867,12 +2867,15 @@ static void gen_cast(CType *type) lexpand(); vpop(); #else - /* XXX some architectures (e.g. risc-v) would like it - better for this merely being a 32-to-64 sign or zero- - extension. */ - vpushi(0xffffffff); - vtop->type.t |= VT_UNSIGNED; - gen_op('&'); + if (dbt & VT_UNSIGNED) { + /* XXX some architectures (e.g. risc-v) would like it + better for this merely being a 32-to-64 sign or zero- + extension. */ + vpushi(0xffffffff); + vtop->type.t |= VT_UNSIGNED; + gen_op('&'); + } else { + } #endif } /* if lvalue and single word type, nothing to do because @@ -5253,7 +5256,7 @@ ST_FUNC void unary(void) vtop->c.f = -1.0 * 0.0; else if (t == VT_DOUBLE) vtop->c.d = -1.0 * 0.0; - else + else vtop->c.ld = -1.0 * 0.0; } else vpushi(0); diff --git a/tests/tcctest.c b/tests/tcctest.c index 5a959c2d..e4645bb5 100644 --- a/tests/tcctest.c +++ b/tests/tcctest.c @@ -1633,6 +1633,7 @@ void cast_test() unsigned b,d; short s; char *p = NULL; + unsigned long ul = 0x80000000UL; p -= 0x700000000042; printf("cast_test:\n"); @@ -1685,6 +1686,9 @@ void cast_test() /* from integers to pointers */ printf("%p %p %p %p\n", (void *)a, (void *)b, (void *)c, (void *)d); + + /* int to int with sign set */ + printf("0x%lx\n", (unsigned long)(int)ul); } /* initializers tests */