Skip to content

Commit 951e50c

Browse files
dgryskideadprogram
authored andcommitted
compiler: mark stringFromRunes as nocapture/readonly
1 parent 40c9c66 commit 951e50c

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

compiler/symbol.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ func (c *compilerContext) getFunction(fn *ssa.Function) (llvm.Type, llvm.Value)
175175
case "runtime.stringFromBytes":
176176
llvmFn.AddAttributeAtIndex(1, c.ctx.CreateEnumAttribute(llvm.AttributeKindID("nocapture"), 0))
177177
llvmFn.AddAttributeAtIndex(1, c.ctx.CreateEnumAttribute(llvm.AttributeKindID("readonly"), 0))
178+
case "runtime.stringFromRunes":
179+
llvmFn.AddAttributeAtIndex(1, c.ctx.CreateEnumAttribute(llvm.AttributeKindID("nocapture"), 0))
180+
llvmFn.AddAttributeAtIndex(1, c.ctx.CreateEnumAttribute(llvm.AttributeKindID("readonly"), 0))
178181
case "runtime.trackPointer":
179182
// This function is necessary for tracking pointers on the stack in a
180183
// portable way (see gc_stack_portable.go). Indicate to the optimizer

transform/testdata/allocs2.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ func main() {
5454
var buf [32]byte
5555
s := string(buf[:])
5656
println(len(s))
57+
58+
var rbuf [5]rune
59+
s = string(rbuf[:])
60+
println(s)
5761
}
5862

5963
func derefInt(x *int) int {

0 commit comments

Comments
 (0)