shithub: scc

Download patch

ref: 825d523e6ae30a93224c2d6799592ae73f7ea926
parent: 7369e862b993e9e62b153f0101d0866f85d5a485
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Aug 5 14:13:42 EDT 2014

Remove decay in convert()

convert() do all the needed operations to convert an expression
of a type in another type. It was generating a decay when the
destination type was an array or an function, but it was incorrect,
because it was generating a decay of the node, that surely was
not an array or a function. The correct here is return NULL,
because we should not receive such types as destination
types.

--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -111,17 +111,15 @@
 Node *
 convert(Node *np, Type *tp, char iscast)
 {
-	uint8_t t;
-
 	if (eqtype(np->type, tp))
 		return np;
-	t = tp->op;
 	switch (np->typeop) {
 	case ENUM: case INT: case FLOAT:
-		switch (t) {
+		switch (tp->op) {
 		case PTR:
 			if (!iscast || np->typeop == FLOAT)
 				return NULL;
+			/* PASSTHROUGH */
 		case INT: case FLOAT: case ENUM: case VOID:
 			break;
 		default:
@@ -129,13 +127,11 @@
 		}
 		break;
 	case PTR:
-		switch (t) {
+		switch (tp->op) {
 		case ENUM: case INT: case VOID: /* TODO: allow p = 0 */
 			if (!iscast)
 				return NULL;;
 			break;
-		case ARY: case FTN:
-			np = decay(np);
 		case PTR:
 			if (iscast ||
 			    tp == pvoidtype ||