Skip to content

Commit

Permalink
compiler: mark stringFromRunes as nocapture/readonly
Browse files Browse the repository at this point in the history
  • Loading branch information
dgryski authored and deadprogram committed Oct 19, 2024
1 parent 40c9c66 commit 951e50c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions compiler/symbol.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ func (c *compilerContext) getFunction(fn *ssa.Function) (llvm.Type, llvm.Value)
case "runtime.stringFromBytes":
llvmFn.AddAttributeAtIndex(1, c.ctx.CreateEnumAttribute(llvm.AttributeKindID("nocapture"), 0))
llvmFn.AddAttributeAtIndex(1, c.ctx.CreateEnumAttribute(llvm.AttributeKindID("readonly"), 0))
case "runtime.stringFromRunes":
llvmFn.AddAttributeAtIndex(1, c.ctx.CreateEnumAttribute(llvm.AttributeKindID("nocapture"), 0))
llvmFn.AddAttributeAtIndex(1, c.ctx.CreateEnumAttribute(llvm.AttributeKindID("readonly"), 0))
case "runtime.trackPointer":
// This function is necessary for tracking pointers on the stack in a
// portable way (see gc_stack_portable.go). Indicate to the optimizer
Expand Down
4 changes: 4 additions & 0 deletions transform/testdata/allocs2.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ func main() {
var buf [32]byte
s := string(buf[:])
println(len(s))

var rbuf [5]rune
s = string(rbuf[:])
println(s)
}

func derefInt(x *int) int {
Expand Down

0 comments on commit 951e50c

Please sign in to comment.