ref: 19e83e69aa412cea8f41a28506cc9bfcc84525c4
parent: 71d0843d509fd2d0a14717bfc6dd30617a1aaba7
author: Roberto E. Vargas Caballero <[email protected]>
date: Wed Sep 2 10:56:56 EDT 2015
Concentrate all the division by 0 in only one place
--- a/cc1/fold.c
+++ b/cc1/fold.c
@@ -93,11 +93,7 @@
{
struct limits *lim = getlimits(tp);
- if (r == 0) {
- warn("division by 0");
- return 0;
- }
- if (l == lim->min.i && r == -1) {
+ if (r == 0 || l == lim->min.i && r == -1) {
warn("overflow in constant expression");
return 0;
}
@@ -112,11 +108,7 @@
if (l < 0) l = -l;
if (r < 0) r = -r;
- if (r == 0.0) {
- warn("division by 0");
- return 0;
- }
- if (r < 1.0 && l > lim->max.f * r) {
+ if (r == 0.0 || r < 1.0 && l > lim->max.f * r) {
warn("overflow in constant expression");
return 0;
}
@@ -308,8 +300,13 @@
Node *np;
int type;
+ if ((op == ODIV || op == OMOD) && cmpnode(rp, 0)) {
+ warn("division by 0");
+ return NULL;
+ }
if (!lp->constant || rp && !rp->constant)
return NULL;
+
ls = lp->sym;
rs = (rp) ? rp->sym : NULL;
@@ -416,9 +413,9 @@
{
Node *np;
+ commutative(&op, &lp, &rp);
if ((np = fold(op, tp, lp, rp)) != NULL)
return np;
- commutative(&op, &lp, &rp);
if ((np = identity(op, lp, rp)) != NULL)
return np;
return node(op, tp, lp, rp);