[hackers] [scc] Allow 0 in pointer initialization || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Tue, 8 Sep 2015 22:25:38 +0200 (CEST)

commit 71c6d0ec20a1644b4cf34d52691993d271417660
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Tue Sep 8 22:23:17 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
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
_AT_@ -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
_AT_@ -39,6 +39,7 @@ char *optxt[] = {
         [OBXOR] = "^",
         [OBOR] = "|",
         [OASSIGN] = ":",
+ [OINIT] = ":",
         [OA_MUL] = ":*",
         [OA_DIV] = ":/",
         [OA_MOD] = ":%",
_AT_@ -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
_AT_@ -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
_AT_@ -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;
         }
 
Received on Tue Sep 08 2015 - 22:25:38 CEST

This archive was generated by hypermail 2.3.0 : Tue Sep 08 2015 - 22:36:11 CEST