diff options
| author | 2026-03-14 17:39:29 +0100 | |
|---|---|---|
| committer | 2026-03-14 17:46:57 +0100 | |
| commit | de8673af7c0885201f284ffd8851ece2cde8cb18 (patch) | |
| tree | 162475f18ce772b3038250f6422b7626a1d75815 /c/eval.c | |
| parent | 1400850e7f579d2c0aa2bf2dddffc4e05d87a804 (diff) | |
eval & fold: handle division overflow for MIN/-1
Diffstat (limited to 'c/eval.c')
| -rw-r--r-- | c/eval.c | 3 |
1 files changed, 3 insertions, 0 deletions
@@ -1,5 +1,6 @@ #include "c.h" #include "../ir/ir.h" +#include <limits.h> 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; |