1
0
mirror of https://github.com/golang/go synced 2024-11-25 00:07:56 -07:00

cmd/gc: fix codegen reordering for expressions involving && and ||

Fixes #2821.

R=rsc
CC=golang-dev
https://golang.org/cl/5606061
This commit is contained in:
Luuk van Dijk 2012-02-06 15:41:01 +01:00
parent 02fb021161
commit 5efd5624cc
3 changed files with 33 additions and 1 deletions

View File

@ -1670,6 +1670,11 @@ ullmancalc(Node *n)
if(n == N)
return;
if(n->ninit != nil) {
ul = UINF;
goto out;
}
switch(n->op) {
case OREGISTER:
case OLITERAL:
@ -3577,4 +3582,5 @@ addinit(Node **np, NodeList *init)
break;
}
n->ninit = concat(init, n->ninit);
n->ullman = UINF;
}

View File

@ -1203,10 +1203,11 @@ walkexpr(Node **np, NodeList **init)
fatal("missing switch %O", n->op);
ret:
ullmancalc(n);
if(debug['w'] && n != N)
dump("walk", n);
ullmancalc(n);
lineno = lno;
*np = n;
}

25
test/fixedbugs/bug406.go Normal file
View File

@ -0,0 +1,25 @@
// $G $D/$F.go && $L $F.$A && ./$A.out || echo "Bug406"
// Copyright 2012 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.
// Issue 2821
package main
type matrix struct {
e []int
}
func (a matrix) equal() bool {
for _ = range a.e {
}
return true
}
func main() {
var a matrix
var i interface{}
i = true && a.equal()
_ = i
}