summaryrefslogtreecommitdiff
path: root/test/align.myr
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2014-06-16 22:45:09 -0400
committerOri Bernstein <ori@eigenstate.org>2014-06-16 22:45:09 -0400
commit994d0ecb8ed4f5f78801669a607dad572c0d93a1 (patch)
tree4ecb7ba48fa35a5f273ff4e19a62b9a655134d3b /test/align.myr
parent4989e1b4e1184e1241c01d7d6f31a073d5a52a20 (diff)
downloadmc-994d0ecb8ed4f5f78801669a607dad572c0d93a1.tar.gz
Fix alignment on structs.
We were aligning big aggregates to 8, instead of to their most strict member. Oops.
Diffstat (limited to 'test/align.myr')
-rw-r--r--test/align.myr64
1 files changed, 64 insertions, 0 deletions
diff --git a/test/align.myr b/test/align.myr
new file mode 100644
index 0000000..975ca75
--- /dev/null
+++ b/test/align.myr
@@ -0,0 +1,64 @@
+use std
+
+/* size should be 16 */
+type alignstruct1 = struct
+ a : byte
+ b : byte[15]
+;;
+
+/* size should be 20 */
+type alignstruct2 = struct
+ a : int
+ b : byte[15]
+ /* 1 byte padding */
+;;
+
+/* size should be 20 */
+type alignstruct3 = struct
+ b : byte[15]
+ a : int
+;;
+
+/* size should be 8 */
+type alignstruct4 = struct
+ a : byte
+ b : int[1]
+;;
+
+/* size should be 24 */
+type alignstruct5 = struct
+ a : byte
+ b : byte[:]
+;;
+
+/* size should be 8 */
+type alignstruct6 = struct
+ a : byte
+ b : byte
+ c : byte
+ d : byte
+ e : int32
+;;
+
+/* size should be 24 */
+type alignstruct7 = struct
+ a : byte
+ b : int32
+ c : byte[:]
+;;
+
+const main = {
+ std.put("size = %i\n", sizeof(alignstruct1))
+ std.put("size = %i\n", sizeof(alignstruct2))
+ std.put("size = %i\n", sizeof(alignstruct3))
+ std.put("size = %i\n", sizeof(alignstruct4))
+ std.put("size = %i\n", sizeof(alignstruct5))
+ std.put("size = %i\n", sizeof(alignstruct6))
+ std.put("size = %i\n", sizeof(alignstruct7))
+ /* size should be 8 */
+ std.put("size = %i\n", sizeof([int, byte, byte]))
+ /* size should be 16 */
+ std.put("size = %i\n", sizeof([int, byte, int, byte]))
+ /* size should be 12 */
+ std.put("size = %i\n", sizeof([int, int, byte, byte]))
+}