From 9721d6ba4036c325a7bdecbf867927566f78e81e Mon Sep 17 00:00:00 2001 From: lemon Date: Sat, 20 Dec 2025 19:32:13 +0100 Subject: some static assertions for packed type sizes --- c/c.h | 14 ++++++++------ ir/ir.h | 2 ++ type.h | 1 + 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/c/c.h b/c/c.h index 787db5d..45ce509 100644 --- a/c/c.h +++ b/c/c.h @@ -25,16 +25,18 @@ enum exprkind { struct expr { uchar t; uchar qual; - ushort narg; /* ECALL */ union type ty; struct span span; union { struct { - struct expr *sub; - struct exgetfld { - ushort off; - uchar bitsiz, bitoff; - } fld; /* EGETF */ + struct expr *sub; /* child(ren) */ + union { + struct exgetfld { + ushort off; + uchar bitsiz, bitoff; + } fld; /* EGETF */ + ushort narg; /* ECALL */ + }; }; uvlong u; vlong i; double f; /* ENUMLIT */ struct { diff --git a/ir/ir.h b/ir/ir.h index 6e8ae88..b47965d 100644 --- a/ir/ir.h +++ b/ir/ir.h @@ -68,6 +68,7 @@ union ref { struct { unsigned t : 3; signed i : 29; }; uint bits; }; +static_assert(sizeof(union ref) == 4); struct addr { union ref base, index; @@ -115,6 +116,7 @@ struct instr { uchar reg; /* 0 -> no reg; else reg + 1 */ union ref l, r; /* args */ }; +static_assert(sizeof(struct instr) == 4*3); enum jumpkind { JXXX, Jb, Jret, Jtrap, }; diff --git a/type.h b/type.h index c3dffb7..6647e70 100644 --- a/type.h +++ b/type.h @@ -44,6 +44,7 @@ union type { }; uint bits; }; +static_assert(sizeof(union type) == 4); #define isprimt(t) in_range((t), TYBOOL, TYVOID) #define isintt(t) in_range((t), TYENUM, TYUVLONG) -- cgit v1.2.3