summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2012-07-27 01:41:06 -0400
committerOri Bernstein <ori@eigenstate.org>2012-07-27 01:41:06 -0400
commit2756212aee21eceb8290d4191e7b0aaa88f41485 (patch)
treecfb782acb36c30652b7e435870b474cdd77c208c
parent18ad8af1fb596563dcc32e618f46b454efb94f75 (diff)
downloadmc-2756212aee21eceb8290d4191e7b0aaa88f41485.tar.gz
Make widening/truncating casts... work?
-rw-r--r--8/isel.c5
-rw-r--r--8/simp.c1
-rw-r--r--test/swidencast.myr8
-rw-r--r--test/trunccast.myr8
4 files changed, 19 insertions, 3 deletions
diff --git a/8/isel.c b/8/isel.c
index 43fdaa2..3920667 100644
--- a/8/isel.c
+++ b/8/isel.c
@@ -597,12 +597,13 @@ Loc *selexpr(Isel *s, Node *n)
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;
diff --git a/8/simp.c b/8/simp.c
index b1cacbd..986a9e7 100644
--- a/8/simp.c
+++ b/8/simp.c
@@ -705,7 +705,6 @@ static Node *lowercast(Simp *s, Node *n)
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) {
diff --git a/test/swidencast.myr b/test/swidencast.myr
new file mode 100644
index 0000000..a24c116
--- /dev/null
+++ b/test/swidencast.myr
@@ -0,0 +1,8 @@
+const main = {
+ var u : uint8
+ var v : uint32
+
+ u = 99
+ v = u castto(uint32)
+ -> v
+}
diff --git a/test/trunccast.myr b/test/trunccast.myr
new file mode 100644
index 0000000..e49b69a
--- /dev/null
+++ b/test/trunccast.myr
@@ -0,0 +1,8 @@
+const main = {
+ var x : int8
+ var y : int32
+
+ y = 9999
+ x = y castto(int8)
+ -> x % 73
+}