Skip to content

Commit 9cf8833

Browse files
committed
cmd/compile: consistently use Type.IsUnsafePtr()
Passes toolstash-check. Change-Id: Iaeae7cc20e26af733642c7c8c7ca0a059e5b07b2 Reviewed-on: https://go-review.googlesource.com/c/go/+/253657 Run-TryBot: Cuong Manh Le <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]>
1 parent bdb480f commit 9cf8833

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

src/cmd/compile/internal/gc/escape.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,15 +485,15 @@ func (e *Escape) exprSkipInit(k EscHole, n *Node) {
485485
e.discard(max)
486486

487487
case OCONV, OCONVNOP:
488-
if checkPtr(e.curfn, 2) && n.Type.Etype == TUNSAFEPTR && n.Left.Type.IsPtr() {
488+
if checkPtr(e.curfn, 2) && n.Type.IsUnsafePtr() && n.Left.Type.IsPtr() {
489489
// When -d=checkptr=2 is enabled, treat
490490
// conversions to unsafe.Pointer as an
491491
// escaping operation. This allows better
492492
// runtime instrumentation, since we can more
493493
// easily detect object boundaries on the heap
494494
// than the stack.
495495
e.assignHeap(n.Left, "conversion to unsafe.Pointer", n)
496-
} else if n.Type.Etype == TUNSAFEPTR && n.Left.Type.Etype == TUINTPTR {
496+
} else if n.Type.IsUnsafePtr() && n.Left.Type.Etype == TUINTPTR {
497497
e.unsafeValue(k, n.Left)
498498
} else {
499499
e.expr(k, n.Left)
@@ -625,7 +625,7 @@ func (e *Escape) unsafeValue(k EscHole, n *Node) {
625625

626626
switch n.Op {
627627
case OCONV, OCONVNOP:
628-
if n.Left.Type.Etype == TUNSAFEPTR {
628+
if n.Left.Type.IsUnsafePtr() {
629629
e.expr(k, n.Left)
630630
} else {
631631
e.discard(n.Left)

src/cmd/compile/internal/gc/ssa.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2113,7 +2113,7 @@ func (s *state) expr(n *Node) *ssa.Value {
21132113
}
21142114

21152115
// unsafe.Pointer <--> *T
2116-
if to.Etype == TUNSAFEPTR && from.IsPtrShaped() || from.Etype == TUNSAFEPTR && to.IsPtrShaped() {
2116+
if to.IsUnsafePtr() && from.IsPtrShaped() || from.IsUnsafePtr() && to.IsPtrShaped() {
21172117
return v
21182118
}
21192119

src/cmd/compile/internal/gc/subr.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,12 +781,12 @@ func convertop(srcConstant bool, src, dst *types.Type, why *string) Op {
781781
}
782782

783783
// 8. src is a pointer or uintptr and dst is unsafe.Pointer.
784-
if (src.IsPtr() || src.Etype == TUINTPTR) && dst.Etype == TUNSAFEPTR {
784+
if (src.IsPtr() || src.Etype == TUINTPTR) && dst.IsUnsafePtr() {
785785
return OCONVNOP
786786
}
787787

788788
// 9. src is unsafe.Pointer and dst is a pointer or uintptr.
789-
if src.Etype == TUNSAFEPTR && (dst.IsPtr() || dst.Etype == TUINTPTR) {
789+
if src.IsUnsafePtr() && (dst.IsPtr() || dst.Etype == TUINTPTR) {
790790
return OCONVNOP
791791
}
792792

src/cmd/compile/internal/gc/walk.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -958,11 +958,11 @@ opswitch:
958958
case OCONV, OCONVNOP:
959959
n.Left = walkexpr(n.Left, init)
960960
if n.Op == OCONVNOP && checkPtr(Curfn, 1) {
961-
if n.Type.IsPtr() && n.Left.Type.Etype == TUNSAFEPTR { // unsafe.Pointer to *T
961+
if n.Type.IsPtr() && n.Left.Type.IsUnsafePtr() { // unsafe.Pointer to *T
962962
n = walkCheckPtrAlignment(n, init, nil)
963963
break
964964
}
965-
if n.Type.Etype == TUNSAFEPTR && n.Left.Type.Etype == TUINTPTR { // uintptr to unsafe.Pointer
965+
if n.Type.IsUnsafePtr() && n.Left.Type.Etype == TUINTPTR { // uintptr to unsafe.Pointer
966966
n = walkCheckPtrArithmetic(n, init)
967967
break
968968
}
@@ -1127,7 +1127,7 @@ opswitch:
11271127
n.List.SetSecond(walkexpr(n.List.Second(), init))
11281128

11291129
case OSLICE, OSLICEARR, OSLICESTR, OSLICE3, OSLICE3ARR:
1130-
checkSlice := checkPtr(Curfn, 1) && n.Op == OSLICE3ARR && n.Left.Op == OCONVNOP && n.Left.Left.Type.Etype == TUNSAFEPTR
1130+
checkSlice := checkPtr(Curfn, 1) && n.Op == OSLICE3ARR && n.Left.Op == OCONVNOP && n.Left.Left.Type.IsUnsafePtr()
11311131
if checkSlice {
11321132
n.Left.Left = walkexpr(n.Left.Left, init)
11331133
} else {
@@ -3886,7 +3886,7 @@ func wrapCall(n *Node, init *Nodes) *Node {
38863886
t := nod(OTFUNC, nil, nil)
38873887
for i, arg := range n.List.Slice() {
38883888
s := lookupN("a", i)
3889-
if !isBuiltinCall && arg.Op == OCONVNOP && arg.Type.Etype == TUINTPTR && arg.Left.Type.Etype == TUNSAFEPTR {
3889+
if !isBuiltinCall && arg.Op == OCONVNOP && arg.Type.Etype == TUINTPTR && arg.Left.Type.IsUnsafePtr() {
38903890
origArgs[i] = arg
38913891
arg = arg.Left
38923892
n.List.SetIndex(i, arg)
@@ -4041,7 +4041,7 @@ func walkCheckPtrArithmetic(n *Node, init *Nodes) *Node {
40414041
walk(n.Left)
40424042
}
40434043
case OCONVNOP:
4044-
if n.Left.Type.Etype == TUNSAFEPTR {
4044+
if n.Left.Type.IsUnsafePtr() {
40454045
n.Left = cheapexpr(n.Left, init)
40464046
originals = append(originals, convnop(n.Left, types.Types[TUNSAFEPTR]))
40474047
}

0 commit comments

Comments
 (0)