Skip to content

Commit 8f85424

Browse files
committed
cmd/compile: fix crash when memmove argument is not the right type
Make sure the argument to memmove is of pointer type before we try to get the element type. This has been noticed for code that uses unsafe+linkname so it can call runtime.memmove. Probably not the best thing to allow, but the code is out there and we'd rather not break it unnecessarily. Fixes #30061 Change-Id: I334a8453f2e293959fd742044c43fbe93f0b3d31 Reviewed-on: https://go-review.googlesource.com/c/160826 Run-TryBot: Keith Randall <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 7e987b7 commit 8f85424

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

src/cmd/compile/internal/ssa/gen/generic.rules

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,6 +1354,7 @@
13541354
// Inline small or disjoint runtime.memmove calls with constant length.
13551355
(StaticCall {sym} s1:(Store _ (Const(64|32) [sz]) s2:(Store _ src s3:(Store {t} _ dst mem))))
13561356
&& isSameSym(sym,"runtime.memmove")
1357+
&& t.(*types.Type).IsPtr() // avoids TUINTPTR, see issue 30061
13571358
&& s1.Uses == 1 && s2.Uses == 1 && s3.Uses == 1
13581359
&& isInlinableMemmove(dst,src,sz,config)
13591360
&& clobber(s1) && clobber(s2) && clobber(s3)

src/cmd/compile/internal/ssa/rewritegeneric.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixedbugs/issue30061.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// compile
2+
3+
// Copyright 2019 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
// Make sure we can linkname to memmove with an unsafe.Pointer argument.
8+
9+
package p
10+
11+
import "unsafe"
12+
13+
//go:linkname memmove runtime.memmove
14+
func memmove(to, from unsafe.Pointer, n uintptr)
15+
16+
var V1, V2 int
17+
18+
func F() {
19+
memmove(unsafe.Pointer(&V1), unsafe.Pointer(&V2), unsafe.Sizeof(int(0)))
20+
}

0 commit comments

Comments
 (0)