diff options
Diffstat (limited to 'sys/src/cmd/cc/com.c')
| -rw-r--r-- | sys/src/cmd/cc/com.c | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/sys/src/cmd/cc/com.c b/sys/src/cmd/cc/com.c index 5072c8a21..9fcf9861f 100644 --- a/sys/src/cmd/cc/com.c +++ b/sys/src/cmd/cc/com.c @@ -266,12 +266,15 @@ tcomo(Node *n, int f) arith(n, 0); while(n->left->op == OCAST) n->left = n->left->left; - if(!sametype(t, n->type) && !mixedasop(t, n->type)) { - r = new1(OCAST, n->right, Z); - r->type = t; - n->right = r; + if(!mixedasop(t, n->type)) { + if(!sametype(t, n->type)) { + r = new1(OCAST, n->right, Z); + r->type = t; + n->right = r; + n->type = t; + } + }else n->type = t; - } if(typeu[n->type->etype]) { if(n->op == OASMOD) n->op = OASLMOD; @@ -1044,6 +1047,23 @@ loop: case OASADD: ccom(l); ccom(r); + if(n->op == OASMOD || n->op == OASLMOD || n->op == OASDIV || n->op == OASLDIV) + if(r->op == OCONST){ + if(!typefd[r->type->etype] && r->vconst == 0) { + if(n->op == OASMOD || n->op == OASLMOD) + diag(n, "modulo by zero"); + else + diag(n, "divide by zero"); + r->vconst = ~0; + } + if(typefd[r->type->etype] && r->fconst == 0.) { + if(n->op == OASMOD || n->op == OASLMOD) + diag(n, "modulo by zero"); + else + diag(n, "divide by zero"); + r->fconst = 1e10; + } + } if(n->op == OASLSHR || n->op == OASASHR || n->op == OASASHL) if(r->op == OCONST) { t = n->type->width * 8; /* bits per byte */ @@ -1053,6 +1073,8 @@ loop: break; case OCAST: + if(castucom(n)) + warn(n, "32-bit unsigned complement zero-extended to 64 bits"); ccom(l); if(l->op == OCONST) { evconst(n); |
