mirror of
https://github.com/golang/go
synced 2024-09-04 23:44:16 +00:00
cmd/compile: fix binary import of unsafe.Pointer literals
Add a type conversion to uintptr for untyped constants before the conversion to unsafe.Pointer. Fixes #16317 Change-Id: Ib85feccad1019e687e7eb6135890b64b82fb87fb Reviewed-on: https://go-review.googlesource.com/27441 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: Robert Griesemer <gri@golang.org> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
ee333b4b74
commit
9aea69d6dc
|
@ -807,6 +807,11 @@ func (p *importer) node() *Node {
|
|||
typ := p.typ()
|
||||
n := nodlit(p.value(typ))
|
||||
if !typ.IsUntyped() {
|
||||
if typ.IsUnsafePtr() {
|
||||
conv := Nod(OCALL, typenod(Types[TUINTPTR]), nil)
|
||||
conv.List.Set1(n)
|
||||
n = conv
|
||||
}
|
||||
conv := Nod(OCALL, typenod(typ), nil)
|
||||
conv.List.Set1(n)
|
||||
n = conv
|
||||
|
|
11
test/fixedbugs/issue16317.dir/a.go
Normal file
11
test/fixedbugs/issue16317.dir/a.go
Normal file
|
@ -0,0 +1,11 @@
|
|||
// Copyright 2016 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package a
|
||||
|
||||
import "unsafe"
|
||||
|
||||
func ConstUnsafePointer() unsafe.Pointer {
|
||||
return unsafe.Pointer(uintptr(0))
|
||||
}
|
11
test/fixedbugs/issue16317.dir/b.go
Normal file
11
test/fixedbugs/issue16317.dir/b.go
Normal file
|
@ -0,0 +1,11 @@
|
|||
// Copyright 2016 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
import "./a"
|
||||
|
||||
func main() {
|
||||
_ = a.ConstUnsafePointer()
|
||||
}
|
10
test/fixedbugs/issue16317.go
Normal file
10
test/fixedbugs/issue16317.go
Normal file
|
@ -0,0 +1,10 @@
|
|||
// compiledir
|
||||
|
||||
// Copyright 2016 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Issue 16317: cmd/compile: internal compiler error:
|
||||
// unhandled OCONV INT -> TUNSAFEPTR
|
||||
|
||||
package ignored
|
Loading…
Reference in a new issue