shithub: mc

Download patch

ref: 2756212aee21eceb8290d4191e7b0aaa88f41485
parent: 18ad8af1fb596563dcc32e618f46b454efb94f75
author: Ori Bernstein <[email protected]>
date: Thu Jul 26 21:41:06 EDT 2012

Make widening/truncating casts... work?

--- a/8/isel.c
+++ b/8/isel.c
@@ -597,12 +597,13 @@
         case Ozwiden:
             a = selexpr(s, args[0]);
             b = locreg(mode(n));
-            g(s, Imovz, b, a, NULL);
+            g(s, Imovz, a, b, NULL);
             r = b;
+            break;
         case Oswiden:
             a = selexpr(s, args[0]);
             b = locreg(mode(n));
-            g(s, Imovs, b, a, NULL);
+            g(s, Imovs, a, b, NULL);
             r = b;
             break;
 
--- a/8/simp.c
+++ b/8/simp.c
@@ -705,7 +705,6 @@
                     fromsz = size(args[0]);
                     tosz = size(n);
                     r = rval(s, args[0], NULL);
-                    r->expr.type = n->expr.type;
                     if (fromsz > tosz) {
                         r = mkexpr(n->line, Otrunc, r, NULL);
                     } else if (tosz > fromsz) {
--- /dev/null
+++ b/test/swidencast.myr
@@ -1,0 +1,8 @@
+const main = {
+	var u : uint8
+	var v : uint32
+	
+	u = 99
+	v = u castto(uint32)
+	-> v
+}
--- /dev/null
+++ b/test/trunccast.myr
@@ -1,0 +1,8 @@
+const main = {
+	var x : int8
+	var y : int32
+
+	y = 9999
+	x = y castto(int8)
+	-> x % 73
+}