]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: add Type.IsUintptr() to detect type is an uintptr
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Wed, 9 Sep 2020 05:09:26 +0000 (12:09 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Wed, 9 Sep 2020 08:03:14 +0000 (08:03 +0000)
Passes toolstash-check.

Change-Id: I7051d45eafbfd4dea73a3d4b5ea6cff39d76cbc1
Reviewed-on: https://go-review.googlesource.com/c/go/+/253658
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/gc/esc.go
src/cmd/compile/internal/gc/escape.go
src/cmd/compile/internal/gc/subr.go
src/cmd/compile/internal/gc/walk.go
src/cmd/compile/internal/types/type.go

index 4b843aba35b396f53fab3194bbe7ea8d154b53a6..375331d1f5b5a15f29aa55c4ddcb979333f1997b 100644 (file)
@@ -377,7 +377,7 @@ func (e *Escape) paramTag(fn *Node, narg int, f *types.Field) string {
                // This really doesn't have much to do with escape analysis per se,
                // but we are reusing the ability to annotate an individual function
                // argument and pass those annotations along to importing code.
-               if f.Type.Etype == TUINTPTR {
+               if f.Type.IsUintptr() {
                        if Debug['m'] != 0 {
                                Warnl(f.Pos, "assuming %v is unsafe uintptr", name())
                        }
@@ -407,13 +407,13 @@ func (e *Escape) paramTag(fn *Node, narg int, f *types.Field) string {
        }
 
        if fn.Func.Pragma&UintptrEscapes != 0 {
-               if f.Type.Etype == TUINTPTR {
+               if f.Type.IsUintptr() {
                        if Debug['m'] != 0 {
                                Warnl(f.Pos, "marking %v as escaping uintptr", name())
                        }
                        return uintptrEscapesTag
                }
-               if f.IsDDD() && f.Type.Elem().Etype == TUINTPTR {
+               if f.IsDDD() && f.Type.Elem().IsUintptr() {
                        // final argument is ...uintptr.
                        if Debug['m'] != 0 {
                                Warnl(f.Pos, "marking %v as escaping ...uintptr", name())
index dc469e276c6b1967e80acf1958c91f5d51385691..75da439bb7f234b75e16915ca00f8412ca3abd87 100644 (file)
@@ -493,7 +493,7 @@ func (e *Escape) exprSkipInit(k EscHole, n *Node) {
                        // easily detect object boundaries on the heap
                        // than the stack.
                        e.assignHeap(n.Left, "conversion to unsafe.Pointer", n)
-               } else if n.Type.IsUnsafePtr() && n.Left.Type.Etype == TUINTPTR {
+               } else if n.Type.IsUnsafePtr() && n.Left.Type.IsUintptr() {
                        e.unsafeValue(k, n.Left)
                } else {
                        e.expr(k, n.Left)
index 6d0a40c287d74b1efa5b598e4ef176c4c6484624..d3ba53ff0c03c478cbf4c68aef824d650a861a90 100644 (file)
@@ -781,12 +781,12 @@ func convertop(srcConstant bool, src, dst *types.Type, why *string) Op {
        }
 
        // 8. src is a pointer or uintptr and dst is unsafe.Pointer.
-       if (src.IsPtr() || src.Etype == TUINTPTR) && dst.IsUnsafePtr() {
+       if (src.IsPtr() || src.IsUintptr()) && dst.IsUnsafePtr() {
                return OCONVNOP
        }
 
        // 9. src is unsafe.Pointer and dst is a pointer or uintptr.
-       if src.IsUnsafePtr() && (dst.IsPtr() || dst.Etype == TUINTPTR) {
+       if src.IsUnsafePtr() && (dst.IsPtr() || dst.IsUintptr()) {
                return OCONVNOP
        }
 
index a9fefb3ddd2edf65c2fc7f9259e872d94f214bcb..361de7e0f38c86e500b6e4c34a7258af9e0db57e 100644 (file)
@@ -962,7 +962,7 @@ opswitch:
                                n = walkCheckPtrAlignment(n, init, nil)
                                break
                        }
-                       if n.Type.IsUnsafePtr() && n.Left.Type.Etype == TUINTPTR { // uintptr to unsafe.Pointer
+                       if n.Type.IsUnsafePtr() && n.Left.Type.IsUintptr() { // uintptr to unsafe.Pointer
                                n = walkCheckPtrArithmetic(n, init)
                                break
                        }
@@ -3886,7 +3886,7 @@ func wrapCall(n *Node, init *Nodes) *Node {
        t := nod(OTFUNC, nil, nil)
        for i, arg := range n.List.Slice() {
                s := lookupN("a", i)
-               if !isBuiltinCall && arg.Op == OCONVNOP && arg.Type.Etype == TUINTPTR && arg.Left.Type.IsUnsafePtr() {
+               if !isBuiltinCall && arg.Op == OCONVNOP && arg.Type.IsUintptr() && arg.Left.Type.IsUnsafePtr() {
                        origArgs[i] = arg
                        arg = arg.Left
                        n.List.SetIndex(i, arg)
index e4b3d885d94c7d97ad3a4c9fd7e2ea6a8be5b8bd..a777a5fd90758a7ad7139203c28913062861ce90 100644 (file)
@@ -1230,6 +1230,11 @@ func (t *Type) IsUnsafePtr() bool {
        return t.Etype == TUNSAFEPTR
 }
 
+// IsUintptr reports whether t is an uintptr.
+func (t *Type) IsUintptr() bool {
+       return t.Etype == TUINTPTR
+}
+
 // 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