compiler: avoid copy for string([]byte) conversion used in string concatenation

If a string([]byte) conversion is used immediately in a string
concatenation, we don't need to copy the backing store of the
byte slice, as the runtime function doesn't hold any reference
to it.

A test could be added in the GCC testsuite:

Index: gcc/testsuite/go.dg/concatstring.go
===================================================================
--- gcc/testsuite/go.dg/concatstring.go	(nonexistent)
+++ gcc/testsuite/go.dg/concatstring.go	(working copy)
@@ -0,0 +1,8 @@
+// { dg-do compile }
+// { dg-options "-fgo-debug-optimization" }
+
+package p
+
+func F(b []byte, x string) string {
+	return "hello " + string(b) + x // { dg-error "no copy string\\(\\\[\\\]byte\\)" }
+}

Change-Id: I1c2d13da6a30aca825aa42964a959452c7f50aaf
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/182437
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
1 file changed