commit 1a58b74e71aff78c8d6bee79604a8330c745d927
Author:     Roberto E. Vargas Caballero <[email protected]>
AuthorDate: Tue Jun 14 12:58:39 2016 +0200
Commit:     Roberto E. Vargas Caballero <[email protected]>
CommitDate: Tue Jun 14 12:58:39 2016 +0200

    [cc1] Deal with redefinitions in the command line
    
    The POSIX standard commands that -D definitions
    without replacement parts must be defined with
    a replacement string "1". We also warn in the
    case of redefining any macro, even when they have the
    same replacement string. It is easier and it is
    a good practice to define them only once.

diff --git a/cc1/cpp.c b/cc1/cpp.c
index 81caa5a..9b89b12 100644
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
@@ -26,15 +26,24 @@ defmacro(char *s)
 {
        char *p, *q;
        Symbol *sym;
+       char def[] = "=1";
 
-       if ((p = strchr(s, '=')) != NULL) {
-               *p++='\0';
-               q = xmalloc(strlen(p) + 4);
-               sprintf(q, "-1#%s", p);
-               p = q;
+       if ((p = strchr(s, '=')) == NULL)
+               p = def;
+       *p++='\0';
+       q = xmalloc(strlen(p) + 4);
+       sprintf(q, "-1#%s", p);
+
+       sym = lookup(NS_CPP, s);
+       if (sym->flags & SDECLARED) {
+               warn("'%s' redefined");
+               free(sym->u.s);
+       } else {
+               install(NS_CPP, sym);
+               sym->flags |= SDECLARED|SSTRING;
        }
-       sym = install(NS_CPP, lookup(NS_CPP, s));
-       sym->u.s = p;
+
+       sym->u.s = q;
        return sym;
 }
 

Reply via email to