aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2025-10-23 17:48:22 +0200
committerlemon <lsof@mailbox.org>2025-10-23 17:49:47 +0200
commitd5f154ed760d0929530fdce5409d5772a708ea05 (patch)
treebc5b9742cda8016173ab539813f48e522ef264b1
parent1182280d291467f21052050ae9131810f8889635 (diff)
c: make builtin va_list an opaque struct
-rw-r--r--c/c.c10
-rw-r--r--common.h4
-rw-r--r--io.c1
-rw-r--r--targ.c5
4 files changed, 14 insertions, 6 deletions
diff --git a/c/c.c b/c/c.c
index 2983018..5bfee6e 100644
--- a/c/c.c
+++ b/c/c.c
@@ -3995,11 +3995,19 @@ function(struct comp *cm, struct function *fn, const char **pnames, const struct
void
docomp(struct comp *cm)
{
+ static union type valistty;
struct token tk[1];
if (!cm->env) cm->env = &toplevel;
- putdecl(cm, &(struct decl) { mktype(TYVALIST), SCTYPEDEF, .name = intern("__builtin_va_list") });
+ if (!valistty.t) {
+ struct typedata td = {
+ .t = TYSTRUCT, .siz = targ_valistsize, .align = targ_primalign[TYPTR], .nmemb = 1,
+ .fld = (struct namedfield [1]){{"?"}}
+ };
+ valistty = mktagtype(intern("__builtin_va_list"), &td);
+ }
+ putdecl(cm, &(struct decl) { valistty, SCTYPEDEF, .name = intern("__builtin_va_list") });
while (peek(cm, tk) != TKEOF) {
struct declstate st = { DTOPLEVEL };
diff --git a/common.h b/common.h
index 9c9fd70..a4b82cc 100644
--- a/common.h
+++ b/common.h
@@ -160,7 +160,6 @@ enum typetag { /* ordering is important here! */
TYBOOL, TYCHAR, TYSCHAR, TYUCHAR, TYSHORT, TYUSHORT, TYINT, TYUINT, TYLONG, TYULONG, TYVLONG, TYUVLONG,
TYFLOAT, TYDOUBLE, TYLDOUBLE,
TYVOID,
- TYVALIST,
TYPTR, TYARRAY, TYFUNC,
TYSTRUCT, TYUNION,
NTYPETAG,
@@ -193,7 +192,7 @@ union type {
uint bits;
};
-#define isprimt(t) in_range((t), TYBOOL, TYVALIST)
+#define isprimt(t) in_range((t), TYBOOL, TYVOID)
#define isintt(t) in_range((t), TYENUM, TYUVLONG)
#define issignedt(t) ((TYSIGNEDSET_ | targ_charsigned << TYCHAR) >> (t) & 1)
#define isunsignedt(t) ((TYUNSIGNEDSET_ | !targ_charsigned << TYCHAR) >> (t) & 1)
@@ -335,6 +334,7 @@ typearrlen(union type t)
/* TARGET */
/**********/
+extern uint targ_valistsize;
extern uchar targ_primsizes[];
extern uchar targ_primalign[];
extern enum typetag targ_sizetype, targ_ptrdifftype, targ_wchartype;
diff --git a/io.c b/io.c
index 53cb6af..77380c3 100644
--- a/io.c
+++ b/io.c
@@ -210,7 +210,6 @@ pritypebefore(struct wbuf *buf, union type ty, int qual)
case TYFLOAT: s = "float"; goto Prim;
case TYDOUBLE: s = "double"; goto Prim;
case TYLDOUBLE:s = "long double"; goto Prim;
- case TYVALIST: s = "va_list"; goto Prim;
case TYPTR:
chld = typechild(ty);
n = pritypebefore(buf, chld, ty.flag & TFCHLDQUAL);
diff --git a/targ.c b/targ.c
index c30886d..b394a9a 100644
--- a/targ.c
+++ b/targ.c
@@ -15,6 +15,7 @@ static const struct targ {
uchar targ_primsizes[TYPTR+1];
uchar targ_primalign[TYPTR+1];
+uint targ_valistsize;
enum typetag targ_sizetype, targ_ptrdifftype, targ_wchartype;
bool targ_charsigned, targ_bigendian, targ_64bit;
const struct mctarg *mctarg;
@@ -35,12 +36,12 @@ targ_init(const char *starg)
sizes[TYULONG] = sizes[TYLONG] = t->longsize;
sizes[TYUVLONG] = sizes[TYVLONG] = t->vlongsize;
sizes[TYPTR] = t->ptrsize;
- sizes[TYVALIST] = t->valistsize;
align[TYULONG] = align[TYLONG] = t->longalign;
align[TYUVLONG] = align[TYVLONG] = t->vlongalign;
align[TYDOUBLE] = t->doublealign;
align[TYLDOUBLE] = t->doublealign;
- align[TYVALIST] = align[TYPTR] = t->ptralign;
+ align[TYPTR] = t->ptralign;
+ targ_valistsize = t->valistsize;
targ_sizetype = t->sizetype;
targ_ptrdifftype = t->ptrdifftype;
targ_wchartype = t->wchartype;