Skip to content

cmd/compile, runtime: go:nocheckptr not respected #42131

@randall77

Description

@randall77

At tip, do

$ go test -gcflags=-d=checkptr net/http -run=WriteSetCookies
fatal error: checkptr: pointer arithmetic result points to invalid allocation

goroutine 6 [running]:
runtime.throw(0x1538101, 0x40)
	/Users/khr/sandbox/readonly/src/runtime/panic.go:1112 +0x72 fp=0xc0000604e8 sp=0xc0000604b8 pc=0x10395b2
runtime.checkptrArithmetic(0xc000060650, 0x0, 0x0, 0x0)
	/Users/khr/sandbox/readonly/src/runtime/checkptr.go:48 +0x1c8 fp=0xc000060520 sp=0xc0000604e8 pc=0x1009228
strings.noescape(...)
	/Users/khr/sandbox/readonly/src/strings/builder.go:30
strings.(*Builder).copyCheck(...)
	/Users/khr/sandbox/readonly/src/strings/builder.go:40
strings.(*Builder).Grow(...)
	/Users/khr/sandbox/readonly/src/strings/builder.go:77
net/http.(*Cookie).String(0x18228a0, 0xc000182090, 0x1766660)
	/Users/khr/sandbox/readonly/src/net/http/cookie.go:179 +0xbb fp=0xc000060680 sp=0xc000060520 pc=0x12a989b
net/http.TestWriteSetCookies(0xc000001e00)
	/Users/khr/sandbox/readonly/src/net/http/cookie_test.go:158 +0xfc fp=0xc000060780 sp=0xc000060680 pc=0x130f95c
testing.tRunner(0xc000001e00, 0x1544960)
	/Users/khr/sandbox/readonly/src/testing/testing.go:1173 +0xef fp=0xc0000607d0 sp=0xc000060780 pc=0x110198f
runtime.goexit()
	/Users/khr/sandbox/readonly/src/runtime/asm_amd64.s:1376 +0x1 fp=0xc0000607d8 sp=0xc0000607d0 pc=0x10722c1
created by testing.(*T).Run
	/Users/khr/sandbox/readonly/src/testing/testing.go:1218 +0x2b3

goroutine 1 [chan receive]:
testing.(*T).Run(0xc000001e00, 0x1519974, 0x13, 0x1544960, 0x1091b46)
	/Users/khr/sandbox/readonly/src/testing/testing.go:1219 +0x2da
testing.runTests.func1(0xc000001c80)
	/Users/khr/sandbox/readonly/src/testing/testing.go:1491 +0x78
testing.tRunner(0xc000001c80, 0xc0000c9d60)
	/Users/khr/sandbox/readonly/src/testing/testing.go:1173 +0xef
testing.runTests(0xc00000e150, 0x1830600, 0x215, 0x215, 0xbfdc4b8416e9b130, 0x8bb2d7dbfe, 0x1835c40, 0xc0000c9e18)
	/Users/khr/sandbox/readonly/src/testing/testing.go:1489 +0x2fe
testing.(*M).Run(0xc000030080, 0x0)
	/Users/khr/sandbox/readonly/src/testing/testing.go:1397 +0x1eb
net/http_test.TestMain(0xc000030080)
	/Users/khr/sandbox/readonly/src/net/http/main_test.go:23 +0x2b
main.main()
	_testmain.go:1177 +0x165
FAIL	net/http	0.165s
FAIL

It appears that even though strings.noescape is marked as go:nocheckptr, there is a checkptr invocation there.
Maybe related, it looks like strings.noescape got inlined, where it probably shouldn't have (because functions marked go:nocheckptr shouldn't be inlined? Not sure.)

runtime.checkptrArithmetic is passed a stack pointer with an empty set of originals, which is the proxmal cause of the assertion failure.

@mdempsky

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions