]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix binary import of unsafe.Pointer literals
authorMartin Möhrmann <martisch@uos.de>
Sun, 21 Aug 2016 15:08:04 +0000 (17:08 +0200)
committerRobert Griesemer <gri@golang.org>
Tue, 23 Aug 2016 18:03:07 +0000 (18:03 +0000)
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>

src/cmd/compile/internal/gc/bimport.go
test/fixedbugs/issue16317.dir/a.go [new file with mode: 0644]
test/fixedbugs/issue16317.dir/b.go [new file with mode: 0644]
test/fixedbugs/issue16317.go [new file with mode: 0644]

index 2f724861f602d8c0c72ec29bd501233074672aed..dfe102b78a2b501dd45bf95f48da70b5f89def6f 100644 (file)
@@ -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
diff --git a/test/fixedbugs/issue16317.dir/a.go b/test/fixedbugs/issue16317.dir/a.go
new file mode 100644 (file)
index 0000000..3a1b7e0
--- /dev/null
@@ -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))
+}
diff --git a/test/fixedbugs/issue16317.dir/b.go b/test/fixedbugs/issue16317.dir/b.go
new file mode 100644 (file)
index 0000000..b813918
--- /dev/null
@@ -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()
+}
diff --git a/test/fixedbugs/issue16317.go b/test/fixedbugs/issue16317.go
new file mode 100644 (file)
index 0000000..b3376bb
--- /dev/null
@@ -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