diff options
| author | 2026-04-14 18:59:28 +0200 | |
|---|---|---|
| committer | 2026-04-14 18:59:28 +0200 | |
| commit | 93f08f8d3095b8d66712c6bf33977d930a63456f (patch) | |
| tree | ae00072ea0a391940f142b3262e62c124e8cfeca | |
| parent | 268397ff8a226f2b46290ceb849f7cebbbce9817 (diff) | |
c: fix type of `<unsigned> /= <float>`
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.
| -rw-r--r-- | src/c.c | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -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 */ |