diff options
| -rw-r--r-- | sys/src/cmd/cc/cc.h | 1 | ||||
| -rw-r--r-- | sys/src/cmd/cc/com.c | 6 | ||||
| -rw-r--r-- | sys/src/cmd/cc/sub.c | 15 |
3 files changed, 20 insertions, 2 deletions
diff --git a/sys/src/cmd/cc/cc.h b/sys/src/cmd/cc/cc.h index 87aceb598..f22cad7e3 100644 --- a/sys/src/cmd/cc/cc.h +++ b/sys/src/cmd/cc/cc.h @@ -691,6 +691,7 @@ Type* copytyp(Type*); void typeext(Type*, Node*); void typeext1(Type*, Node*); int side(Node*); +int zpconst(Node*); int vconst(Node*); int log2(uvlong); int vlog(Node*); diff --git a/sys/src/cmd/cc/com.c b/sys/src/cmd/cc/com.c index 418bbae26..49fcefd1a 100644 --- a/sys/src/cmd/cc/com.c +++ b/sys/src/cmd/cc/com.c @@ -341,11 +341,13 @@ tcomo(Node *n, int f) o |= tcom(r->left); if(o | tcom(r->right)) goto bad; - if(r->right->type->etype == TIND && vconst(r->left) == 0) { + if(r->right->type->etype == TIND && zpconst(r->left)) { + r->type = r->right->type; r->left->type = r->right->type; r->left->vconst = 0; } - if(r->left->type->etype == TIND && vconst(r->right) == 0) { + if(r->left->type->etype == TIND && zpconst(r->right)) { + r->type = r->left->type; r->right->type = r->left->type; r->right->vconst = 0; } diff --git a/sys/src/cmd/cc/sub.c b/sys/src/cmd/cc/sub.c index ee4ab07ce..9be762a0c 100644 --- a/sys/src/cmd/cc/sub.c +++ b/sys/src/cmd/cc/sub.c @@ -1026,6 +1026,21 @@ loop: } int +zpconst(Node *n) +{ + while(n->op == OCAST){ + if(n->type == T) + break; + if(n->type->etype != TIND) + break; + if(n->type->link->etype != TVOID) + break; + n = n->left; + } + return vconst(n) == 0; +} + +int vconst(Node *n) { int i; |
