1
0
mirror of https://github.com/golang/go synced 2024-11-26 07:17:59 -07:00

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:
Cuong Manh Le 2021-08-28 10:08:32 +07:00
parent 010817714e
commit 044550ab0e
2 changed files with 45 additions and 0 deletions

View File

@ -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)
}
})
}
}

View File

@ -20,6 +20,7 @@ func init() {
register("CheckPtrSmall", CheckPtrSmall)
register("CheckPtrSliceOK", CheckPtrSliceOK)
register("CheckPtrSliceFail", CheckPtrSliceFail)
register("CheckPtrAlignmentNested", CheckPtrAlignmentNested)
}
func CheckPtrAlignmentNoPtr() {
@ -96,3 +97,10 @@ func CheckPtrSliceFail() {
sink2 = p
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]
}