ref: 814d466b8deea3209cb4178a3862eb803defca72
parent: 9e7035dc20b95a41672e56d086569988c8130975
author: Roberto E. Vargas Caballero <[email protected]>
date: Thu Apr 24 14:19:16 EDT 2014
Negate condition in if jump Without this jump the if semantic was the inverse of the correct, because it was jumping to the label if the condition was correct.
--- a/cc1.h
+++ b/cc1.h
@@ -248,6 +248,8 @@
#define SYM(s) ((union unode) {.sym = s})
#define OP(s) ((union unode) {.op = s})
#define TYP(s) ((union unode) {.type = s})
+#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)
--- a/expr.c
+++ b/expr.c
@@ -267,7 +267,7 @@
exp2cond(Node *np, char neg)
{
if (ISNODECMP(np)) {
- np->u.op ^= neg;
+ NEGATE(np, neg);
return np;
}
--- a/stmt.c
+++ b/stmt.c
@@ -264,10 +264,12 @@
If(Symbol *lbreak, Symbol *lcont, Caselist *lswitch)
{
Symbol *end = label(NULL, 1);
+ Node *np;
expect(IF);
- /* TODO: negate the condition */
- emitjump(end, condition());
+ np = condition();
+ NEGATE(np, 1);
+ emitjump(end, np);
stmt(lbreak, lcont, lswitch);
if (accept(ELSE)) {
emitlabel(end);