]> Cypherpunks repositories - gostls13.git/commitdiff
gc: fix another blank bug
authorRuss Cox <rsc@golang.org>
Fri, 9 Dec 2011 16:59:21 +0000 (11:59 -0500)
committerRuss Cox <rsc@golang.org>
Fri, 9 Dec 2011 16:59:21 +0000 (11:59 -0500)
R=ken2
CC=golang-dev
https://golang.org/cl/5478051

src/cmd/5g/gsubr.c
src/cmd/6g/gsubr.c
src/cmd/8g/gsubr.c
test/blank.go

index 73ae3304ad865898059de616f7f218a84bfe47d4..d8460ff7547aac4ab4537ae05d69e6213d1d9f8f 100644 (file)
@@ -515,6 +515,12 @@ nodarg(Type *t, int fp)
        n->orig = t->nname;
 
 fp:
+       // Rewrite argument named _ to __,
+       // or else the assignment to _ will be
+       // discarded during code generation.
+       if(isblank(n))
+               n->sym = lookup("__");
+
        switch(fp) {
        default:
                fatal("nodarg %T %d", t, fp);
index c43d2ef82fef9a2974124c3a27020d19f31b576a..cf00c3c49406882baff0dcfa481925487aafc60a 100644 (file)
@@ -481,6 +481,7 @@ nodarg(Type *t, int fp)
        n = nod(ONAME, N, N);
        n->type = t->type;
        n->sym = t->sym;
+       
        if(t->width == BADWIDTH)
                fatal("nodarg: offset not computed for %T", t);
        n->xoffset = t->width;
@@ -488,6 +489,12 @@ nodarg(Type *t, int fp)
        n->orig = t->nname;
 
 fp:
+       // Rewrite argument named _ to __,
+       // or else the assignment to _ will be
+       // discarded during code generation.
+       if(isblank(n))
+               n->sym = lookup("__");
+
        switch(fp) {
        case 0:         // output arg
                n->op = OINDREG;
index dd6ffbc4c69344de421fd38a2b3f3d45f5ff923a..9d0f7025f449deaa74bf11234f10347de9b3790f 100644 (file)
@@ -967,6 +967,12 @@ nodarg(Type *t, int fp)
                n->orig = t->nname;
                break;
        }
+       
+       // Rewrite argument named _ to __,
+       // or else the assignment to _ will be
+       // discarded during code generation.
+       if(isblank(n))
+               n->sym = lookup("__");
 
        switch(fp) {
        default:
index 581bc85c80a319c792e7fa2da9fa3ed6187ae807..d6c9e79c607f74e20d5de50495e108549b86bec5 100644 (file)
@@ -118,12 +118,29 @@ func (TI) M(x int, y int) {
        }
 }
 
+var fp = func(_ int, y int) {}
+
+func init() {
+       fp = fp1
+}
+
+func fp1(x, y int) {
+       if x != y {
+               println("invalid fp1 call:", x, y)
+               panic("bad fp1")
+       }
+}
+
+
 func m() {
        var i I
        
        i = TI{}
        i.M(1, 1)
        i.M(2, 2)
+       
+       fp(1, 1)
+       fp(2, 2)
 }
 
 // useless but legal