Skip to content

Commit 6dfc795

Browse files
committed
cmd/7g: fix unary OMINUS
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.
1 parent ca565b4 commit 6dfc795

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

src/cmd/7g/cgen.c

+7-18
Original file line numberDiff line numberDiff line change
@@ -246,14 +246,13 @@ cgen(Node *n, Node *res)
246246
goto ret;
247247

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

258257
// symmetric binary
259258
case OAND:
@@ -544,16 +543,6 @@ cgen(Node *n, Node *res)
544543
regfree(&n1);
545544
if(n2.op != OLITERAL)
546545
regfree(&n2);
547-
goto ret;
548-
549-
uop: // unary
550-
regalloc(&n1, nl->type, res);
551-
cgen(nl, &n1);
552-
gins(a, N, &n1);
553-
gmove(&n1, res);
554-
regfree(&n1);
555-
goto ret;
556-
557546
ret:
558547
;
559548
}

0 commit comments

Comments
 (0)