shithub: mc

Download patch

ref: a4bcc9067518182c6de7d335c7adc1b4cc2bfb90
parent: d42f32137f5a59e229b6b0e086e9b2502f5c729d
author: Ori Bernstein <ori@eigenstate.org>
date: Mon Sep 14 10:44:10 EDT 2015

Fix alignment of function args.

--- a/6/isel.c
+++ b/6/isel.c
@@ -555,13 +555,13 @@
     vararg = 0;
     for (i = 1; i < n->expr.nargs; i++) {
         arg = selexpr(s, n->expr.args[i]);
-        argoff = align(argoff, min(size(n->expr.args[i]), Ptrsz));
+        argoff = alignto(argoff, exprtype(n->expr.args[i]));
         if (i > nargs)
             vararg = 1;
         if (stacknode(n->expr.args[i])) {
             src = locreg(ModeQ);
             g(s, Ilea, arg, src, NULL);
-            a = alignto(1, n->expr.args[i]->expr.type);
+            a = tyalign(exprtype(n->expr.args[i]));
             blit(s, rsp, src, argoff, 0, size(n->expr.args[i]), a);
             argoff += size(n->expr.args[i]);
         } else if (!vararg && isfloatmode(arg->mode) && nfloats < Nfloatregargs) {
--- a/6/typeinfo.c
+++ b/6/typeinfo.c
@@ -327,7 +327,7 @@
         default:
             align = tysize(ty);
     }
-    return align;
+    return min(align, Ptrsz);
 }
 
 /* gets the byte offset of 'memb' within the aggregate type 'aggr' */
--- a/lib/std/test/fmt.myr
+++ b/lib/std/test/fmt.myr
@@ -71,6 +71,8 @@
 
 	/* multiple values */
 	check("formatted a pair: [-10, -10], formatted a pair: [-10, -10]", "{}, {}", p, p)
+	/* multiple values of different types */
+	check("11, formatted a pair: [-10, -10], formatted an int: 111", "{}, {}, {}", 11 castto(byte), p, 111)
 
 }
 
--- a/lib/std/varargs.myr
+++ b/lib/std/varargs.myr
@@ -78,7 +78,6 @@
 }
 
 generic vanext = {ap -> @a
-	var v : @a
 	var ti
 	var align
 	var p
@@ -90,11 +89,9 @@
 	p = ap.args castto(intptr)
 	p = (p + align - 1) & ~(align - 1)
 
-	v = (p castto(@a#))#
-
 	/* TODO: check for type mismatch */
 	tcnext(&ap.tc)
 	/* only move on after we read through the value */
 	ap.args = ((p castto(intptr)) + sizeof(@a)) castto(byte#)
-	-> v
+	-> (p castto(@a#))#
 }