shithub: scc

Download patch

ref: 71c6d0ec20a1644b4cf34d52691993d271417660
parent: 3a225104759c18a70e8eb918d88a07111f3a128b
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Tue Sep 8 18:23:17 EDT 2015

Allow 0 in pointer initialization

This situation is handled in assignop(), so it is better
do the work on it, but the error message can be a bit
confusing, so it is better define a new operator
and give the correct message.

--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -305,7 +305,8 @@
 	ORET,
 	ODECL,
 	OSWITCH,
-	OSWITCHT
+	OSWITCHT,
+	OINIT
 };
 
 /* error.c */
--- a/cc1/code.c
+++ b/cc1/code.c
@@ -39,6 +39,7 @@
 	[OBXOR]  = "^",
 	[OBOR] = "|",
 	[OASSIGN] = ":",
+	[OINIT] = ":",
 	[OA_MUL] = ":*",
 	[OA_DIV] = ":/",
 	[OA_MOD] = ":%",
@@ -91,6 +92,7 @@
 	[OBXOR]  = emitbin,
 	[OBOR] = emitbin,
 	[OASSIGN] = emitbin,
+	[OINIT] = emitbin,
 	[OA_MUL] = emitbin,
 	[OA_DIV] = emitbin,
 	[OA_MOD] = emitbin,
--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -372,16 +372,11 @@
 		return;
 	}
 	np = expr();
-	if ((np = convert(np, tp, 0)) == NULL)
-		goto bad_initializer;
 	if ((sym->flags & ISLOCAL) == 0) {
-		emit(OEXPR, assignop(OASSIGN, varnode(sym), np));
+		emit(OEXPR, assignop(OINIT, varnode(sym), np));
 		return;
 	}
 	return;
-
-bad_initializer:
-	errorp("invalid initializer");
 }
 
 static Symbol *
--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -433,7 +433,9 @@
 		force = 1;
 	}
 	if ((rp = convert(rp, tp, force)) == NULL) {
-		errorp("incompatible types when assigning");
+		errorp((op == OINIT) ?
+		        "incorrect initiliazer" :
+		        "incompatible types when assigning");
 		return lp;
 	}