Files
gcc-reflection/gcc/testsuite/go.dg/cmpstring.go
Cherry Zhang 3407d1658f compiler: avoid copy for string([]byte) conversion used in string comparison
If a string([]byte) conversion is used immediately in a string
    comparison, we don't need to copy the backing store of the byte
    slice, as the string comparison doesn't hold any reference to
    it. Instead, just create a string header from the byte slice and
    pass it for comparison.
    
    A new type of expression, String_value_expression, is introduced,
    for constructing string headers.
    
    Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/170894

	* go.dg/cmpstring.go: New test.

From-SVN: r271021
2019-05-08 23:06:52 +00:00

14 lines
363 B
Go

// { dg-do compile }
// { dg-options "-fgo-debug-optimization" }
package p
func F(x []byte, y string) bool {
return string(x) == y // { dg-error "no copy string\\(\\\[\\\]byte\\)" }
}
func BytesEqual(x, y []byte) bool {
return string(x) == // { dg-error "no copy string\\(\\\[\\\]byte\\)" }
string(y) // { dg-error "no copy string\\(\\\[\\\]byte\\)" }
}