go/test/fixedbugs/issue52788.go
Cherry Mui 9ae7dc3040 cmd/compile: fix If lowering on ARM64
On ARM64, an If block is lowered to (NZ cond yes no). This is
incorrect because cond is a boolean value and therefore only the
last byte is meaningful (same as AMD64, see ARM64Ops.go). But here
we are comparing a full register width with 0. Correct it by
comparing only the last bit.

Fixes #52788.

Change-Id: I2cacf9f3d2f45e149c361a290f511b2d4ed845c4
Reviewed-on: https://go-review.googlesource.com/c/go/+/405114
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
2022-05-09 16:02:28 +00:00

28 lines
605 B
Go

// run
// Copyright 2022 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 52788: miscompilation for boolean comparison on ARM64.
package main
import (
"fmt"
"reflect"
)
func f(next func() bool) {
for b := next(); b; b = next() {
fmt.Printf("next() returned %v\n", b)
}
}
func main() {
next := reflect.MakeFunc(reflect.TypeOf((func() bool)(nil)), func(_ []reflect.Value) []reflect.Value {
return []reflect.Value{reflect.ValueOf(false)}
})
reflect.ValueOf(f).Call([]reflect.Value{next})
}