[hackers] [scc] [cc2-qbe] Avoid name collision in local variables || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Fri, 22 Apr 2016 18:13:47 +0200 (CEST)

commit 0b5080ef495991eb73e8d946285a14d1ca143409
Author: Roberto E. Vargas Caballero <Roberto E. Vargas Caballero>
AuthorDate: Thu Apr 21 03:15:28 2016 +0200
Commit: Roberto E. Vargas Caballero <Roberto E. Vargas Caballero>
CommitDate: Thu Apr 21 03:15:28 2016 +0200

    [cc2-qbe] Avoid name collision in local variables
    
    C is a block language, and it means we can have variables with the
    same name in different blocks. For this reason we have to append
    an identifier for every local variable and in this way we avoid
    possible name clashes.

diff --git a/cc2/arch/qbe/code.c b/cc2/arch/qbe/code.c
index f668c60..258c745 100644
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
_AT_@ -7,7 +7,7 @@
 #include "../../cc2.h"
 #include "../../../inc/sizes.h"
 
-#define ADDR_LEN (IDENTSIZ+2)
+#define ADDR_LEN (IDENTSIZ+64)
 
 static void binary(void), load(void), store(void);
 
_AT_@ -118,17 +118,19 @@ sigil(Symbol *sym)
 static char *
 symname(Symbol *sym)
 {
- static char name[IDENTSIZ+2];
- static unsigned short id;
+ static char name[ADDR_LEN];
+ static unsigned id;
         char c = sigil(sym);
 
         if (sym->name) {
                 switch (sym->kind) {
                 case SEXTRN:
                 case SGLOB:
+ sprintf(name, "%c%s", c, sym->name);
+ return name;
                 case SPRIV:
                 case SAUTO:
- sprintf(name, "%c%s", c, sym->name);
+ sprintf(name, "%c%s.%u", c, sym->name, sym->id);
                         return name;
                 default:
                         abort();
_AT_@ -137,7 +139,7 @@ symname(Symbol *sym)
 
         if (sym->numid == 0 && (sym->numid = ++id) == 0)
                 error(EIDOVER);
- sprintf(name, "%c.%d", c, sym->numid);
+ sprintf(name, "%c.%u", c, sym->numid);
 
         return name;
 }
Received on Fri Apr 22 2016 - 18:13:47 CEST

This archive was generated by hypermail 2.3.0 : Fri Apr 22 2016 - 18:24:19 CEST