diff --git a/sys/src/cmd/cc/cc.h b/sys/src/cmd/cc/cc.h index 8445a868..a7d5c59d 100644 --- a/sys/src/cmd/cc/cc.h +++ b/sys/src/cmd/cc/cc.h @@ -694,6 +694,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 fab1ba63..996d96c9 100644 --- a/sys/src/cmd/cc/com.c +++ b/sys/src/cmd/cc/com.c @@ -331,11 +331,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 e5a5cf44..5190c17e 100644 --- a/sys/src/cmd/cc/sub.c +++ b/sys/src/cmd/cc/sub.c @@ -987,6 +987,21 @@ side(Node *n) return 1; } +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) {