ref: 05e48648c32fff671b79a615310f4d2bc5136aba
parent: 3d32bf03a7837cf015d44f85383a240a79c3d264
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Thu Jun 23 07:19:14 EDT 2016
[cc1] Fix negation of OSYM nodes Due to fold of constant we can have a OSYM in negate, because comparision between constants will generate a constant integer node. In this case we cannot use negop(), because in this case we do not want to negate OSYM, we want to change the symbol of the node.
--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -1,4 +1,5 @@
/* See LICENSE file for copyright and license details. */
+#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -416,6 +417,7 @@
case OGE: return OLT;
case OLE: return OGT;
case OGT: return OLE;
+ default: abort();
}
return op;
}
@@ -423,7 +425,13 @@
Node *
negate(Node *np)
{
- np->op = negop(np->op);
+ if (np->op == OSYM) {
+ assert(np->flags&NCONST && np->type->prop&TINTEGER);
+ np->sym = (np->sym->u.i) ? zero : one;
+ } else {
+ np->op = negop(np->op);
+ }
+
return np;
}
--- a/cc1/tests/test006.c
+++ b/cc1/tests/test006.c
@@ -12,14 +12,14 @@
G3 I F "main
{
\
- y L4 #I0
+ y L4 #I1
h #I1
j L5
L4
- y L6 #I0
+ y L6 #I1
j L7
L6
- y L8 #I1
+ y L8 #I0
y L9 G1 gI #I0 =I
h #I1
j L10
--- a/cc1/tests/test037.c
+++ b/cc1/tests/test037.c
@@ -12,13 +12,13 @@
G2 I F "main
{
\
- y L3 #I0
+ y L3 #I1
h #I1
L3
- y L4 #I0
+ y L4 #I1
h #I2
L4
- y L5 #I0
+ y L5 #I1
h #I3
L5
h #I0