scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit a4cb78cee5275f797d66793149a4d642e6c70f0d
parent b9856b63e76cd86231ac9075d27dcde8231a0aea
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 10 Oct 2014 10:07:36 +0200

Fix negation of logical expressions

When we found a comparision expression in the body of a negation, then
the signess of the negation is interchanged, but the code was wrong
and it was also done in logical operators, without applying De Morgan
rules.

Diffstat:
Mcc1/cc1.h | 7+++++--
Mcc1/expr.c | 2+-
2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/cc1/cc1.h b/cc1/cc1.h @@ -178,11 +178,13 @@ enum { OA_MOD, OA_ADD, OA_SUB, OA_SHL, OA_SHR, OA_AND, OA_XOR, OA_OR, OADDR,ONEG, OCPL, OEXC, OCOMMA, + /* TODO: This order is important, but must be changed */ + OAND, OOR, /* * Complementary relational operators only differ in less * significant bit */ - OEQ = 0x40, ONE, OLT, OGE, OLE, OGT, OAND, OOR + OEQ = 0x40, ONE, OLT, OGE, OLE, OGT }; extern void @@ -210,7 +212,8 @@ extern Node #define NEGATE(n, v) ((n)->u.op ^= (v)) /* TODO: remove some of these ugly macros */ #define ISNODEBIN(n) ((n)->code == emitbin) -#define ISNODECMP(n) (ISNODEBIN(n) && (n)->u.op & 0x40) +#define ISNODECMP(n) (ISNODEBIN(n) && (n)->u.op >= OEQ) +#define ISNODELOG(n) (ISNODEBIN(n) && (n)->u.op >= OAND) extern Node *expr(void); extern void extdecl(void), decl(void); diff --git a/cc1/expr.c b/cc1/expr.c @@ -74,7 +74,7 @@ eval(Node *np) { if (!np) return NULL; - if (!ISNODECMP(np)) + if (!ISNODELOG(np)) return np; return ternarycode(np, symcode(one), symcode(zero)); }