Skip to content

Commit 5183696

Browse files
committed
cmd/compile: add Type.IsUintptr() to detect type is an uintptr
Passes toolstash-check. Change-Id: I7051d45eafbfd4dea73a3d4b5ea6cff39d76cbc1 Reviewed-on: https://go-review.googlesource.com/c/go/+/253658 Run-TryBot: Cuong Manh Le <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]>
1 parent 9cf8833 commit 5183696

File tree

5 files changed

+13
-8
lines changed

5 files changed

+13
-8
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ func (e *Escape) paramTag(fn *Node, narg int, f *types.Field) string {
377377
// This really doesn't have much to do with escape analysis per se,
378378
// but we are reusing the ability to annotate an individual function
379379
// argument and pass those annotations along to importing code.
380-
if f.Type.Etype == TUINTPTR {
380+
if f.Type.IsUintptr() {
381381
if Debug['m'] != 0 {
382382
Warnl(f.Pos, "assuming %v is unsafe uintptr", name())
383383
}
@@ -407,13 +407,13 @@ func (e *Escape) paramTag(fn *Node, narg int, f *types.Field) string {
407407
}
408408

409409
if fn.Func.Pragma&UintptrEscapes != 0 {
410-
if f.Type.Etype == TUINTPTR {
410+
if f.Type.IsUintptr() {
411411
if Debug['m'] != 0 {
412412
Warnl(f.Pos, "marking %v as escaping uintptr", name())
413413
}
414414
return uintptrEscapesTag
415415
}
416-
if f.IsDDD() && f.Type.Elem().Etype == TUINTPTR {
416+
if f.IsDDD() && f.Type.Elem().IsUintptr() {
417417
// final argument is ...uintptr.
418418
if Debug['m'] != 0 {
419419
Warnl(f.Pos, "marking %v as escaping ...uintptr", name())

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ func (e *Escape) exprSkipInit(k EscHole, n *Node) {
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.IsUnsafePtr() && n.Left.Type.Etype == TUINTPTR {
496+
} else if n.Type.IsUnsafePtr() && n.Left.Type.IsUintptr() {
497497
e.unsafeValue(k, n.Left)
498498
} else {
499499
e.expr(k, n.Left)

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.IsUnsafePtr() {
784+
if (src.IsPtr() || src.IsUintptr()) && dst.IsUnsafePtr() {
785785
return OCONVNOP
786786
}
787787

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ opswitch:
962962
n = walkCheckPtrAlignment(n, init, nil)
963963
break
964964
}
965-
if n.Type.IsUnsafePtr() && n.Left.Type.Etype == TUINTPTR { // uintptr to unsafe.Pointer
965+
if n.Type.IsUnsafePtr() && n.Left.Type.IsUintptr() { // uintptr to unsafe.Pointer
966966
n = walkCheckPtrArithmetic(n, init)
967967
break
968968
}
@@ -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.IsUnsafePtr() {
3889+
if !isBuiltinCall && arg.Op == OCONVNOP && arg.Type.IsUintptr() && arg.Left.Type.IsUnsafePtr() {
38903890
origArgs[i] = arg
38913891
arg = arg.Left
38923892
n.List.SetIndex(i, arg)

src/cmd/compile/internal/types/type.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,11 @@ func (t *Type) IsUnsafePtr() bool {
12301230
return t.Etype == TUNSAFEPTR
12311231
}
12321232

1233+
// IsUintptr reports whether t is an uintptr.
1234+
func (t *Type) IsUintptr() bool {
1235+
return t.Etype == TUINTPTR
1236+
}
1237+
12331238
// IsPtrShaped reports whether t is represented by a single machine pointer.
12341239
// In addition to regular Go pointer types, this includes map, channel, and
12351240
// function types and unsafe.Pointer. It does not include array or struct types

0 commit comments

Comments
 (0)