[hackers] [scc] [cc1] Fix negation of OSYM nodes || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Thu, 23 Jun 2016 11:22:08 +0200 (CEST)

commit df9834664bb8d240a37132a3f75fd798b4117fab
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Thu Jun 23 11:19:14 2016 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Thu Jun 23 11:19:14 2016 +0200

    [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.

diff --git a/cc1/expr.c b/cc1/expr.c
index 5c86075..56055ed 100644
--- a/cc1/expr.c
+++ b/cc1/expr.c
_AT_@ -1,4 +1,5 @@
 /* See LICENSE file for copyright and license details. */
+#include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
_AT_@ -416,6 +417,7 @@ negop(int op)
         case OGE: return OLT;
         case OLE: return OGT;
         case OGT: return OLE;
+ default: abort();
         }
         return op;
 }
_AT_@ -423,7 +425,13 @@ negop(int op)
 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;
 }
 
diff --git a/cc1/tests/test006.c b/cc1/tests/test006.c
index da5cdfd..c38bccb 100644
--- a/cc1/tests/test006.c
+++ b/cc1/tests/test006.c
_AT_@ -12,14 +12,14 @@ G1 K "c
 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
diff --git a/cc1/tests/test037.c b/cc1/tests/test037.c
index 953bcf2..f3a9425 100644
--- a/cc1/tests/test037.c
+++ b/cc1/tests/test037.c
_AT_@ -12,13 +12,13 @@ output:
 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
Received on Thu Jun 23 2016 - 11:22:08 CEST

This archive was generated by hypermail 2.3.0 : Thu Jun 23 2016 - 11:24:14 CEST