mirror of
https://github.com/golang/go
synced 2024-11-22 10:44:41 -07:00
625f2dccd4
CL 38338 introduced SSA rules to optimize two types of pointer equality tests: a pointer compared with itself, and comparison of addresses taken of two symbols which may have the same base. This patch adds rules to apply the same optimization to pointer inequality tests, which also ensures that two pointers to zero-width types cannot be both equal and unequal at the same time. Fixes #24503. Change-Id: Ic828aeb86ae2e680caf66c35f4c247674768a9ba Reviewed-on: https://go-review.googlesource.com/102275 Reviewed-by: Keith Randall <khr@golang.org> Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
29 lines
517 B
Go
29 lines
517 B
Go
// run
|
|
|
|
// Copyright 2018 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 24503: Handle == and != of addresses taken of symbols consistently.
|
|
|
|
package main
|
|
|
|
func test() string {
|
|
type test struct{}
|
|
o1 := test{}
|
|
o2 := test{}
|
|
if &o1 == &o2 {
|
|
return "equal"
|
|
}
|
|
if &o1 != &o2 {
|
|
return "unequal"
|
|
}
|
|
return "failed"
|
|
}
|
|
|
|
func main() {
|
|
if test() == "failed" {
|
|
panic("expected either 'equal' or 'unequal'")
|
|
}
|
|
}
|