shithub: scc

Download patch

ref: fbd7247cc8cf0a6829d6a9a1e7e9f26f30e4005d
parent: ea7eeb566e8f2493e3495d974ba587ffabbe027d
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Tue Jan 19 10:38:53 EST 2016

Convert empry inirializers to the correct type

zero has integer type, and it is not what we always want.

--- a/cc1/code.c
+++ b/cc1/code.c
@@ -328,9 +328,10 @@
 	case PTR:
 	case INT:
 	case ENUM:
-		aux = (sym) ? *sym->u.init : constnode(zero);
+		aux = (sym) ? *sym->u.init : convert(constnode(zero), tp, 0);
 		emitexp(OEXPR, aux);
 		break;
+	/* TODO: case UNION: */
 	case STRUCT:
 	case ARY:
 		for (n = 0; n < tp->n.elem; ++n) {
@@ -339,10 +340,13 @@
 		}
 		break;
 	default:
-		/* TODO: Handle other kind of constants */
 		abort();
 	}
 
+	if (sym) {
+		free(sym->u.init);
+		sym->u.init = NULL;
+	}
 	freetree(np);
 	return;