From de8673af7c0885201f284ffd8851ece2cde8cb18 Mon Sep 17 00:00:00 2001 From: lemon Date: Sat, 14 Mar 2026 17:39:29 +0100 Subject: eval & fold: handle division overflow for MIN/-1 --- c/eval.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'c') diff --git a/c/eval.c b/c/eval.c index 721401b..8f458da 100644 --- a/c/eval.c +++ b/c/eval.c @@ -1,5 +1,6 @@ #include "c.h" #include "../ir/ir.h" +#include static int targ2hosttype(enum typetag t) @@ -303,6 +304,7 @@ binop(struct expr *ex, enum evalmode mode) lhs->u /= rhs->u; break; case EDIV|S: if (!rhs->i) return 0; + if (lhs->i == LLONG_MIN && rhs->i == -1) break; lhs->i /= rhs->i; break; case EDIV|F: lhs->f /= rhs->f; break; @@ -311,6 +313,7 @@ binop(struct expr *ex, enum evalmode mode) lhs->u %= rhs->u; break; case EREM|S: if (!rhs->i) return 0; + if (lhs->i == LLONG_MIN && rhs->i == -1) lhs->i = 0; lhs->i %= rhs->i; break; -- cgit v1.2.3