From 93f08f8d3095b8d66712c6bf33977d930a63456f Mon Sep 17 00:00:00 2001 From: lemon Date: Tue, 14 Apr 2026 18:59:28 +0200 Subject: c: fix type of ` /= ` Would wrongly generate `udiv` and fail later in the backend. Should add a IR sanity checks pass to catch e.g. unsigned operations being used with floating point classes. --- src/c.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/c.c b/src/c.c index c6df58f..73a03cb 100644 --- a/src/c.c +++ b/src/c.c @@ -3817,10 +3817,10 @@ compileexpr(Function *fn, const Expr *ex, bool discard) op = Omul; goto Compound; case ESETDIV: - op = isunsigned(ex->ty) ? Oudiv : Odiv; + op = Odiv; goto Compound; case ESETREM: - op = issigned(ex->ty) ? Orem : Ourem; + op = Orem; goto Compound; case ESETAND: op = Oand; @@ -3845,6 +3845,9 @@ compileexpr(Function *fn, const Expr *ex, bool discard) Compound: ty = in_range(ex->t, ESETSHL, ESETSHR) ? mktype(intpromote(ex->ty.t)) : cvtarith(sub[0].ty, sub[1].ty); + if (isunsigned(ty) && in_range(op, Odiv, Orem)) { + op = op - Odiv + Oudiv; + } r = exprvalue(fn, &sub[1]); if (sub[0].t == EGETF && (bitsiz = sub[0].fld.bitsiz)) { /* bit-field */ -- cgit v1.2.3