diff options
| author | Tal Shprecher <tshprecher@gmail.com> | 2016-04-20 14:05:48 -0700 |
|---|---|---|
| committer | Matthew Dempsky <mdempsky@google.com> | 2016-04-21 00:32:01 +0000 |
| commit | 75b886ab790782f34945c0e1b0dee4189399ac9e (patch) | |
| tree | 35c5dd559bfab315de694b7269df19d89e7cd93e /src | |
| parent | f4f1b30749be167b7c5ecb7c775c2acd8d32ae9e (diff) | |
| download | go-75b886ab790782f34945c0e1b0dee4189399ac9e.tar.xz | |
cmd/compile: reject embedded unsafe.Pointer values
Fixes #14729
Change-Id: Ied819aa7b23e25de30aa8cde049c97297b4cab11
Reviewed-on: https://go-review.googlesource.com/22325
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src')
| -rw-r--r-- | src/cmd/compile/internal/gc/dcl.go | 2 | ||||
| -rw-r--r-- | src/cmd/compile/internal/gc/type.go | 5 | ||||
| -rw-r--r-- | src/cmd/compile/internal/gc/typecheck.go | 2 |
3 files changed, 7 insertions, 2 deletions
diff --git a/src/cmd/compile/internal/gc/dcl.go b/src/cmd/compile/internal/gc/dcl.go index 0e4b5f6051..e303f11c09 100644 --- a/src/cmd/compile/internal/gc/dcl.go +++ b/src/cmd/compile/internal/gc/dcl.go @@ -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 diff --git a/src/cmd/compile/internal/gc/type.go b/src/cmd/compile/internal/gc/type.go index 855b070af6..16399547c7 100644 --- a/src/cmd/compile/internal/gc/type.go +++ b/src/cmd/compile/internal/gc/type.go @@ -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 diff --git a/src/cmd/compile/internal/gc/typecheck.go b/src/cmd/compile/internal/gc/typecheck.go index bf85819bce..e158c87611 100644 --- a/src/cmd/compile/internal/gc/typecheck.go +++ b/src/cmd/compile/internal/gc/typecheck.go @@ -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") } } |
