mirror of https://github.com/golang/go.git
runtime: add test case for checkptr alignment with nested expression
Discover while working on moving checkptr instrumentation from walk to SSA generation. Change-Id: I3f4a41fe4ad308b86c7c57d14b6ccc7c613e7f98 Reviewed-on: https://go-review.googlesource.com/c/go/+/345432 Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
010817714e
commit
044550ab0e
|
|
@ -55,3 +55,40 @@ func TestCheckPtr(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCheckPtr2(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
testenv.MustHaveGoRun(t)
|
||||||
|
|
||||||
|
exe, err := buildTestProg(t, "testprog", "-gcflags=all=-d=checkptr=2")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
testCases := []struct {
|
||||||
|
cmd string
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{"CheckPtrAlignmentNested", "fatal error: checkptr: converted pointer straddles multiple allocations\n"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range testCases {
|
||||||
|
tc := tc
|
||||||
|
t.Run(tc.cmd, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
got, err := testenv.CleanCmdEnv(exec.Command(exe, tc.cmd)).CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
t.Log(err)
|
||||||
|
}
|
||||||
|
if tc.want == "" {
|
||||||
|
if len(got) > 0 {
|
||||||
|
t.Errorf("output:\n%s\nwant no output", got)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !strings.HasPrefix(string(got), tc.want) {
|
||||||
|
t.Errorf("output:\n%s\n\nwant output starting with: %s", got, tc.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ func init() {
|
||||||
register("CheckPtrSmall", CheckPtrSmall)
|
register("CheckPtrSmall", CheckPtrSmall)
|
||||||
register("CheckPtrSliceOK", CheckPtrSliceOK)
|
register("CheckPtrSliceOK", CheckPtrSliceOK)
|
||||||
register("CheckPtrSliceFail", CheckPtrSliceFail)
|
register("CheckPtrSliceFail", CheckPtrSliceFail)
|
||||||
|
register("CheckPtrAlignmentNested", CheckPtrAlignmentNested)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckPtrAlignmentNoPtr() {
|
func CheckPtrAlignmentNoPtr() {
|
||||||
|
|
@ -96,3 +97,10 @@ func CheckPtrSliceFail() {
|
||||||
sink2 = p
|
sink2 = p
|
||||||
sink2 = unsafe.Slice(p, 100)
|
sink2 = unsafe.Slice(p, 100)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CheckPtrAlignmentNested() {
|
||||||
|
s := make([]int8, 100)
|
||||||
|
p := unsafe.Pointer(&s[0])
|
||||||
|
n := 9
|
||||||
|
_ = ((*[10]int8)(unsafe.Pointer((*[10]int64)(unsafe.Pointer(&p)))))[:n:n]
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue