Skip to content

Commit e5847b2

Browse files
committed
update, based on review comments
Change-Id: I6175d154af235a31dd1c985827b99bdd7c0ac993
1 parent 1bacc01 commit e5847b2

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

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

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,19 +222,14 @@ func HeapAllocReason(n ir.Node) string {
222222
n.Cap = s
223223
}
224224
}
225-
}
226-
if n.Len != nil {
225+
} else if n.Len != nil {
227226
if s := ir.StaticValue(n.Len); s.Op() == ir.OLITERAL {
228227
len, ok := s.(*ir.BasicLit)
229228
if !ok || len.Val().Kind() != constant.Int {
230229
base.Fatalf("unexpected BasicLit Kind")
231230
}
232-
233231
if constant.Compare(len.Val(), token.GEQ, constant.MakeInt64(0)) {
234-
cap, ok := n.Cap.(*ir.BasicLit)
235-
if n.Cap == nil || (ok && constant.Compare(cap.Val(), token.GEQ, len.Val())) {
236-
n.Len = s
237-
}
232+
n.Len = s
238233
}
239234
}
240235
}

test/escape_make_non_const.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,44 +14,44 @@ var globalVarSize = 128
1414
func testSlices() {
1515
{
1616
size := 128
17-
_ = make([]byte, size) // ERROR "does not escape"
17+
_ = make([]byte, size) // ERROR "make\(\[\]byte, 128\) does not escape"
1818
}
1919

2020
{
2121
s := 128
2222
size := s
23-
_ = make([]byte, size) // ERROR "does not escape"
23+
_ = make([]byte, size) // ERROR "make\(\[\]byte, 128\) does not escape"
2424
}
2525

2626
{
2727
size := 128
28-
_ = make([]byte, 0, size) // ERROR "does not escape"
28+
_ = make([]byte, size) // ERROR "make\(\[\]byte, 128\) does not escape"
2929
}
3030

3131
{
3232
s := 128
3333
size := s
34-
_ = make([]byte, 0, size) // ERROR "does not escape"
34+
_ = make([]byte, size) // ERROR "make\(\[\]byte, 128\) does not escape"
3535
}
3636

3737
{
3838
s1 := 128
3939
s2 := 256
40-
_ = make([]byte, s2, s1) // ERROR "does not escape"
40+
_ = make([]byte, s2, s1) // ERROR "make\(\[\]byte, s2, 128\) does not escape"
4141
}
4242

43-
allocLen(256) // ERROR "does not escape" "inlining call"
44-
allocCap(256) // ERROR "does not escape" "inlining call"
45-
_ = newT(256) // ERROR "does not escape" "inlining call"
43+
allocLen(256) // ERROR "make\(\[\]byte, 256\) does not escape" "inlining call"
44+
allocCap(256) // ERROR "make\(\[\]byte, 0, 256\) does not escape" "inlining call"
45+
_ = newT(256) // ERROR "make\(\[\]byte, 256\) does not escape" "inlining call"
4646

4747
{
4848
size := globalConstSize
49-
_ = make([]byte, size) // ERROR "does not escape"
49+
_ = make([]byte, size) // ERROR "make\(\[\]byte, 128\) does not escape"
5050
}
5151

52-
allocLen(globalConstSize) // ERROR "does not escape" "inlining call"
53-
allocCap(globalConstSize) // ERROR "does not escape" "inlining call"
54-
_ = newT(globalConstSize) // ERROR "does not escape" "inlining call"
52+
allocLen(globalConstSize) // ERROR "make\(\[\]byte, 128\) does not escape" "inlining call"
53+
allocCap(globalConstSize) // ERROR "make\(\[\]byte, 0, 128\) does not escape" "inlining call"
54+
_ = newT(globalConstSize) // ERROR "make\(\[\]byte, 128\) does not escape" "inlining call"
5555

5656
{
5757
c := 128
@@ -65,7 +65,8 @@ func testSlices() {
6565
}
6666

6767
{
68-
_ = make([]byte, globalVarSize) // ERROR "escapes to heap"
68+
_ = make([]byte, globalVarSize) // ERROR "make\(\[\]byte, globalVarSize\) escapes to heap"
69+
_ = make([]byte, globalVarSize, globalConstSize) // ERROR "make\(\[\]byte, globalVarSize, 128\) does not escape"
6970
}
7071
}
7172

0 commit comments

Comments
 (0)