shithub: mc

Download patch

ref: 2f8d3d7f2e4e3592b0a2fce30a4ec218aafe9bce
parent: 5c0705ccfaeef1fbb08762229fb66a7a977baaba
author: Ori Bernstein <ori@eigenstate.org>
date: Mon May 9 20:18:39 EDT 2016

Align union tag when entering subtype.

--- a/lib/std/test/fmt.myr
+++ b/lib/std/test/fmt.myr
@@ -28,6 +28,10 @@
 	;;
 }
 
+type aligncheck = union
+	`Foo
+	`Bar int64
+;;
 
 const main = {
 	builtins()
@@ -62,6 +66,7 @@
 	check("666.91972", "{}", 666.91972)
 	check("1.0001", "{}", 1.0001)
 	check("0.000101323461002", "{}", 0.000101323461002)
+	check("(1, `Bar 123, `Foo )", "{}", (1, `Bar 123, `Foo))
 
 	/* 
 	compound types, followed by single value to make
--- a/lib/std/varargs.myr
+++ b/lib/std/varargs.myr
@@ -81,8 +81,13 @@
 }
 
 const vaenterunion = {ap, elt
-	var sub
+	var sub, ti, p, align
 
+	ti = typeinfo(tcpeek(&ap.tc))
+	align = ti.align castto(intptr)
+	p = ap.args castto(intptr)
+	p = (p + align - 1) & ~(align - 1)
+	ap.args = p castto(byte#)
 	match typedesc(vatype(ap))
 	| `Tyunion nc:	
 		for var i = 0; i < elt; i++