]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: add test case for checkptr alignment with nested expression
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Sat, 28 Aug 2021 03:08:32 +0000 (10:08 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Sat, 28 Aug 2021 06:22:11 +0000 (06:22 +0000)
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>
src/runtime/checkptr_test.go
src/runtime/testdata/testprog/checkptr.go

index d5dd101adbe051164a9f23f858dfd46d99f29c66..b3aea079c66a25bb92747e5f8191e12050d1df47 100644 (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)
+                       }
+               })
+       }
+}
index 9c5561396e5d43b335c3b270201025809c307f1c..b27e5f74f868f3db8c31d60d745feac20f085cc8 100644 (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]
+}