commit 71c6d0ec20a1644b4cf34d52691993d271417660
Author:     Roberto E. Vargas Caballero <[email protected]>
AuthorDate: Tue Sep 8 22:23:17 2015 +0200
Commit:     Roberto E. Vargas Caballero <[email protected]>
CommitDate: Tue Sep 8 22:23:17 2015 +0200

    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.

diff --git a/cc1/cc1.h b/cc1/cc1.h
index 8e00760..7b14454 100644
--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -305,7 +305,8 @@ enum op {
        ORET,
        ODECL,
        OSWITCH,
-       OSWITCHT
+       OSWITCHT,
+       OINIT
 };
 
 /* error.c */
diff --git a/cc1/code.c b/cc1/code.c
index 0be9d93..92d5217 100644
--- a/cc1/code.c
+++ b/cc1/code.c
@@ -39,6 +39,7 @@ char *optxt[] = {
        [OBXOR]  = "^",
        [OBOR] = "|",
        [OASSIGN] = ":",
+       [OINIT] = ":",
        [OA_MUL] = ":*",
        [OA_DIV] = ":/",
        [OA_MOD] = ":%",
@@ -91,6 +92,7 @@ void (*opcode[])(unsigned, void *) = {
        [OBXOR]  = emitbin,
        [OBOR] = emitbin,
        [OASSIGN] = emitbin,
+       [OINIT] = emitbin,
        [OA_MUL] = emitbin,
        [OA_DIV] = emitbin,
        [OA_MOD] = emitbin,
diff --git a/cc1/decl.c b/cc1/decl.c
index 79cfc68..bb12e81 100644
--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -372,16 +372,11 @@ initializer(Symbol *sym)
                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 *
diff --git a/cc1/expr.c b/cc1/expr.c
index d26d919..d4fd0f9 100644
--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -433,7 +433,9 @@ assignop(char op, Node *lp, Node *rp)
                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;
        }
 

Reply via email to