diff options
author | Cherry Zhang <cherryyz@google.com> | 2020-10-28 09:12:20 -0400 |
---|---|---|
committer | Cherry Zhang <cherryyz@google.com> | 2020-10-28 09:12:20 -0400 |
commit | a16e30d162c1c7408db7821e7b9513cefa09c6ca (patch) | |
tree | af752ba9ba44c547df39bb0af9bff79f610ba9d5 /test | |
parent | 91e4d2d57bc341dd82c98247117114c851380aef (diff) | |
parent | cf6cfba4d5358404dd890f6025e573a4b2156543 (diff) | |
download | go-git-dev.link.tar.gz |
[dev.link] all: merge branch 'master' into dev.linkdev.link
Clean merge.
Change-Id: Ia7b2808bc649790198d34c226a61d9e569084dc5
Diffstat (limited to 'test')
27 files changed, 533 insertions, 58 deletions
diff --git a/test/bounds.go b/test/bounds.go index 34c444877b..aa1d51b6f9 100644 --- a/test/bounds.go +++ b/test/bounds.go @@ -201,6 +201,20 @@ func main() { use(p1k[ui&1000]) use(p100k[ui&1000]) // ERROR "index bounds check elided" + use(a1[i&^-1]) // ERROR "index bounds check elided" + use(a1[i&^0]) + use(a1[i&^-2]) + use(a1[i&^1]) + use(a1k[i&^-1]) // ERROR "index bounds check elided" + use(a1k[i&^0]) + use(a1k[i&^-2]) // ERROR "index bounds check elided" + use(a1k[i&^1]) + use(a1k[i8&^0]) + use(a1k[i8&^-128]) // ERROR "index bounds check elided" + use(a1k[ui8&^1]) // ERROR "index bounds check elided" + use(a1k[ui16&^0xf000]) + use(a1k[ui16&^0xff00]) // ERROR "index bounds check elided" + // Right shift cuts the effective number of bits in the index, // but only for unsigned (signed stays negative). use(s[i32>>22]) diff --git a/test/closure3.dir/main.go b/test/closure3.dir/main.go index 3ec90139a3..5694673f1e 100644 --- a/test/closure3.dir/main.go +++ b/test/closure3.dir/main.go @@ -238,8 +238,7 @@ func main() { if c != 4 { ppanic("c != 4") } - for i := 0; i < 10; i++ { // prevent inlining - } + recover() // prevent inlining }() }() if c != 4 { diff --git a/test/codegen/floats.go b/test/codegen/floats.go index 3fae1a327c..83b4a358a5 100644 --- a/test/codegen/floats.go +++ b/test/codegen/floats.go @@ -6,8 +6,6 @@ package codegen -import "math" - // This file contains codegen tests related to arithmetic // simplifications and optimizations on float types. // For codegen tests on integer types, see arithmetic.go. @@ -18,7 +16,6 @@ import "math" func Mul2(f float64) float64 { // 386/sse2:"ADDSD",-"MULSD" - // 386/387:"FADDDP",-"FMULDP" // amd64:"ADDSD",-"MULSD" // arm/7:"ADDD",-"MULD" // arm64:"FADDD",-"FMULD" @@ -29,7 +26,6 @@ func Mul2(f float64) float64 { func DivPow2(f1, f2, f3 float64) (float64, float64, float64) { // 386/sse2:"MULSD",-"DIVSD" - // 386/387:"FMULDP",-"FDIVDP" // amd64:"MULSD",-"DIVSD" // arm/7:"MULD",-"DIVD" // arm64:"FMULD",-"FDIVD" @@ -38,7 +34,6 @@ func DivPow2(f1, f2, f3 float64) (float64, float64, float64) { x := f1 / 16.0 // 386/sse2:"MULSD",-"DIVSD" - // 386/387:"FMULDP",-"FDIVDP" // amd64:"MULSD",-"DIVSD" // arm/7:"MULD",-"DIVD" // arm64:"FMULD",-"FDIVD" @@ -47,7 +42,6 @@ func DivPow2(f1, f2, f3 float64) (float64, float64, float64) { y := f2 / 0.125 // 386/sse2:"ADDSD",-"DIVSD",-"MULSD" - // 386/387:"FADDDP",-"FDIVDP",-"FMULDP" // amd64:"ADDSD",-"DIVSD",-"MULSD" // arm/7:"ADDD",-"MULD",-"DIVD" // arm64:"FADDD",-"FMULD",-"FDIVD" @@ -58,11 +52,6 @@ func DivPow2(f1, f2, f3 float64) (float64, float64, float64) { return x, y, z } -func getPi() float64 { - // 386/387:"FLDPI" - return math.Pi -} - func indexLoad(b0 []float32, b1 float32, idx int) float32 { // arm64:`FMOVS\s\(R[0-9]+\)\(R[0-9]+\),\sF[0-9]+` return b0[idx] * b1 diff --git a/test/codegen/math.go b/test/codegen/math.go index 1ebfda0405..ac8071400e 100644 --- a/test/codegen/math.go +++ b/test/codegen/math.go @@ -46,7 +46,7 @@ func approx(x float64) { func sqrt(x float64) float64 { // amd64:"SQRTSD" - // 386/387:"FSQRT" 386/sse2:"SQRTSD" + // 386/sse2:"SQRTSD" 386/softfloat:-"SQRTD" // arm64:"FSQRTD" // arm/7:"SQRTD" // mips/hardfloat:"SQRTD" mips/softfloat:-"SQRTD" diff --git a/test/codegen/rotate.go b/test/codegen/rotate.go index ce24b57877..0c8b030970 100644 --- a/test/codegen/rotate.go +++ b/test/codegen/rotate.go @@ -6,6 +6,8 @@ package codegen +import "math/bits" + // ------------------- // // const rotates // // ------------------- // @@ -166,3 +168,46 @@ func f32(x uint32) uint32 { // amd64:"ROLL\t[$]7" return rot32nc(x, 7) } + +// --------------------------------------- // +// Combined Rotate + Masking operations // +// --------------------------------------- // + +func checkMaskedRotate32(a []uint32, r int) { + i := 0 + + // ppc64le: "RLWNM\t[$]16, R[0-9]+, [$]16711680, R[0-9]+" + // ppc64: "RLWNM\t[$]16, R[0-9]+, [$]16711680, R[0-9]+" + a[i] = bits.RotateLeft32(a[i], 16) & 0xFF0000 + i++ + // ppc64le: "RLWNM\t[$]16, R[0-9]+, [$]16711680, R[0-9]+" + // ppc64: "RLWNM\t[$]16, R[0-9]+, [$]16711680, R[0-9]+" + a[i] = bits.RotateLeft32(a[i]&0xFF, 16) + i++ + // ppc64le: "RLWNM\t[$]4, R[0-9]+, [$]4080, R[0-9]+" + // ppc64: "RLWNM\t[$]4, R[0-9]+, [$]4080, R[0-9]+" + a[i] = bits.RotateLeft32(a[i], 4) & 0xFF0 + i++ + // ppc64le: "RLWNM\t[$]16, R[0-9]+, [$]255, R[0-9]+" + // ppc64: "RLWNM\t[$]16, R[0-9]+, [$]255, R[0-9]+" + a[i] = bits.RotateLeft32(a[i]&0xFF0000, 16) + i++ + + // ppc64le: "RLWNM\tR[0-9]+, R[0-9]+, [$]16711680, R[0-9]+" + // ppc64: "RLWNM\tR[0-9]+, R[0-9]+, [$]16711680, R[0-9]+" + a[i] = bits.RotateLeft32(a[i], r) & 0xFF0000 + i++ + // ppc64le: "RLWNM\tR[0-9]+, R[0-9]+, [$]65280, R[0-9]+" + // ppc64: "RLWNM\tR[0-9]+, R[0-9]+, [$]65280, R[0-9]+" + a[i] = bits.RotateLeft32(a[3], r) & 0xFF00 + i++ + + // ppc64le: "RLWNM\tR[0-9]+, R[0-9]+, [$]4293922815, R[0-9]+" + // ppc64: "RLWNM\tR[0-9]+, R[0-9]+, [$]4293922815, R[0-9]+" + a[i] = bits.RotateLeft32(a[3], r) & 0xFFF00FFF + i++ + // ppc64le: "RLWNM\t[$]4, R[0-9]+, [$]4293922815, R[0-9]+" + // ppc64: "RLWNM\t[$]4, R[0-9]+, [$]4293922815, R[0-9]+" + a[i] = bits.RotateLeft32(a[3], 4) & 0xFFF00FFF + i++ +} diff --git a/test/codegen/shift.go b/test/codegen/shift.go index abc4b091c9..a45f27c9cf 100644 --- a/test/codegen/shift.go +++ b/test/codegen/shift.go @@ -156,29 +156,29 @@ func checkUnneededTrunc(tab *[100000]uint32, d uint64, v uint32, h uint16, b byt // ppc64:-".*RLWINM",-".*RLDICR",".*CLRLSLDI" f := tab[byte(v)^b] // ppc64le:-".*RLWINM",-".*RLDICR",".*CLRLSLDI" - // ppc64:-".*RLWINM",-".*RLDICR",".*CLRLSLDI" + // ppc64:-".*RLWINM",-".*RLDICR",".*CLRLSLDI" f += tab[byte(v)&b] // ppc64le:-".*RLWINM",-".*RLDICR",".*CLRLSLDI" - // ppc64:-".*RLWINM",-".*RLDICR",".*CLRLSLDI" + // ppc64:-".*RLWINM",-".*RLDICR",".*CLRLSLDI" f += tab[byte(v)|b] // ppc64le:-".*RLWINM",-".*RLDICR",".*CLRLSLDI" - // ppc64:-".*RLWINM",-".*RLDICR",".*CLRLSLDI" + // ppc64:-".*RLWINM",-".*RLDICR",".*CLRLSLDI" f += tab[uint16(v)&h] // ppc64le:-".*RLWINM",-".*RLDICR",".*CLRLSLDI" - // ppc64:-".*RLWINM",-".*RLDICR",".*CLRLSLDI" + // ppc64:-".*RLWINM",-".*RLDICR",".*CLRLSLDI" f += tab[uint16(v)^h] // ppc64le:-".*RLWINM",-".*RLDICR",".*CLRLSLDI" - // ppc64:-".*RLWINM",-".*RLDICR",".*CLRLSLDI" + // ppc64:-".*RLWINM",-".*RLDICR",".*CLRLSLDI" f += tab[uint16(v)|h] // ppc64le:-".*AND",-"RLDICR",".*CLRLSLDI" // ppc64:-".*AND",-"RLDICR",".*CLRLSLDI" f += tab[v&0xff] // ppc64le:-".*AND",".*CLRLSLWI" - // ppc64:-".*AND",".*CLRLSLWI" - f += 2*uint32(uint16(d)) + // ppc64:-".*AND",".*CLRLSLWI" + f += 2 * uint32(uint16(d)) // ppc64le:-".*AND",-"RLDICR",".*CLRLSLDI" // ppc64:-".*AND",-"RLDICR",".*CLRLSLDI" - g := 2*uint64(uint32(d)) + g := 2 * uint64(uint32(d)) return f, g } @@ -186,47 +186,102 @@ func checkCombinedShifts(v8 uint8, v16 uint16, v32 uint32, x32 int32, v64 uint64 // ppc64le:-"AND","CLRLSLWI" // ppc64:-"AND","CLRLSLWI" - f := (v8 &0xF) << 2 - // ppc64le:-"AND","CLRLSLWI" - // ppc64:-"AND","CLRLSLWI" - f += byte(v16)<<3 + f := (v8 & 0xF) << 2 + // ppc64le:"CLRLSLWI" + // ppc64:"CLRLSLWI" + f += byte(v16) << 3 // ppc64le:-"AND","CLRLSLWI" // ppc64:-"AND","CLRLSLWI" g := (v16 & 0xFF) << 3 // ppc64le:-"AND","CLRLSLWI" // ppc64:-"AND","CLRLSLWI" h := (v32 & 0xFFFFF) << 2 - // ppc64le:-"AND","CLRLSLWI" - // ppc64:-"AND","CLRLSLWI" - h += uint32(v64)<<4 - // ppc64le:-"AND","CLRLSLDI" - // ppc64:-"AND","CLRLSLDI" + // ppc64le:"CLRLSLDI" + // ppc64:"CLRLSLDI" i := (v64 & 0xFFFFFFFF) << 5 + // ppc64le:-"CLRLSLDI" + // ppc64:-"CLRLSLDI" + i += (v64 & 0xFFFFFFF) << 38 + // ppc64le/power9:-"CLRLSLDI" + // ppc64/power9:-"CLRLSLDI" + i += (v64 & 0xFFFF00) << 10 // ppc64le/power9:-"SLD","EXTSWSLI" // ppc64/power9:-"SLD","EXTSWSLI" - j := int64(x32+32)*8 + j := int64(x32+32) * 8 return f, g, h, i, j } func checkWidenAfterShift(v int64, u uint64) (int64, uint64) { // ppc64le:-".*MOVW" - f := int32(v>>32) + f := int32(v >> 32) // ppc64le:".*MOVW" - f += int32(v>>31) + f += int32(v >> 31) // ppc64le:-".*MOVH" - g := int16(v>>48) + g := int16(v >> 48) // ppc64le:".*MOVH" - g += int16(v>>30) + g += int16(v >> 30) // ppc64le:-".*MOVH" - g += int16(f>>16) + g += int16(f >> 16) // ppc64le:-".*MOVB" - h := int8(v>>56) + h := int8(v >> 56) // ppc64le:".*MOVB" - h += int8(v>>28) + h += int8(v >> 28) // ppc64le:-".*MOVB" - h += int8(f>>24) + h += int8(f >> 24) // ppc64le:".*MOVB" - h += int8(f>>16) - return int64(h),uint64(g) + h += int8(f >> 16) + return int64(h), uint64(g) +} + +func checkShiftAndMask32(v []uint32) { + i := 0 + + // ppc64le: "RLWNM\t[$]24, R[0-9]+, [$]1044480, R[0-9]+" + // ppc64: "RLWNM\t[$]24, R[0-9]+, [$]1044480, R[0-9]+" + v[i] = (v[i] & 0xFF00000) >> 8 + i++ + // ppc64le: "RLWNM\t[$]26, R[0-9]+, [$]1020, R[0-9]+" + // ppc64: "RLWNM\t[$]26, R[0-9]+, [$]1020, R[0-9]+" + v[i] = (v[i] & 0xFF00) >> 6 + i++ + // ppc64le: "MOVW\tR0" + // ppc64: "MOVW\tR0" + v[i] = (v[i] & 0xFF) >> 8 + i++ + // ppc64le: "MOVW\tR0" + // ppc64: "MOVW\tR0" + v[i] = (v[i] & 0xF000000) >> 28 + i++ + // ppc64le: "RLWNM\t[$]26, R[0-9]+, [$]255, R[0-9]+" + // ppc64: "RLWNM\t[$]26, R[0-9]+, [$]255, R[0-9]+" + v[i] = (v[i] >> 6) & 0xFF + i++ + // ppc64le: "RLWNM\t[$]26, R[0-9]+, [$]1044480, R[0-9]+" + // ppc64: "RLWNM\t[$]26, R[0-9]+, [$]1044480, R[0-9]+" + v[i] = (v[i] >> 6) & 0xFF000 + i++ + // ppc64le: "MOVW\tR0" + // ppc64: "MOVW\tR0" + v[i] = (v[i] >> 20) & 0xFF000 + i++ + // ppc64le: "MOVW\tR0" + // ppc64: "MOVW\tR0" + v[i] = (v[i] >> 24) & 0xFF00 + i++ +} + +func checkMergedShifts32(a [256]uint32, b [256]uint64, u uint32, v uint32) { + //ppc64le: -"CLRLSLDI", "RLWNM\t[$]10, R[0-9]+, [$]1020, R[0-9]+" + //ppc64: -"CLRLSLDI", "RLWNM\t[$]10, R[0-9]+, [$]1020, R[0-9]+" + a[0] = a[uint8(v>>24)] + //ppc64le: -"CLRLSLDI", "RLWNM\t[$]11, R[0-9]+, [$]2040, R[0-9]+" + //ppc64: -"CLRLSLDI", "RLWNM\t[$]11, R[0-9]+, [$]2040, R[0-9]+" + b[0] = b[uint8(v>>24)] + //ppc64le: -"CLRLSLDI", "RLWNM\t[$]15, R[0-9]+, [$]2040, R[0-9]+" + //ppc64: -"CLRLSLDI", "RLWNM\t[$]15, R[0-9]+, [$]2040, R[0-9]+" + b[1] = b[(v>>20)&0xFF] + //ppc64le: -"SLD", "RLWNM\t[$]10, R[0-9]+, [$]1016, R[0-9]+" + //ppc64: -"SLD", "RLWNM\t[$]10, R[0-9]+, [$]1016, R[0-9]+" + b[2] = b[v>>25] } diff --git a/test/directive.go b/test/directive.go index 6167cd6279..37781c30d5 100644 --- a/test/directive.go +++ b/test/directive.go @@ -6,11 +6,16 @@ // Verify that misplaced directives are diagnosed. +// ok +//go:build !ignore + //go:noinline // ERROR "misplaced compiler directive" //go:noinline // ERROR "misplaced compiler directive" package main +//go:build bad // ERROR "misplaced compiler directive" + //go:nosplit func f1() {} @@ -93,3 +98,5 @@ type T6 = int // EOF //go:noinline // ERROR "misplaced compiler directive" + +//go:build bad // ERROR "misplaced compiler directive" diff --git a/test/escape_closure.go b/test/escape_closure.go index 3b14027fa4..9152319fe0 100644 --- a/test/escape_closure.go +++ b/test/escape_closure.go @@ -50,7 +50,7 @@ func ClosureCallArgs4() { } func ClosureCallArgs5() { - x := 0 // ERROR "moved to heap: x" + x := 0 // ERROR "moved to heap: x" // TODO(mdempsky): We get "leaking param: p" here because the new escape analysis pass // can tell that p flows directly to sink, but it's a little weird. Re-evaluate. sink = func(p *int) *int { // ERROR "leaking param: p" "func literal does not escape" @@ -132,7 +132,7 @@ func ClosureCallArgs14() { } func ClosureCallArgs15() { - x := 0 // ERROR "moved to heap: x" + x := 0 // ERROR "moved to heap: x" p := &x sink = func(p **int) *int { // ERROR "leaking param content: p" "func literal does not escape" return *p @@ -164,3 +164,16 @@ func ClosureLeak2a(a ...string) string { // ERROR "leaking param content: a" func ClosureLeak2b(f func() string) string { // ERROR "f does not escape" return f() } + +func ClosureIndirect() { + f := func(p *int) {} // ERROR "p does not escape" "func literal does not escape" + f(new(int)) // ERROR "new\(int\) does not escape" + + g := f + g(new(int)) // ERROR "new\(int\) does not escape" + + h := nopFunc + h(new(int)) // ERROR "new\(int\) does not escape" +} + +func nopFunc(p *int) {} // ERROR "p does not escape" diff --git a/test/fixedbugs/bug429_run.go b/test/fixedbugs/bug429_run.go index c6a02aae5e..60cc5b62de 100644 --- a/test/fixedbugs/bug429_run.go +++ b/test/fixedbugs/bug429_run.go @@ -1,6 +1,11 @@ -// +build !nacl,!js // run +// +build !nacl,!js +// +build !darwin !arm64 + +// Skip on darwin/arm64 as it requires external linking, which brings in +// cgo, causing deadlock detection not working. + // Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff --git a/test/fixedbugs/issue21576.go b/test/fixedbugs/issue21576.go index b7a32f07ac..3797a8c9ba 100644 --- a/test/fixedbugs/issue21576.go +++ b/test/fixedbugs/issue21576.go @@ -1,6 +1,11 @@ -// +build !nacl,!js // run +// +build !nacl,!js +// +build !darwin !arm64 + +// Skip on darwin/arm64 as it requires external linking, which brings in +// cgo, causing deadlock detection not working. + // Copyright 2019 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff --git a/test/fixedbugs/issue24491a.go b/test/fixedbugs/issue24491a.go index 3c595798b5..8accf8c0a3 100644 --- a/test/fixedbugs/issue24491a.go +++ b/test/fixedbugs/issue24491a.go @@ -34,9 +34,6 @@ func test(s string, p, q uintptr, rest ...uintptr) int { panic(s + ": q failed") } for _, r := range rest { - // TODO(mdempsky): Remove. - break - if *(*string)(unsafe.Pointer(r)) != "ok" { panic(s + ": r[i] failed") } diff --git a/test/fixedbugs/issue35739.dir/a.go b/test/fixedbugs/issue35739.dir/a.go new file mode 100644 index 0000000000..b79503e996 --- /dev/null +++ b/test/fixedbugs/issue35739.dir/a.go @@ -0,0 +1,15 @@ +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package a + +type myError string + +func (e myError) Error() string { return string(e) } + +const myErrorVal myError = "error" + +func IsMyError(err error) bool { + return err == error(myErrorVal) +} diff --git a/test/fixedbugs/issue35739.dir/b.go b/test/fixedbugs/issue35739.dir/b.go new file mode 100644 index 0000000000..8d22aac8d6 --- /dev/null +++ b/test/fixedbugs/issue35739.dir/b.go @@ -0,0 +1,11 @@ +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package b + +import "./a" + +func F(err error) bool { + return a.IsMyError(err) +} diff --git a/test/fixedbugs/issue35739.go b/test/fixedbugs/issue35739.go new file mode 100644 index 0000000000..26f09d8c1b --- /dev/null +++ b/test/fixedbugs/issue35739.go @@ -0,0 +1,9 @@ +// compiledir + +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Issue 35739: gccgo inlining error with constant with method. + +package ignored diff --git a/test/fixedbugs/issue41635.go b/test/fixedbugs/issue41635.go index b33c1a07e7..35c0034cdd 100644 --- a/test/fixedbugs/issue41635.go +++ b/test/fixedbugs/issue41635.go @@ -7,12 +7,11 @@ package p func f() { // ERROR "" - b1 := make([]byte, 1<<17) // ERROR "too large for stack" "" - b2 := make([]byte, 100, 1<<17) // ERROR "too large for stack" "" - n, m := 100, 200 - b1 = make([]byte, n) // ERROR "non-constant size" "" - b2 = make([]byte, 100, m) // ERROR "non-constant size" "" + _ = make([]byte, 1<<17) // ERROR "too large for stack" "" + _ = make([]byte, 100, 1<<17) // ERROR "too large for stack" "" + _ = make([]byte, n, 1<<17) // ERROR "too large for stack" "" - _, _ = b1, b2 + _ = make([]byte, n) // ERROR "non-constant size" "" + _ = make([]byte, 100, m) // ERROR "non-constant size" "" } diff --git a/test/fixedbugs/issue41736.go b/test/fixedbugs/issue41736.go new file mode 100644 index 0000000000..36f127f4fb --- /dev/null +++ b/test/fixedbugs/issue41736.go @@ -0,0 +1,105 @@ +// compile + +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +type I struct { + x int64 +} + +type F struct { + x float64 +} + +type C struct { + x *complex128 +} + +type D struct { + x complex64 +} + +type A [1]*complex128 + +//go:noinline +func (i I) X() C { + cx := complex(0, float64(i.x)) + return C{&cx} +} + +//go:noinline +func (f F) X() C { + cx := complex(f.x, 0) + return C{&cx} +} + +//go:noinline +func (c C) X() C { + cx := complex(imag(*c.x), real(*c.x)) + return C{&cx} +} + +//go:noinline +func (d D) X() C { + cx := complex(float64(imag(d.x)), -float64(real(d.x))) + return C{&cx} +} + +//go:noinline +func (a A) X() C { + cx := complex(-float64(imag(*a[0])), float64(real(*a[0]))) + return C{&cx} +} + +//go:noinline +func (i I) id() I { + return i +} + +//go:noinline +func (f F) id() F { + return f +} + +//go:noinline +func (c C) id() C { + return c +} + +//go:noinline +func (d D) id() D { + return d +} + +//go:noinline +func (a A) id() A { + return a +} + +type T interface { + X() C +} + +func G(x []T) []T { + var y []T + for _, a := range x { + var v T + switch u := a.(type) { + case I: + v = u.id() + case F: + v = u.id() + case C: + v = u.id() + case D: + v = u.id() + case A: + v = u.id() + } + y = append(y, v) + } + return y +} diff --git a/test/fixedbugs/issue41780.go b/test/fixedbugs/issue41780.go new file mode 100644 index 0000000000..632c144a48 --- /dev/null +++ b/test/fixedbugs/issue41780.go @@ -0,0 +1,39 @@ +// run + +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Checks that conversion of CMP(x,-y) -> CMN(x,y) is only applied in correct context. + +package main + +type decimal struct { + d [8]byte // digits, big-endian representation + dp int // decimal point +} + +var powtab = []int{1, 3, 6, 9, 13, 16, 19, 23, 26} + +//go:noinline +func foo(d *decimal) int { + exp := int(d.d[1]) + if d.dp < 0 || d.dp == 0 && d.d[0] < '5' { + var n int + if -d.dp >= len(powtab) { + n = 27 + } else { + n = powtab[-d.dp] // incorrect CMP -> CMN substitution causes indexing panic. + } + exp += n + } + return exp +} + +func main() { + var d decimal + d.d[0] = '1' + if foo(&d) != 1 { + println("FAILURE (though not the one this test was written to catch)") + } +} diff --git a/test/fixedbugs/issue41872.go b/test/fixedbugs/issue41872.go new file mode 100644 index 0000000000..837d61ae0a --- /dev/null +++ b/test/fixedbugs/issue41872.go @@ -0,0 +1,26 @@ +// run + +// Copyright 2020 The Go Authors. All rights reserved. Use of this +// source code is governed by a BSD-style license that can be found in +// the LICENSE file. + +package main + +//go:noinline +func f8(x int32) bool { + return byte(x&0xc0) == 64 +} + +//go:noinline +func f16(x int32) bool { + return uint16(x&0x8040) == 64 +} + +func main() { + if !f8(64) { + panic("wanted true, got false") + } + if !f16(64) { + panic("wanted true, got false") + } +} diff --git a/test/fixedbugs/issue42032.go b/test/fixedbugs/issue42032.go new file mode 100644 index 0000000000..c456b1db02 --- /dev/null +++ b/test/fixedbugs/issue42032.go @@ -0,0 +1,27 @@ +// run + +// Copyright 2020 The Go Authors. All rights reserved. Use of this +// source code is governed by a BSD-style license that can be found in +// the LICENSE file. + +package main + +//go:notinheap +type NIH struct { +} + +type T struct { + x *NIH + p *int +} + +var y NIH +var z int + +func main() { + a := []T{{&y, &z}} + a = append(a, T{&y, &z}) + if a[1].x == nil { + panic("pointer not written") + } +} diff --git a/test/fixedbugs/issue42058a.go b/test/fixedbugs/issue42058a.go new file mode 100644 index 0000000000..67751a1b0c --- /dev/null +++ b/test/fixedbugs/issue42058a.go @@ -0,0 +1,13 @@ +// errorcheck + +// Copyright 2020 The Go Authors. All rights reserved. Use of this +// source code is governed by a BSD-style license that can be found in +// the LICENSE file. + +package p + +var c chan [2 << 16]byte // ERROR "channel element type too large" + +type T [1 << 17]byte + +var x chan T // ERROR "channel element type too large" diff --git a/test/fixedbugs/issue42058b.go b/test/fixedbugs/issue42058b.go new file mode 100644 index 0000000000..03f86ee1b1 --- /dev/null +++ b/test/fixedbugs/issue42058b.go @@ -0,0 +1,13 @@ +// errorcheck + +// Copyright 2020 The Go Authors. All rights reserved. Use of this +// source code is governed by a BSD-style license that can be found in +// the LICENSE file. + +package p + +var c chan [2 << 16]byte // ERROR "channel element type too large" + +func f() { + _ = 42 +} diff --git a/test/fixedbugs/issue42075.go b/test/fixedbugs/issue42075.go new file mode 100644 index 0000000000..af85fb281d --- /dev/null +++ b/test/fixedbugs/issue42075.go @@ -0,0 +1,16 @@ +// errorcheck + +// Copyright 2020 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +import "unsafe" + +type T struct { // ERROR "recursive type" + x int + p unsafe.Pointer + + f T +} diff --git a/test/fixedbugs/issue42076.go b/test/fixedbugs/issue42076.go new file mode 100644 index 0000000000..3e954813c9 --- /dev/null +++ b/test/fixedbugs/issue42076.go @@ -0,0 +1,21 @@ +// run + +// Copyright 2020 The Go Authors. All rights reserved. Use of this +// source code is governed by a BSD-style license that can be found in +// the LICENSE file. + +package main + +import "reflect" + +//go:notinheap +type NIH struct { +} + +var x, y NIH + +func main() { + if reflect.DeepEqual(&x, &y) != true { + panic("should report true") + } +} diff --git a/test/fixedbugs/issue4348.go b/test/fixedbugs/issue4348.go index c59b6b8caa..8b1a56c1d5 100644 --- a/test/fixedbugs/issue4348.go +++ b/test/fixedbugs/issue4348.go @@ -1,4 +1,4 @@ -// compile +// skip // Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -7,6 +7,8 @@ // Issue 4348. After switch to 64-bit ints the compiler generates // illegal instructions when using large array bounds or indexes. +// Skip. We reject symbols larger that 2GB (Issue #9862). + package main // 1<<32 on a 64-bit machine, 1 otherwise. diff --git a/test/inline.go b/test/inline.go index 3edcf2edfd..9b75bc5065 100644 --- a/test/inline.go +++ b/test/inline.go @@ -49,6 +49,12 @@ func j(x int) int { // ERROR "can inline j" } } +func _() int { // ERROR "can inline _" + tmp1 := h + tmp2 := tmp1 + return tmp2(0) // ERROR "inlining call to h" +} + var somethingWrong error // local closures can be inlined @@ -58,6 +64,9 @@ func l(x, y int) (int, int, error) { } if x == y { e(somethingWrong) // ERROR "inlining call to l.func1" + } else { + f := e + f(nil) // ERROR "inlining call to l.func1" } return y, x, nil } @@ -197,3 +206,43 @@ func gg(x int) { // ERROR "can inline gg" func hh(x int) { // ERROR "can inline hh" ff(x - 1) // ERROR "inlining call to ff" // ERROR "inlining call to gg" } + +// Issue #14768 - make sure we can inline for loops. +func for1(fn func() bool) { // ERROR "can inline for1" "fn does not escape" + for { + if fn() { + break + } else { + continue + } + } +} + +// BAD: for2 should be inlineable too. +func for2(fn func() bool) { // ERROR "fn does not escape" +Loop: + for { + if fn() { + break Loop + } else { + continue Loop + } + } +} + +// Issue #18493 - make sure we can do inlining of functions with a method value +type T1 struct{} + +func (a T1) meth(val int) int { // ERROR "can inline T1.meth" "inlining call to T1.meth" + return val + 5 +} + +func getMeth(t1 T1) func(int) int { // ERROR "can inline getMeth" + return t1.meth // ERROR "t1.meth escapes to heap" +} + +func ii() { // ERROR "can inline ii" + var t1 T1 + f := getMeth(t1) // ERROR "inlining call to getMeth" "t1.meth does not escape" + _ = f(3) +} diff --git a/test/nilptr.go b/test/nilptr.go index 90f57c54b6..c9a044dd36 100644 --- a/test/nilptr.go +++ b/test/nilptr.go @@ -8,7 +8,8 @@ // in a large address space. // +build !aix -// Address space starts at 1<<32 on AIX, so dummy is too far. +// +build !darwin !arm64 +// Address space starts at 1<<32 on AIX and on darwin/arm64, so dummy is too far. package main diff --git a/test/run.go b/test/run.go index 95b94b7277..672861c8d7 100644 --- a/test/run.go +++ b/test/run.go @@ -1489,7 +1489,7 @@ var ( // value[0] is the variant-changing environment variable, and values[1:] // are the supported variants. archVariants = map[string][]string{ - "386": {"GO386", "387", "sse2"}, + "386": {"GO386", "sse2", "softfloat"}, "amd64": {}, "arm": {"GOARM", "5", "6", "7"}, "arm64": {}, |