aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2026-04-14 18:59:28 +0200
committerlemon <lsof@mailbox.org>2026-04-14 18:59:28 +0200
commit93f08f8d3095b8d66712c6bf33977d930a63456f (patch)
treeae00072ea0a391940f142b3262e62c124e8cfeca /src
parent268397ff8a226f2b46290ceb849f7cebbbce9817 (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.
Diffstat (limited to 'src')
-rw-r--r--src/c.c7
1 files 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 */