Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sys/src/cmd/cc/cc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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*);
Expand Down
6 changes: 4 additions & 2 deletions sys/src/cmd/cc/com.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
15 changes: 15 additions & 0 deletions sys/src/cmd/cc/sub.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down