ref: a4cb78cee5275f797d66793149a4d642e6c70f0d
parent: b9856b63e76cd86231ac9075d27dcde8231a0aea
author: Roberto E. Vargas Caballero <[email protected]>
date: Fri Oct 10 06:07:36 EDT 2014
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.
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -178,11 +178,13 @@
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 @@
#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);
--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -74,7 +74,7 @@
{
if (!np)
return NULL;
- if (!ISNODECMP(np))
+ if (!ISNODELOG(np))
return np;
return ternarycode(np, symcode(one), symcode(zero));
}