Skip to content

Commit

Permalink
cmd/7g: fix unary OMINUS
Browse files Browse the repository at this point in the history
Fixes golang#20

Unary OMINUS was all messed up, so port over the 5g version. In the process the unused uop: label and code was found to be unused.
  • Loading branch information
davecheney committed Dec 17, 2014
1 parent ca565b4 commit 6dfc795
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions src/cmd/7g/cgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,13 @@ cgen(Node *n, Node *res)
goto ret;

case OMINUS:
if(isfloat[nl->type->etype]) {
nr = nodintconst(-1);
convlit(&nr, n->type);
a = optoas(OMUL, nl->type);
goto sbop;
}
a = optoas(n->op, nl->type);
goto uop;
regalloc(&n1, nl->type, N);
cgen(nl, &n1);
nodconst(&n2, nl->type, 0);
gins(optoas(OMINUS, nl->type), &n2, &n1);
gmove(&n1, res);
regfree(&n1);
goto ret;

// symmetric binary
case OAND:
Expand Down Expand Up @@ -544,16 +543,6 @@ cgen(Node *n, Node *res)
regfree(&n1);
if(n2.op != OLITERAL)
regfree(&n2);
goto ret;

uop: // unary
regalloc(&n1, nl->type, res);
cgen(nl, &n1);
gins(a, N, &n1);
gmove(&n1, res);
regfree(&n1);
goto ret;

ret:
;
}
Expand Down

0 comments on commit 6dfc795

Please sign in to comment.