| 1 |
// run |
| 2 |
|
| 3 |
// Copyright 2023 The Go Authors. All rights reserved. |
| 4 |
// Use of this source code is governed by a BSD-style |
| 5 |
// license that can be found in the LICENSE file. |
| 6 |
|
| 7 |
// Test that zero-sized variables get same address as |
| 8 |
// runtime.zerobase. |
| 9 |
|
| 10 |
package main |
| 11 |
|
| 12 |
var x, y [0]int |
| 13 |
var p, q = new([0]int), new([0]int) // should get &runtime.zerobase |
| 14 |
|
| 15 |
func main() { |
| 16 |
if &x != &y { |
| 17 |
// Failing for now. x and y are at same address, but compiler optimizes &x==&y to false. Skip. |
| 18 |
// print("&x=", &x, " &y=", &y, " &x==&y = ", &x==&y, "\n") |
| 19 |
// panic("FAIL") |
| 20 |
} |
| 21 |
if p != q { |
| 22 |
print("p=", p, " q=", q, " p==q = ", p==q, "\n") |
| 23 |
panic("FAIL") |
| 24 |
} |
| 25 |
if &x != p { |
| 26 |
print("&x=", &x, " p=", p, " &x==p = ", &x==p, "\n") |
| 27 |
panic("FAIL") |
| 28 |
} |
| 29 |
if &y != p { |
| 30 |
print("&y=", &y, " p=", p, " &y==p = ", &y==p, "\n") |
| 31 |
panic("FAIL") |
| 32 |
} |
| 33 |
} |