scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit df9834664bb8d240a37132a3f75fd798b4117fab
parent 8e0d9d84f4f62953f1b3f4e6db6342f7f44bffd9
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 23 Jun 2016 11:19:14 +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.

Diffstat:
cc1/expr.c | 10+++++++++-
cc1/tests/test006.c | 6+++---
cc1/tests/test037.c | 6+++---
3 files changed, 15 insertions(+), 7 deletions(-)

diff --git 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 @@ negop(int op) case OGE: return OLT; case OLE: return OGT; case OGT: return OLE; + default: abort(); } return op; } @@ -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 @@ -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 @@ -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