]> Cypherpunks repositories - gostls13.git/commitdiff
gc: fix zero-length struct eval
authorRuss Cox <rsc@golang.org>
Mon, 5 Sep 2011 19:31:22 +0000 (15:31 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 5 Sep 2011 19:31:22 +0000 (15:31 -0400)
Fixes #2232.

R=ken2
CC=golang-dev
https://golang.org/cl/4960054

src/cmd/5g/cgen.c
src/cmd/6g/cgen.c
src/cmd/8g/cgen.c
test/struct0.go [new file with mode: 0644]

index 9481769d39d6c64d5308019b4e9f1bdaadc0cd73..0ea8695a024cfb9ea5e04a1edfe70e1511154071 100644 (file)
@@ -1201,8 +1201,6 @@ sgen(Node *n, Node *res, int32 w)
                dump("r", n);
                dump("res", res);
        }
-       if(w == 0)
-               return;
        if(w < 0)
                fatal("sgen copy %d", w);
        if(n->ullman >= UINF && res->ullman >= UINF)
@@ -1210,6 +1208,15 @@ sgen(Node *n, Node *res, int32 w)
        if(n->type == T)
                fatal("sgen: missing type");
 
+       if(w == 0) {
+               // evaluate side effects only.
+               regalloc(&dst, types[tptr], N);
+               agen(res, &dst);
+               agen(n, &dst);
+               regfree(&dst);
+               return;
+       }
+
        // determine alignment.
        // want to avoid unaligned access, so have to use
        // smaller operations for less aligned types.
index 6448d9c069eed86335c04ac519bec4bb99f78d33..43bec00594cf440aa8d6f17c34ad11f3e6bdc1b8 100644 (file)
@@ -1029,11 +1029,9 @@ sgen(Node *n, Node *ns, int32 w)
                dump("r", n);
                dump("res", ns);
        }
-       if(w == 0)
-               return;
-       if(n->ullman >= UINF && ns->ullman >= UINF) {
+
+       if(n->ullman >= UINF && ns->ullman >= UINF)
                fatal("sgen UINF");
-       }
 
        if(w < 0)
                fatal("sgen copy %d", w);
@@ -1041,6 +1039,15 @@ sgen(Node *n, Node *ns, int32 w)
        if(w == 16)
                if(componentgen(n, ns))
                        return;
+       
+       if(w == 0) {
+               // evaluate side effects only
+               regalloc(&nodr, types[tptr], N);
+               agen(ns, &nodr);
+               agen(n, &nodr);
+               regfree(&nodr);
+               return;
+       }
 
        // offset on the stack
        osrc = stkof(n);
index 4a37514d455264cd470ae5dd997288e96e7f70c2..21b7815fd484c9997b1389c5a73818d43df41219 100644 (file)
@@ -1136,15 +1136,20 @@ sgen(Node *n, Node *res, int32 w)
                dump("r", n);
                dump("res", res);
        }
-       if(w == 0)
-               return;
-       if(n->ullman >= UINF && res->ullman >= UINF) {
+       if(n->ullman >= UINF && res->ullman >= UINF)
                fatal("sgen UINF");
-       }
 
        if(w < 0)
                fatal("sgen copy %d", w);
 
+       if(w == 0) {
+               // evaluate side effects only.
+               tempname(&tdst, types[tptr]);
+               agen(res, &tdst);
+               agen(n, &tdst);
+               return;
+       }
+
        // offset on the stack
        osrc = stkof(n);
        odst = stkof(res);
diff --git a/test/struct0.go b/test/struct0.go
new file mode 100644 (file)
index 0000000..2398c41
--- /dev/null
@@ -0,0 +1,34 @@
+// $G $D/$F.go && $L $F.$A && ./$A.out
+
+// Copyright 2011 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// zero length structs.
+// used to not be evaluated.
+// issue 2232.
+
+package main
+
+func recv(c chan interface{}) struct{} {
+       return (<-c).(struct{})
+}
+
+var m = make(map[interface{}]int)
+
+func recv1(c chan interface{}) {
+       defer rec()
+       m[(<-c).(struct{})] = 0
+}
+
+func rec() {
+       recover()
+}
+
+func main() {
+       c := make(chan interface{})
+       go recv(c)
+       c <- struct{}{}
+       go recv1(c)
+       c <- struct{}{}
+}