]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: consistently use Type.IsUnsafePtr()
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Wed, 9 Sep 2020 05:06:18 +0000 (12:06 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Wed, 9 Sep 2020 08:03:05 +0000 (08:03 +0000)
Passes toolstash-check.

Change-Id: Iaeae7cc20e26af733642c7c8c7ca0a059e5b07b2
Reviewed-on: https://go-review.googlesource.com/c/go/+/253657
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/escape.go
src/cmd/compile/internal/gc/ssa.go
src/cmd/compile/internal/gc/subr.go
src/cmd/compile/internal/gc/walk.go

index d5cca4a38bdcb770dab5af7f010772bc5ae50309..dc469e276c6b1967e80acf1958c91f5d51385691 100644 (file)
@@ -485,7 +485,7 @@ func (e *Escape) exprSkipInit(k EscHole, n *Node) {
                e.discard(max)
 
        case OCONV, OCONVNOP:
-               if checkPtr(e.curfn, 2) && n.Type.Etype == TUNSAFEPTR && n.Left.Type.IsPtr() {
+               if checkPtr(e.curfn, 2) && n.Type.IsUnsafePtr() && n.Left.Type.IsPtr() {
                        // When -d=checkptr=2 is enabled, treat
                        // conversions to unsafe.Pointer as an
                        // escaping operation. This allows better
@@ -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.Etype == TUNSAFEPTR && n.Left.Type.Etype == TUINTPTR {
+               } else if n.Type.IsUnsafePtr() && n.Left.Type.Etype == TUINTPTR {
                        e.unsafeValue(k, n.Left)
                } else {
                        e.expr(k, n.Left)
@@ -625,7 +625,7 @@ func (e *Escape) unsafeValue(k EscHole, n *Node) {
 
        switch n.Op {
        case OCONV, OCONVNOP:
-               if n.Left.Type.Etype == TUNSAFEPTR {
+               if n.Left.Type.IsUnsafePtr() {
                        e.expr(k, n.Left)
                } else {
                        e.discard(n.Left)
index 52083d999e544b9807a3581ea98ee84a00c1b112..89644cd3f269fa5e3e4ca7cab9967b1063f1597a 100644 (file)
@@ -2113,7 +2113,7 @@ func (s *state) expr(n *Node) *ssa.Value {
                }
 
                // unsafe.Pointer <--> *T
-               if to.Etype == TUNSAFEPTR && from.IsPtrShaped() || from.Etype == TUNSAFEPTR && to.IsPtrShaped() {
+               if to.IsUnsafePtr() && from.IsPtrShaped() || from.IsUnsafePtr() && to.IsPtrShaped() {
                        return v
                }
 
index 8fa3fca50f5dd32cda675721969d118c8dfa1d06..6d0a40c287d74b1efa5b598e4ef176c4c6484624 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.Etype == TUNSAFEPTR {
+       if (src.IsPtr() || src.Etype == TUINTPTR) && dst.IsUnsafePtr() {
                return OCONVNOP
        }
 
        // 9. src is unsafe.Pointer and dst is a pointer or uintptr.
-       if src.Etype == TUNSAFEPTR && (dst.IsPtr() || dst.Etype == TUINTPTR) {
+       if src.IsUnsafePtr() && (dst.IsPtr() || dst.Etype == TUINTPTR) {
                return OCONVNOP
        }
 
index ab7f857031fc7b6e0304802d2d5dfd846bd680ba..a9fefb3ddd2edf65c2fc7f9259e872d94f214bcb 100644 (file)
@@ -958,11 +958,11 @@ opswitch:
        case OCONV, OCONVNOP:
                n.Left = walkexpr(n.Left, init)
                if n.Op == OCONVNOP && checkPtr(Curfn, 1) {
-                       if n.Type.IsPtr() && n.Left.Type.Etype == TUNSAFEPTR { // unsafe.Pointer to *T
+                       if n.Type.IsPtr() && n.Left.Type.IsUnsafePtr() { // unsafe.Pointer to *T
                                n = walkCheckPtrAlignment(n, init, nil)
                                break
                        }
-                       if n.Type.Etype == TUNSAFEPTR && n.Left.Type.Etype == TUINTPTR { // uintptr to unsafe.Pointer
+                       if n.Type.IsUnsafePtr() && n.Left.Type.Etype == TUINTPTR { // uintptr to unsafe.Pointer
                                n = walkCheckPtrArithmetic(n, init)
                                break
                        }
@@ -1127,7 +1127,7 @@ opswitch:
                n.List.SetSecond(walkexpr(n.List.Second(), init))
 
        case OSLICE, OSLICEARR, OSLICESTR, OSLICE3, OSLICE3ARR:
-               checkSlice := checkPtr(Curfn, 1) && n.Op == OSLICE3ARR && n.Left.Op == OCONVNOP && n.Left.Left.Type.Etype == TUNSAFEPTR
+               checkSlice := checkPtr(Curfn, 1) && n.Op == OSLICE3ARR && n.Left.Op == OCONVNOP && n.Left.Left.Type.IsUnsafePtr()
                if checkSlice {
                        n.Left.Left = walkexpr(n.Left.Left, init)
                } else {
@@ -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.Etype == TUNSAFEPTR {
+               if !isBuiltinCall && arg.Op == OCONVNOP && arg.Type.Etype == TUINTPTR && arg.Left.Type.IsUnsafePtr() {
                        origArgs[i] = arg
                        arg = arg.Left
                        n.List.SetIndex(i, arg)
@@ -4041,7 +4041,7 @@ func walkCheckPtrArithmetic(n *Node, init *Nodes) *Node {
                                walk(n.Left)
                        }
                case OCONVNOP:
-                       if n.Left.Type.Etype == TUNSAFEPTR {
+                       if n.Left.Type.IsUnsafePtr() {
                                n.Left = cheapexpr(n.Left, init)
                                originals = append(originals, convnop(n.Left, types.Types[TUNSAFEPTR]))
                        }