Closed xhd2015 closed 4 months ago
This can be replicated with the following test:
var ints [3]int
func TestArrayPointer(t *testing.T) {
x := &ints[0]
y := &ints[0]
t.Logf("x=0x%x", x)
t.Logf("y=0x%x", y)
}
Running go test
succeeds, while xgo test
fails:
$ go test -v ./
=== RUN TestArrayPointer
debug_test.go:19: x=0x124f640
debug_test.go:20: y=0x124f640
--- PASS: TestArrayPointer (0.00s)
PASS
ok github.com/xhd2015/xgo/runtime/test/debug 0.663s
$ xgo test -v ./
=== RUN TestArrayPointer
debug_test.go:19: x=0xc00001c1b0
debug_test.go:20: y=0xc00001c1c8
debug_test.go:22: x != y
--- FAIL: TestArrayPointer (0.00s)
FAIL
FAIL github.com/xhd2015/xgo/runtime/test/debug 0.831s
FAIL
exit status 1
The compiler will rewrite &ints[0]
to
tmp_ints1 := ints
__trap(&tmp_ints1)
x := &tmp_ints1[0]
tmp_ints2 := ints
__trap(&tmp_ints2)
y:=&tmp_ints2[0]
That's why x
and y
has 24 byte(3 ints) offset when testing with xgo
When encountering an Operation{Op: AND, X: Index}
, where the Index might be slice, array or map, skip intercepting the expression. Since it's invalid for map. And for slice and array, it's value is not useful.
xgo test -v -run TestOrder ./tpl/internal/go_templates/fmtsort/
Go Version: Go1.22
Go test succeeds, xgo test fails: