aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDamian Gryski <[email protected]>2024-10-18 12:17:38 -0700
committerRon Evans <[email protected]>2024-10-19 11:02:54 +0100
commit951e50c06fc617e9a45caddc62b76b88f86200a2 (patch)
tree04b90783776c54d9de805d518d6b44c34cbf50cb
parent40c9c66c1d6d758157fbc8163cc48e8cdecd85b9 (diff)
downloadtinygo-951e50c06fc617e9a45caddc62b76b88f86200a2.tar.gz
tinygo-951e50c06fc617e9a45caddc62b76b88f86200a2.zip
compiler: mark stringFromRunes as nocapture/readonly
-rw-r--r--compiler/symbol.go3
-rw-r--r--transform/testdata/allocs2.go4
2 files changed, 7 insertions, 0 deletions
diff --git a/compiler/symbol.go b/compiler/symbol.go
index 5447e0dba..e175bdd78 100644
--- a/compiler/symbol.go
+++ b/compiler/symbol.go
@@ -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
diff --git a/transform/testdata/allocs2.go b/transform/testdata/allocs2.go
index 13c460231..299df5b21 100644
--- a/transform/testdata/allocs2.go
+++ b/transform/testdata/allocs2.go
@@ -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 {