Currently, kencc generates temporaries into a global rathole, rahter than putting them onto the stack; this means that any code with a 'non-interruptible temporary' not thread or note safe. this code takes a first pass at removing it from kencc, using 'regsalloc' to store them on the stack. There's no attempt at reuse, so there may be room for improvement, but given that we don't use so many temporaries this way, it seems acceptable to just leave them on the stack until the function exits. this has only been tested lightly, and hasn't built more than a few dozen lines of test code, so it's nowhere near ready to commit; it's just presented for comment. any thoughts on the approach? anything obvious I missed? diff f305820f8891305ad73afa67ed2585b69d4054d8 uncommitted --- a/6c/cgen.c +++ b/6c/cgen.c @@ -1016,17 +1016,14 @@ break; case ODOT: - sugen(l, nodrat, l->type->width); + regsalloc(&nod, l); + sugen(l, &nod, l->type->width); if(nn == Z) break; - warn(n, "non-interruptable temporary"); - nod = *nodrat; if(!r || r->op != OCONST) { diag(n, "DOT and no offset"); break; } - nod.xoffset += (long)r->vconst; - nod.type = n->type; cgen(&nod, nn); break; @@ -1409,9 +1406,6 @@ prtree(nn, "sugen lhs"); prtree(n, "sugen"); } - if(nn == nodrat) - if(w > nrathole) - nrathole = w; switch(n->op) { case OIND: if(nn == Z) { @@ -1427,18 +1421,15 @@ case ODOT: l = n->left; - sugen(l, nodrat, l->type->width); + regsalloc(&nod1, l); + sugen(l, &nod1, l->type->width); if(nn == Z) break; - warn(n, "non-interruptable temporary"); - nod1 = *nodrat; r = n->right; if(!r || r->op != OCONST) { diag(n, "DOT and no offset"); break; } - nod1.xoffset += (long)r->vconst; - nod1.type = n->type; sugen(&nod1, nn, w); break; @@ -1524,15 +1515,17 @@ break; } - sugen(n->right, nodrat, w); + regsalloc(&nod0, n->right); + sugen(n->right, &nod0, w); warn(n, "non-interruptable temporary"); - sugen(nodrat, n->left, w); - sugen(nodrat, nn, w); + sugen(&nod0, n->left, w); + sugen(&nod0, nn, w); break; case OFUNC: if(nn == Z) { - sugen(n, nodrat, w); + regsalloc(&nod0, n); + sugen(n, &nod0, w); break; } if(nn->op != OIND) { --- a/6c/gc.h +++ b/6c/gc.h @@ -144,10 +144,8 @@ EXTERN Prog* lastp; EXTERN long maxargsafe; EXTERN int mnstring; -EXTERN Node* nodrat; EXTERN Node* nodret; EXTERN Node* nodsafe; -EXTERN long nrathole; EXTERN long nstring; EXTERN Prog* p; EXTERN long pc; @@ -154,7 +152,6 @@ EXTERN Node lregnode; EXTERN Node qregnode; EXTERN char string[NSNAME]; -EXTERN Sym* symrathole; EXTERN Node znode; EXTERN Prog zprog; EXTERN int reg[D_NONE]; --- a/6c/swt.c +++ b/6c/swt.c @@ -350,7 +350,7 @@ char *n; ulong sig; - if(debug['T'] && t == D_EXTERN && s->sig != SIGDONE && s->type != types[TENUM] && s != symrathole){ + if(debug['T'] && t == D_EXTERN && s->sig != SIGDONE){ sig = sign(s); Bputc(b, ASIGNAME); Bputc(b, ASIGNAME>>8); --- a/6c/test.c +++ b/6c/test.c @@ -1,17 +1,22 @@ #include <u.h> #include <libc.h> +typedef struct S S; + +struct S{ + int x; + int y; +}; + +S +fn(void) +{ + static int ncall; + return (S){1, ncall++}; +} + void main(void) { - uvlong a; - vlong b; - - a = 0xFFFFFFFF80000000; - b = 0xFFFFFFFF; - - - print("%ullX %llX, %ullX %ullX\n", a, b, (uvlong)0xffffffff); - exits(nil); + print("x: %d, y0:%d y1:%d y2: %d\n", fn().x, fn().y, fn().y, fn().y); } - --- a/6c/txt.c +++ b/6c/txt.c @@ -6,7 +6,6 @@ ginit(void) { int i; - Type *t; thechar = '6'; thestring = "amd64"; @@ -15,7 +14,6 @@ listinit(); nstring = 0; mnstring = 0; - nrathole = 0; pc = 0; breakpc = -1; continpc = -1; @@ -72,19 +70,6 @@ nodsafe->class = CAUTO; complex(nodsafe); - t = typ(TARRAY, types[TCHAR]); - symrathole = slookup(".rathole"); - symrathole->class = CGLOBL; - symrathole->type = t; - - nodrat = new(ONAME, Z, Z); - nodrat->sym = symrathole; - nodrat->type = types[TIND]; - nodrat->etype = TVOID; - nodrat->class = CGLOBL; - complex(nodrat); - nodrat->type = t; - nodret = new(ONAME, Z, Z); nodret->sym = slookup(".ret"); nodret->type = types[TIND]; @@ -126,7 +111,6 @@ while(mnstring) outstring("", 1L); symstring->type->width = nstring; - symrathole->type->width = nrathole; for(i=0; i<NHASH; i++) for(s = hash[i]; s != S; s = s->link) { if(s->type == T)