Skip to content

Commit ed2a14e

Browse files
committed
compiler: mark the source argument to the append builtin as not escaping
1 parent 0edeaf6 commit ed2a14e

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

compiler/symbol.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ func (c *compilerContext) getFunction(fn *ssa.Function) (llvm.Type, llvm.Value)
163163
// > allocsize argument to signify "not present."
164164
llvmFn.AddFunctionAttr(c.ctx.CreateEnumAttribute(llvm.AttributeKindID("allocsize"), 0x0000_0000_ffff_ffff))
165165
case "runtime.sliceAppend":
166+
// The slice doesn't escape.
167+
llvmFn.AddAttributeAtIndex(1, c.ctx.CreateEnumAttribute(llvm.AttributeKindID("nocapture"), 0))
166168
// Appending a slice will only read the to-be-appended slice, it won't
167169
// be modified.
168170
llvmFn.AddAttributeAtIndex(2, c.ctx.CreateEnumAttribute(llvm.AttributeKindID("nocapture"), 0))

transform/testdata/allocs2.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func main() {
2323
s4 := make([]byte, 300) // OUT: object allocated on the heap: object size 300 exceeds maximum stack allocation size 256
2424
readByteSlice(s4)
2525

26-
s5 := make([]int, 4) // OUT: object allocated on the heap: escapes at line 27
26+
s5 := make([]int, 4)
2727
_ = append(s5, 5)
2828

2929
s6 := make([]int, 3)

0 commit comments

Comments
 (0)