History

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.

Michael Matz committed 7 years ago

Commit 509f5611 parent 1ada3292 files · +14 −7Browse files

Unified · Split

2 files
  1. tccgen.c +10 −7
  2. tests/tcctest.c +4 −0
tccgen.c+10−7
@@ -2867,12 +2867,15 @@ static void gen_cast(CType *type) · 2866 unmodified lines
28672867 lexpand();
28682868 vpop();
28692869 #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+ }
28762879 #endif
28772880 }
28782881 /* if lvalue and single word type, nothing to do because
@@ -5253,7 +5256,7 @@ ST_FUNC void unary(void) · 2374 unmodified lines
52535256 vtop->c.f = -1.0 * 0.0;
52545257 else if (t == VT_DOUBLE)
52555258 vtop->c.d = -1.0 * 0.0;
5256− else
5259+ else
52575260 vtop->c.ld = -1.0 * 0.0;
52585261 } else
52595262 vpushi(0);
tests/tcctest.c+4−0
@@ -1633,6 +1633,7 @@ void cast_test() · 1632 unmodified lines
16331633 unsigned b,d;
16341634 short s;
16351635 char *p = NULL;
1636+ unsigned long ul = 0x80000000UL;
16361637 p -= 0x700000000042;
16371638
16381639 printf("cast_test:\n");
@@ -1685,6 +1686,9 @@ void cast_test() · 46 unmodified lines
16851686 /* from integers to pointers */
16861687 printf("%p %p %p %p\n",
16871688 (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);
16881692 }
16891693
16901694 /* initializers tests */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t