Commit 75b886ab authored by Tal Shprecher's avatar Tal Shprecher Committed by Matthew Dempsky

cmd/compile: reject embedded unsafe.Pointer values

Fixes #14729

Change-Id: Ied819aa7b23e25de30aa8cde049c97297b4cab11
Reviewed-on: https://go-review.googlesource.com/22325Reviewed-by: 's avatarMatthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent f4f1b307
......@@ -719,7 +719,7 @@ func checkembeddedtype(t *Type) {
}
}
if t.IsPtr() {
if t.IsPtr() || t.IsUnsafePtr() {
Yyerror("embedded type cannot be a pointer")
} else if t.Etype == TFORW && t.ForwardType().Embedlineno == 0 {
t.ForwardType().Embedlineno = lineno
......
......@@ -1111,6 +1111,11 @@ func (t *Type) IsPtr() bool {
return t.Etype == TPTR32 || t.Etype == TPTR64
}
// IsUnsafePtr reports whether t is an unsafe pointer.
func (t *Type) IsUnsafePtr() bool {
return t.Etype == TUNSAFEPTR
}
// IsPtrShaped reports whether t is represented by a single machine pointer.
// In addition to regular Go pointer types, this includes map, channel, and
// function types and unsafe.Pointer. It does not include array or struct types
......
......@@ -3557,7 +3557,7 @@ func copytype(n *Node, t *Type) {
if embedlineno != 0 {
lineno = embedlineno
if t.IsPtr() {
if t.IsPtr() || t.IsUnsafePtr() {
Yyerror("embedded type cannot be a pointer")
}
}
......
// errorcheck
// 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 14729: structs cannot embed unsafe.Pointer per the spec.
package main
import "unsafe"
type s struct { unsafe.Pointer } // ERROR "embedded type cannot be a pointer"
type s1 struct { p unsafe.Pointer }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment