]> Cypherpunks repositories - gostls13.git/commitdiff
8g: make a[byte(x)] truncate x
authorRuss Cox <rsc@golang.org>
Fri, 26 Feb 2010 21:15:29 +0000 (13:15 -0800)
committerRuss Cox <rsc@golang.org>
Fri, 26 Feb 2010 21:15:29 +0000 (13:15 -0800)
R=ken2
CC=golang-dev
https://golang.org/cl/223069

src/cmd/8g/cgen.c
test/fixedbugs/bug259.go [new file with mode: 0644]

index 5712fc28e12d39cd88472275c0a4c648b793f6cb..f932f991854f3f21cc329a429076e8246d1edaf2 100644 (file)
@@ -215,7 +215,14 @@ cgen(Node *n, Node *res)
                        break;
                }
                mgen(nl, &n1, res);
-               gmove(&n1, res);
+               if(n->type->width > widthptr)
+                       tempname(&n2, n->type);
+               else
+                       regalloc(&n2, n->type, res);
+               gmove(&n1, &n2);
+               gmove(&n2, res);
+               if(n2.op == OREGISTER)
+                       regfree(&n2);
                mfree(&n1);
                break;
 
diff --git a/test/fixedbugs/bug259.go b/test/fixedbugs/bug259.go
new file mode 100644 (file)
index 0000000..d148fb3
--- /dev/null
@@ -0,0 +1,16 @@
+// $G $D/$F.go && $L $F.$A && ./$A.out
+
+// Copyright 2010 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.
+
+package main
+
+import "fmt"
+
+var x = uint32(0x01020304)
+var y = [...]uint32{1,2,3,4,5}
+
+func main() {
+       fmt.Sprint(y[byte(x)])
+}