Skip to content

Commit

Permalink
compiler: mark the source argument to the append builtin as not escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
eliasnaur committed Nov 1, 2024
1 parent 0edeaf6 commit ed2a14e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions compiler/symbol.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ func (c *compilerContext) getFunction(fn *ssa.Function) (llvm.Type, llvm.Value)
// > allocsize argument to signify "not present."
llvmFn.AddFunctionAttr(c.ctx.CreateEnumAttribute(llvm.AttributeKindID("allocsize"), 0x0000_0000_ffff_ffff))
case "runtime.sliceAppend":
// The slice doesn't escape.
llvmFn.AddAttributeAtIndex(1, c.ctx.CreateEnumAttribute(llvm.AttributeKindID("nocapture"), 0))
// Appending a slice will only read the to-be-appended slice, it won't
// be modified.
llvmFn.AddAttributeAtIndex(2, c.ctx.CreateEnumAttribute(llvm.AttributeKindID("nocapture"), 0))
Expand Down
2 changes: 1 addition & 1 deletion transform/testdata/allocs2.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func main() {
s4 := make([]byte, 300) // OUT: object allocated on the heap: object size 300 exceeds maximum stack allocation size 256
readByteSlice(s4)

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

s6 := make([]int, 3)
Expand Down

0 comments on commit ed2a14e

Please sign in to comment.