shithub: scc

Download patch

ref: 335eb0c1602243c85248fe1ba52666913ee0b357
parent: 999193996c042e7cf8f43e7b9512e131cf93b7c5
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sat Feb 4 17:40:04 EST 2017

[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().

--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -426,7 +426,7 @@
 /* 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);
--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -419,7 +419,7 @@
 	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 @@
 }
 
 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);
--- a/cc1/stmt.c
+++ b/cc1/stmt.c
@@ -8,6 +8,9 @@
 #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 @@
 }
 
 static Node *
-condition(void)
+condition(int neg)
 {
 	Node *np;
 
 	expect('(');
-	np = condexpr();
+	np = condexpr(neg);
 	expect(')');
 
 	return np;
@@ -77,7 +80,7 @@
 	lbreak = newlabel();
 
 	expect(WHILE);
-	np = condition();
+	np = condition(NONEGATE);
 
 	emit(OJUMP, lcont);
 
@@ -120,7 +123,7 @@
 		expect(';');
 		break;
 	}
-	econd = (yytoken != ';') ? condexpr() : NULL;
+	econd = (yytoken != ';') ? condexpr(NONEGATE) : NULL;
 	expect(';');
 	einc = (yytoken != ')') ? expr() : NULL;
 	expect(')');
@@ -158,7 +161,7 @@
 	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 @@
 
 	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();