import (
"runtime"
+ "strings"
"testing"
)
}
}
}
+
+func TestLargeStringConcat(t *testing.T) {
+ output := executeTest(t, largeStringConcatSource, nil)
+ want := "panic: " + strings.Repeat("0", 1<<10) + strings.Repeat("1", 1<<10) +
+ strings.Repeat("2", 1<<10) + strings.Repeat("3", 1<<10)
+ if !strings.HasPrefix(output, want) {
+ t.Fatalf("output does not start with %q:\n%s", want, output)
+ }
+}
+
+var largeStringConcatSource = `
+package main
+import "strings"
+func main() {
+ s0 := strings.Repeat("0", 1<<10)
+ s1 := strings.Repeat("1", 1<<10)
+ s2 := strings.Repeat("2", 1<<10)
+ s3 := strings.Repeat("3", 1<<10)
+ s := s0 + s1 + s2 + s3
+ panic(s)
+}
+`
#pragma textflag NOSPLIT
func rawstring(size intgo) (s String, b Slice) {
+ uintptr ms;
byte *p;
p = runtime·mallocgc(size, 0, FlagNoScan|FlagNoZero);
b.array = p;
b.len = size;
b.cap = size;
+ for(;;) {
+ ms = runtime·maxstring;
+ if((uintptr)size <= ms || runtime·casp((void**)&runtime·maxstring, (void*)ms, (void*)size))
+ break;
+ }
}
#pragma textflag NOSPLIT