Skip to content

Commit

Permalink
cmd/compile: fix register allocation for == operator
Browse files Browse the repository at this point in the history
The issue 12226 has been caused by the allocation of the same register
for the equality check of two byte values. The code in cgen.go freed the
register for the second operand before the allocation of the register
for the first operand.

Fixes golang#12226

Change-Id: Ie4dc33a488bd48a17f8ae9b497fd63c1ae390555
Reviewed-on: https://go-review.googlesource.com/13771
Reviewed-by: Russ Cox <[email protected]>
  • Loading branch information
ulikunitz authored and rsc committed Aug 25, 2015
1 parent 05a3b1f commit 6ec1809
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cmd/compile/internal/gc/cgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -2018,11 +2018,11 @@ func bgenx(n, res *Node, wantTrue bool, likely int, to *obj.Prog) {
Regalloc(&n2, nr.Type, nil)
Cgen(nr, &n2)
nr = &n2
Regfree(&n2)

Regalloc(&n1, nl.Type, nil)
Cgen(&tmp, &n1)
Regfree(&n1)
Regfree(&n2)
} else {
var n1 Node
if !nl.Addable && Ctxt.Arch.Thechar == '8' {
Expand Down
15 changes: 15 additions & 0 deletions test/fixedbugs/issue12226.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// run

// Copyright 2015 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"

func main() {
if []byte("foo")[0] == []byte("b")[0] {
fmt.Println("BUG: \"foo\" and \"b\" appear to have the same first byte")
}
}

0 comments on commit 6ec1809

Please sign in to comment.