commit dd90c975dcfd14bc186b498f92c69df2b7b04121
Author:     Roberto E. Vargas Caballero <[email protected]>
AuthorDate: Sat Feb 4 22:40:04 2017 +0100
Commit:     Roberto E. Vargas Caballero <[email protected]>
CommitDate: Sat Feb 4 22:40:04 2017 +0100

    [cc1] Fix compilation after 7c9e9d84
    
    Negate() was used in stmt.c, but a better solution was to pass
    a parameter to condexpr() instead of having negate().

diff --git a/cc1/cc1.h b/cc1/cc1.h
index 3052c10..705e0b9 100644
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -426,7 +426,7 @@ extern TUINT ones(int nbytes);
 /* expr.c */
 extern Node *decay(Node *), *negate(Node *np), *assign(void);
 extern Node *convert(Node *np, Type *tp1, char iscast);
-extern Node *constexpr(void), *condexpr(void), *expr(void);
+extern Node *constexpr(void), *condexpr(int neg), *expr(void);
 extern int isnodecmp(int op);
 extern int negop(int op);
 extern int cmpnode(Node *np, TUINT val);
diff --git a/cc1/expr.c b/cc1/expr.c
index 1d8925a..6744511 100644
--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -419,7 +419,7 @@ exp2cond(Node *np, int neg)
        case ONEG:
        case OOR:
        case OAND:
-               return node(ONEG, inttype, np, NULL);
+               return (neg) ? node(ONEG, inttype, np, NULL) : np;
        case OEQ:
        case ONE:
        case OLT:
@@ -1128,11 +1128,11 @@ expr(void)
 }
 
 Node *
-condexpr(void)
+condexpr(int neg)
 {
        Node *np;
 
-       np = exp2cond(xexpr(), 0);
+       np = exp2cond(xexpr(), neg);
        if (np->flags & NCONST)
                warn("conditional expression is constant");
        return simplify(np);
diff --git a/cc1/stmt.c b/cc1/stmt.c
index 3abee59..dc778d0 100644
--- a/cc1/stmt.c
+++ b/cc1/stmt.c
@@ -8,6 +8,9 @@ static char sccsid[] = "@(#) ./cc1/stmt.c";
 #include "../inc/cc.h"
 #include "cc1.h"
 
+#define NEGATE   1
+#define NONEGATE 0
+
 Symbol *curfun;
 
 static void stmt(Symbol *lbreak, Symbol *lcont, Switch *lswitch);
@@ -55,12 +58,12 @@ stmtexp(Symbol *lbreak, Symbol *lcont, Switch *lswitch)
 }
 
 static Node *
-condition(void)
+condition(int neg)
 {
        Node *np;
 
        expect('(');
-       np = condexpr();
+       np = condexpr(neg);
        expect(')');
 
        return np;
@@ -77,7 +80,7 @@ While(Symbol *lbreak, Symbol *lcont, Switch *lswitch)
        lbreak = newlabel();
 
        expect(WHILE);
-       np = condition();
+       np = condition(NONEGATE);
 
        emit(OJUMP, lcont);
 
@@ -120,7 +123,7 @@ For(Symbol *lbreak, Symbol *lcont, Switch *lswitch)
                expect(';');
                break;
        }
-       econd = (yytoken != ';') ? condexpr() : NULL;
+       econd = (yytoken != ';') ? condexpr(NONEGATE) : NULL;
        expect(';');
        einc = (yytoken != ')') ? expr() : NULL;
        expect(')');
@@ -158,7 +161,7 @@ Dowhile(Symbol *lbreak, Symbol *lcont, Switch *lswitch)
        emit(OLABEL, begin);
        stmt(lbreak, lcont, lswitch);
        expect(WHILE);
-       np = condition();
+       np = condition(NONEGATE);
        emit(OLABEL, lcont);
        emit(OBRANCH, begin);
        emit(OEXPR, np);
@@ -305,9 +308,9 @@ If(Symbol *lbreak, Symbol *lcont, Switch *lswitch)
 
        lelse = newlabel();
        expect(IF);
-       np = condition();
+       np = condition(NEGATE);
        emit(OBRANCH, lelse);
-       emit(OEXPR, negate(np));
+       emit(OEXPR, np);
        stmt(lbreak, lcont, lswitch);
        if (accept(ELSE)) {
                end = newlabel();

Reply via email to