aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2025-12-20 19:32:13 +0100
committerlemon <lsof@mailbox.org>2025-12-20 19:32:13 +0100
commit9721d6ba4036c325a7bdecbf867927566f78e81e (patch)
treef122f18c10b1a420585cb4e4127cdf05069d1942
parente6fbab42185f4fb4e3a3b1e3e93eaa5d3d81b7c7 (diff)
some static assertions for packed type sizes
-rw-r--r--c/c.h14
-rw-r--r--ir/ir.h2
-rw-r--r--type.h1
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)