From f3391dde28a8ab2a6652cd43c7f58cafa04a5861 Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Mon, 18 Oct 2021 10:49:24 -0700 Subject: expr: Make sure __builtin_va_end argument is evaluated for side-effects --- expr.c | 3 +-- qbe.c | 3 --- test/varargs+riscv64.qbe | 6 ++++-- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/expr.c b/expr.c index 19dd012..0da1d43 100644 --- a/expr.c +++ b/expr.c @@ -668,8 +668,7 @@ builtinfunc(struct scope *s, enum builtinkind kind) e = assignexpr(s); if (!typesame(e->type, typeadjvalist)) error(&tok.loc, "va_end argument must have type va_list"); - e = mkexpr(EXPRBUILTIN, &typevoid, NULL); - e->builtin.kind = BUILTINVAEND; + e = exprconvert(e, &typevoid); break; case BUILTINVASTART: e = mkexpr(EXPRBUILTIN, &typevoid, assignexpr(s)); diff --git a/qbe.c b/qbe.c index d40029a..f9a6f08 100644 --- a/qbe.c +++ b/qbe.c @@ -937,9 +937,6 @@ funcexpr(struct func *f, struct expr *e) error(&tok.loc, "va_arg with non-scalar type is not yet supported"); l = funcexpr(f, e->base); return funcinst(f, IVAARG, qbetype(e->type).base, l, NULL); - case BUILTINVAEND: - /* no-op */ - break; case BUILTINALLOCA: l = funcexpr(f, e->base); return funcinst(f, IALLOC16, ptrclass, l, NULL); diff --git a/test/varargs+riscv64.qbe b/test/varargs+riscv64.qbe index a918014..48638bb 100644 --- a/test/varargs+riscv64.qbe +++ b/test/varargs+riscv64.qbe @@ -22,8 +22,9 @@ function w $f2(w %.1, ...) { %.6 =l loadl %.4 %.7 =w call $f1(w %.5, l %.6) storew %.7, %.3 - %.8 =w loadw %.3 - ret %.8 + %.8 =l loadl %.4 + %.9 =w loadw %.3 + ret %.9 } export function $f3(w %.1, ...) { @@ -45,5 +46,6 @@ function $f3(w %.1, ...) { storew %.9, %.2 jmp @while_cond.7 @while_join.9 + %.10 =l loadl %.3 ret } -- cgit v1.2.3