--- /dev/null
+// compile
+
+// Copyright 2015 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 10047: gccgo failed to compile a type switch where the switch variable
+// and the base type of a case share the same identifier.
+
+package main
+
+func main() {
+ type t int
+ var p interface{}
+ switch t := p.(type) {
+ case t:
+ _ = t
+ }
+}
--- /dev/null
+package a
+
+import "log"
+
+func Do() {
+ Do2()
+}
+
+func Do2() {
+ println(log.Ldate | log.Ltime | log.Lshortfile)
+}
--- /dev/null
+package b
+
+import "./a"
+
+func test() {
+ a.Do()
+}
--- /dev/null
+// compiledir
+
+// Copyright 2015 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 10066: constants are printed in the original form
+// in export data. This is the opposite of issue 9076.
+
+package ignored
--- /dev/null
+// run
+
+// Copyright 2015 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 10135: append a slice with zero-sized element used
+// to always return a slice with the same data pointer as the
+// old slice, even if it's nil, so this program used to panic
+// with nil pointer dereference because after append, s is a
+// slice with nil data pointer but non-zero len and cap.
+
+package main
+
+type empty struct{}
+
+func main() {
+ var s []empty
+
+ s = append(s, empty{})
+
+ for _, v := range s {
+ _ = v
+ }
+}
--- /dev/null
+// Copyright 2015 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 m struct {
+ S string
+}
+
+var g = struct {
+ m
+ P string
+}{
+ m{"a"},
+ "",
+}
+
+type S struct{}
+
+func (s *S) M(p string) {
+ r := g
+ r.P = p
+}
--- /dev/null
+// Copyright 2015 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() *a.S {
+ return &a.S{}
+}
--- /dev/null
+// Copyright 2015 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 c
+
+import "./b"
+
+func F() {
+ s := b.F()
+ s.M("c")
+}
--- /dev/null
+// compiledir
+
+// Copyright 2015 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 10219: failure of inlinable function that uses embedded types
+// in an anonymous struct via :=.
+
+package ignored
--- /dev/null
+// run
+
+// Copyright 2015 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 10253: cmd/7g: bad codegen, probably regopt related
+
+package main
+
+func main() {
+ if !eq() {
+ panic("wrong value")
+ }
+}
+
+var text = "abc"
+var s = &str{text}
+
+func eq() bool {
+ return text[0] == s.text[0]
+}
+
+type str struct {
+ text string
+}
--- /dev/null
+// compile
+
+// Copyright 2015 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 10284: gccgo failed to allow converting a user-defined
+// type whose underlying type is uintptr to unsafe.Pointer.
+
+package p
+
+import "unsafe"
+
+type T uintptr
+
+var _ unsafe.Pointer = unsafe.Pointer(T(0))
--- /dev/null
+// run
+
+// Copyright 2015 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 10320: 7g failed to compile a program because it attempted
+// to use ZR as register. Other programs compiled but failed to
+// execute correctly because they clobbered the g register.
+
+package main
+
+func main() {
+ var x00, x01, x02, x03, x04, x05, x06, x07, x08, x09 int
+ var x10, x11, x12, x13, x14, x15, x16, x17, x18, x19 int
+ var x20, x21, x22, x23, x24, x25, x26, x27, x28, x29 int
+ var x30, x31, x32 int
+
+ _ = x00
+ _ = x01
+ _ = x02
+ _ = x03
+ _ = x04
+ _ = x05
+ _ = x06
+ _ = x07
+ _ = x08
+ _ = x09
+
+ _ = x10
+ _ = x11
+ _ = x12
+ _ = x13
+ _ = x14
+ _ = x15
+ _ = x16
+ _ = x17
+ _ = x18
+ _ = x19
+
+ _ = x20
+ _ = x21
+ _ = x22
+ _ = x23
+ _ = x24
+ _ = x25
+ _ = x26
+ _ = x27
+ _ = x28
+ _ = x29
+
+ _ = x30
+ _ = x31
+ _ = x32
+}
--- /dev/null
+// run
+
+// Copyright 2015 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.
+
+// The PkgPath of unexported fields of types defined in package main was incorrectly ""
+
+package main
+
+import (
+ "fmt"
+ "reflect"
+)
+
+type foo struct {
+ bar int
+}
+
+func main() {
+ pkgpath := reflect.ValueOf(foo{}).Type().Field(0).PkgPath
+ if pkgpath != "main" {
+ fmt.Printf("BUG: incorrect PkgPath: %v", pkgpath)
+ }
+}
--- /dev/null
+// run
+
+// Copyright 2015 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 10253: cmd/gc: incorrect escape analysis of closures
+// Partial call x.foo was not promoted to heap.
+
+package main
+
+func main() {
+ c := make(chan bool)
+ // Create a new goroutine to get a default-size stack segment.
+ go func() {
+ x := new(X)
+ clos(x.foo)()
+ c <- true
+ }()
+ <-c
+}
+
+type X int
+
+func (x *X) foo() {
+}
+
+func clos(x func()) func() {
+ f := func() {
+ print("")
+ x() // This statement crashed, because the partial call was allocated on the old stack.
+ }
+ // Grow stack so that partial call x becomes invalid if allocated on stack.
+ growstack(10000)
+ c := make(chan bool)
+ // Spoil the previous stack segment.
+ go func() {
+ c <- true
+ }()
+ <-c
+ return f
+}
+
+func growstack(x int) {
+ if x == 0 {
+ return
+ }
+ growstack(x - 1)
+}
--- /dev/null
+// runoutput
+
+// Copyright 2015 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 10407: gccgo failed to remove carriage returns
+// from raw string literals.
+
+package main
+
+import "fmt"
+
+func main() {
+ fmt.Println("package main\nfunc main() { if `a\rb\r\nc` != \"ab\\nc\" { panic(42) }}")
+}
--- /dev/null
+// build
+
+// Copyright 2015 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
+
+func bar() {
+ f := func() {}
+ foo(&f)
+}
+
+//go:noinline
+func foo(f *func()) func() {
+ return *f
+}
--- /dev/null
+// run
+
+// Copyright 2015 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 10486.
+// Check stack walk during div by zero fault,
+// especially on software divide systems.
+
+package main
+
+import "runtime"
+
+var A, B int
+
+func divZero() int {
+ defer func() {
+ if p := recover(); p != nil {
+ var pcs [512]uintptr
+ runtime.Callers(2, pcs[:])
+ runtime.GC()
+ }
+ }()
+ return A / B
+}
+
+func main() {
+ A = 1
+ divZero()
+}
--- /dev/null
+// +build linux,!ppc64,!riscv64
+// run
+
+// Copyright 2015 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.
+
+// Test that a -B option is passed through when using both internal
+// and external linking mode.
+
+// TODO(jsing): Re-enable on riscv64 when it has support for external
+// linking - see golang.org/issue/36739
+
+package main
+
+import (
+ "fmt"
+ "os"
+ "os/exec"
+ "path/filepath"
+)
+
+func main() {
+ test("internal")
+ test("external")
+}
+
+func test(linkmode string) {
+ out, err := exec.Command("go", "run", "-ldflags", "-B=0x12345678 -linkmode="+linkmode, filepath.Join("fixedbugs", "issue10607a.go")).CombinedOutput()
+ if err != nil {
+ fmt.Printf("BUG: linkmode=%s %v\n%s\n", linkmode, err, out)
+ os.Exit(1)
+ }
+}
--- /dev/null
+// skip
+
+// Copyright 2015 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.
+
+// This is built by issue10607.go with a -B option.
+// Verify that we have one build-id note with the expected value.
+
+package main
+
+import (
+ "bytes"
+ "debug/elf"
+ "fmt"
+ "os"
+)
+
+func main() {
+ f, err := elf.Open("/proc/self/exe")
+ if err != nil {
+ if os.IsNotExist(err) {
+ return
+ }
+ fmt.Fprintln(os.Stderr, "opening /proc/self/exe:", err)
+ os.Exit(1)
+ }
+
+ c := 0
+ fail := false
+ for i, s := range f.Sections {
+ if s.Type != elf.SHT_NOTE {
+ continue
+ }
+
+ d, err := s.Data()
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "reading data of note section %d: %v\n", i, err)
+ continue
+ }
+
+ for len(d) > 0 {
+ namesz := f.ByteOrder.Uint32(d)
+ descsz := f.ByteOrder.Uint32(d[4:])
+ typ := f.ByteOrder.Uint32(d[8:])
+
+ an := (namesz + 3) &^ 3
+ ad := (descsz + 3) &^ 3
+
+ if int(12+an+ad) > len(d) {
+ fmt.Fprintf(os.Stderr, "note section %d too short for header (%d < 12 + align(%d,4) + align(%d,4))\n", i, len(d), namesz, descsz)
+ break
+ }
+
+ // 3 == NT_GNU_BUILD_ID
+ if typ == 3 && namesz == 4 && bytes.Equal(d[12:16], []byte("GNU\000")) {
+ id := string(d[12+an:12+an+descsz])
+ if id == "\x12\x34\x56\x78" {
+ c++
+ } else {
+ fmt.Fprintf(os.Stderr, "wrong build ID data: %q\n", id)
+ fail = true
+ }
+ }
+
+ d = d[12+an+ad:]
+ }
+ }
+
+ if c == 0 {
+ fmt.Fprintln(os.Stderr, "no build-id note")
+ fail = true
+ } else if c > 1 {
+ fmt.Fprintln(os.Stderr, c, "build-id notes")
+ fail = true
+ }
+
+ if fail {
+ os.Exit(1)
+ }
+}
--- /dev/null
+// compile
+
+// Copyright 2015 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 10654: Failure to use generated temps
+// for function calls etc. in boolean codegen.
+
+package main
+
+var s string
+
+func main() {
+ if (s == "this") != (s == "that") {
+ }
+}
--- /dev/null
+// Copyright 2015 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 other
+
+type Exported interface {
+ Do()
+ secret()
+}
--- /dev/null
+// errorcheck -0 -m -l
+
+// Copyright 2015 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 "./other"
+
+type Imported interface {
+ Do()
+}
+
+type HasAMethod struct {
+ x int
+}
+
+func (me *HasAMethod) Do() {
+ println(me.x)
+}
+
+func InMyCode(x *Imported, y *HasAMethod, z *other.Exported) {
+ x.Do() // ERROR "x\.Do undefined \(type \*Imported is pointer to interface, not interface\)|type that is pointer to interface"
+ x.do() // ERROR "x\.do undefined \(type \*Imported is pointer to interface, not interface\)|type that is pointer to interface"
+ (*x).Do()
+ x.Dont() // ERROR "x\.Dont undefined \(type \*Imported is pointer to interface, not interface\)|type that is pointer to interface"
+ (*x).Dont() // ERROR "\(\*x\)\.Dont undefined \(type Imported has no field or method Dont\)|reference to undefined field or method"
+
+ y.Do()
+ y.do() // ERROR "y\.do undefined \(type \*HasAMethod has no field or method do, but does have Do\)|reference to undefined field or method"
+ (*y).Do()
+ (*y).do() // ERROR "\(\*y\)\.do undefined \(type HasAMethod has no field or method do, but does have Do\)|reference to undefined field or method"
+ y.Dont() // ERROR "y\.Dont undefined \(type \*HasAMethod has no field or method Dont\)|reference to undefined field or method"
+ (*y).Dont() // ERROR "\(\*y\)\.Dont undefined \(type HasAMethod has no field or method Dont\)|reference to undefined field or method"
+
+ z.Do() // ERROR "z\.Do undefined \(type \*other\.Exported is pointer to interface, not interface\)|type that is pointer to interface"
+ z.do() // ERROR "z\.do undefined \(type \*other\.Exported is pointer to interface, not interface\)|type that is pointer to interface"
+ (*z).Do()
+ (*z).do() // ERROR "\(\*z\)\.do undefined \(type other.Exported has no field or method do, but does have Do\)|reference to undefined field or method"
+ z.Dont() // ERROR "z\.Dont undefined \(type \*other\.Exported is pointer to interface, not interface\)|type that is pointer to interface"
+ (*z).Dont() // ERROR "\(\*z\)\.Dont undefined \(type other\.Exported has no field or method Dont\)|reference to undefined field or method"
+ z.secret() // ERROR "z\.secret undefined \(type \*other\.Exported is pointer to interface, not interface\)|type that is pointer to interface"
+ (*z).secret() // ERROR "\(\*z\)\.secret undefined \(cannot refer to unexported field or method secret\)|reference to unexported field or method"
+
+}
+
+func main() {
+}
--- /dev/null
+// errorcheckdir
+
+// Copyright 2015 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 ignored
--- /dev/null
+// run
+
+// Copyright 2015 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 "fmt"
+
+func prototype(xyz []string) {}
+func main() {
+ var got [][]string
+ f := prototype
+ f = func(ss []string) { got = append(got, ss) }
+ for _, s := range []string{"one", "two", "three"} {
+ f([]string{s})
+ }
+ if got[0][0] != "one" || got[1][0] != "two" || got[2][0] != "three" {
+ // Bug's wrong output was [[three] [three] [three]]
+ fmt.Println("Expected [[one] [two] [three]], got", got)
+ }
+}
--- /dev/null
+// +build !nacl,!js,disabled_see_issue_18589
+// buildrun -t 10 -gcflags=-d=ssa/insert_resched_checks/on,ssa/check/on
+
+// Copyright 2016 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.
+
+// Test is disabled because it flakes when run in all.bash
+// on some platforms, but is useful standalone to verify
+// that rescheduling checks are working (and we may wish
+// to investigate the flake, since it suggests that the
+// loop rescheduling check may not work right on those
+// platforms).
+
+// This checks to see that call-free infinite loops do not
+// block garbage collection. IF YOU RUN IT STANDALONE without
+// -gcflags=-d=ssa/insert_resched_checks/on in a not-experimental
+// build, it should hang.
+
+package main
+
+import (
+ "runtime"
+)
+
+var someglobal1 int
+var someglobal2 int
+var someglobal3 int
+
+//go:noinline
+func f() {}
+
+func standinacorner1() {
+ for someglobal1&1 == 0 {
+ someglobal1++
+ someglobal1++
+ }
+}
+
+func standinacorner2(i int) {
+ // contains an irreducible loop containing changes to memory
+ if i != 0 {
+ goto midloop
+ }
+
+loop:
+ if someglobal2&1 != 0 {
+ goto done
+ }
+ someglobal2++
+midloop:
+ someglobal2++
+ goto loop
+
+done:
+ return
+}
+
+func standinacorner3() {
+ for someglobal3&1 == 0 {
+ if someglobal3&2 != 0 {
+ for someglobal3&3 == 2 {
+ someglobal3++
+ someglobal3++
+ someglobal3++
+ someglobal3++
+ }
+ }
+ someglobal3++
+ someglobal3++
+ someglobal3++
+ someglobal3++
+ }
+}
+
+func main() {
+ go standinacorner1()
+ go standinacorner2(0)
+ go standinacorner3()
+ // println("About to stand in a corner1")
+ for someglobal1 == 0 {
+ runtime.Gosched()
+ }
+ // println("About to stand in a corner2")
+ for someglobal2 == 0 {
+ runtime.Gosched()
+ }
+ // println("About to stand in a corner3")
+ for someglobal3 == 0 {
+ runtime.Gosched()
+ }
+ // println("About to GC")
+ runtime.GC()
+ // println("Success")
+}
--- /dev/null
+// errorcheck
+
+// Copyright 2015 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 10975: Returning an invalid interface would cause
+// `internal compiler error: getinarg: not a func`.
+
+package main
+
+type I interface {
+ int // ERROR "interface contains embedded non-interface"
+}
+
+func New() I {
+ return struct{}{}
+}
--- /dev/null
+// compile
+
+// Copyright 2015 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 T struct{}
+
+var (
+ t = T{}
+ u = t.New()
+)
+
+func x(T) (int, int) { return 0, 0 }
+
+var _, _ = x(u)
+
+func (T) New() T { return T{} }
--- /dev/null
+// Copyright 2015 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
+
+func Int32(i int32) *int32 {
+ return &i
+}
--- /dev/null
+// Copyright 2015 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 (
+ "fmt"
+ "p"
+)
+
+type I interface {
+ Add(out *P)
+}
+
+type P struct {
+ V *int32
+}
+
+type T struct{}
+
+var x int32 = 42
+
+func Int32x(i int32) *int32 {
+ return &i
+}
+
+func (T) Add(out *P) {
+ out.V = p.Int32(x) // inlined, p.i.2 moved to heap
+}
+
+var PP P
+var out *P = &PP
+
+func F(s I) interface{} {
+ s.Add(out) // not inlined.
+ return out
+}
+
+var s T
+
+func main() {
+ println("Starting")
+ fmt.Sprint(new(int32))
+ resp := F(s).(*P)
+ println("Before, *resp.V=", *resp.V) // Trashes *resp.V in process of printing.
+ println("After, *resp.V=", *resp.V)
+ if got, want := *resp.V, int32(42); got != want {
+ fmt.Printf("FAIL, got %v, want %v", got, want)
+ }
+}
--- /dev/null
+// rundir
+
+// Copyright 2015 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 11053: Compiler does not run escape analysis on an inlined
+// generated method wrapper.
+
+package ignored
--- /dev/null
+Starting
+Before, *resp.V= 42
+After, *resp.V= 42
--- /dev/null
+// run
+
+// Copyright 2015 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.
+
+// Test that stack barriers are reset when a goroutine exits without
+// returning.
+
+package main
+
+import (
+ "runtime"
+ "sync/atomic"
+ "time"
+)
+
+func main() {
+ // Let the garbage collector run concurrently.
+ runtime.GOMAXPROCS(2)
+
+ var x [100][]byte
+
+ for i := range x {
+ var done int32
+
+ go func() {
+ // Use enough stack to get stack barriers, but
+ // not so much that we go over _FixedStack.
+ // There's a very narrow window here on most
+ // OSs, so we basically can't do anything (not
+ // even a time.Sleep or a channel).
+ var buf [1024]byte
+ buf[0]++
+ for atomic.LoadInt32(&done) == 0 {
+ runtime.Gosched()
+ }
+ atomic.StoreInt32(&done, 0)
+ // Exit without unwinding stack barriers.
+ runtime.Goexit()
+ }()
+
+ // Generate some garbage.
+ x[i] = make([]byte, 1024*1024)
+
+ // Give GC some time to install stack barriers in the G.
+ time.Sleep(50 * time.Microsecond)
+ atomic.StoreInt32(&done, 1)
+ for atomic.LoadInt32(&done) == 1 {
+ runtime.Gosched()
+ }
+ }
+}
--- /dev/null
+// run
+
+// Copyright 2015 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.
+
+// Test that pointer bitmaps of types with large scalar tails are
+// correctly repeated when unrolled into the heap bitmap.
+
+package main
+
+import "runtime"
+
+const D = 57
+
+type T struct {
+ a [D]float64
+ b map[string]int
+ c [D]float64
+}
+
+var ts []T
+
+func main() {
+ ts = make([]T, 4)
+ for i := range ts {
+ ts[i].b = make(map[string]int)
+ }
+ ts[3].b["abc"] = 42
+ runtime.GC()
+ if ts[3].b["abc"] != 42 {
+ panic("bad field value")
+ }
+}
--- /dev/null
+// run
+
+// Copyright 2015 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
+
+// Tests for golang.org/issue/11326.
+
+func main() {
+ {
+ const n = 1e646456992
+ const d = 1e646456991
+ x := n / d
+ if x != 10.0 {
+ println("incorrect value:", x)
+ }
+ }
+ {
+ const n = 1e64645699
+ const d = 1e64645698
+ x := n / d
+ if x != 10.0 {
+ println("incorrect value:", x)
+ }
+ }
+ {
+ const n = 1e6464569
+ const d = 1e6464568
+ x := n / d
+ if x != 10.0 {
+ println("incorrect value:", x)
+ }
+ }
+ {
+ const n = 1e646456
+ const d = 1e646455
+ x := n / d
+ if x != 10.0 {
+ println("incorrect value:", x)
+ }
+ }
+}
--- /dev/null
+// compile
+
+// Copyright 2017 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
+
+type X int
+
+var foo = map[int]X{}
+
+var bar = map[int][8]X{}
+
+func main() {}
--- /dev/null
+// errorcheck
+
+// Copyright 2015 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.
+
+// identifiers beginning with non-ASCII digits were incorrectly accepted.
+// issue 11359.
+
+package p
+var Û¶ = 0 // ERROR "identifier cannot begin with digit"
--- /dev/null
+// errorcheck
+
+// Copyright 2016 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
+
+import "fmt" // GC_ERROR "imported and not used"
+
+const n = fmt // ERROR "fmt without selector|unexpected reference to package"
--- /dev/null
+// errorcheck
+
+// Copyright 2015 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 11362: prints empty canonical import path
+
+package main
+
+import _ "unicode//utf8" // GC_ERROR "non-canonical import path .unicode//utf8. \(should be .unicode/utf8.\)" "can't find import: .unicode//utf8."
+
+func main() {
+}
+
--- /dev/null
+// run
+
+// Copyright 2015 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.
+
+// Test that the half multiply resulting from a division
+// by a constant generates correct code.
+
+package main
+
+func main() {
+ var _ = 7 / "0"[0] // test case from #11369
+ var _ = 1 / "."[0] // test case from #11358
+ var x = 0 / "0"[0]
+ var y = 48 / "0"[0]
+ var z = 5 * 48 / "0"[0]
+ if x != 0 {
+ panic("expected 0")
+ }
+ if y != 1 {
+ panic("expected 1")
+ }
+ if z != 5 {
+ panic("expected 5")
+ }
+}
--- /dev/null
+// compile
+
+// Copyright 2015 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 11370: cmd/compile: "0"[0] should not be a constant
+
+package p
+
+func main() {
+ println(-"abc"[1] >> 1)
+}
--- /dev/null
+// errorcheck
+
+// Copyright 2017 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 11371 (cmd/compile: meaningless error message "truncated to
+// integer")
+
+package issue11371
+
+const a int = 1.1 // ERROR "constant 1.1 truncated to integer|floating-point constant truncated to integer"
+const b int = 1e20 // ERROR "overflows int|integer constant overflow"
+const c int = 1 + 1e-70 // ERROR "constant truncated to integer"
+const d int = 1 - 1e-70 // ERROR "constant truncated to integer"
+const e int = 1.00000001 // ERROR "constant truncated to integer"
+const f int = 0.00000001 // ERROR "constant 1e-08 truncated to integer|floating-point constant truncated to integer"
--- /dev/null
+// errorcheck
+
+// Copyright 2015 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 _ = int8(4) * 300 // ERROR "constant 300 overflows int8" "constant 1200 overflows int8|integer constant overflow"
+var _ = complex64(1) * 1e200 // ERROR "constant 1e\+200 overflows complex64|complex real part overflow"
+var _ = complex128(1) * 1e500 // ERROR "constant 1e\+500 overflows complex128|complex real part overflow"
--- /dev/null
+// errorcheck
+
+// Copyright 2015 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.
+
+// Test an internal compiler error on ? symbol in declaration
+// following an empty import.
+
+package a
+import"" // ERROR "import path is empty"
+var? // ERROR "invalid character U\+003F '\?'|invalid character 0x3f in input file"
+
+var x int // ERROR "unexpected var|expected identifier|expected type"
+
+func main() {
+}
--- /dev/null
+// errorcheck
+
+// Copyright 2015 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.
+
+// Test that incorrect expressions involving wrong anonymous interface
+// do not generate panics in Type Stringer.
+// Does not compile.
+
+package main
+
+type I interface {
+ int // ERROR "interface contains embedded non-interface"
+}
+
+func n() {
+ (I)
+}
+
+func m() {
+ (interface{int}) // ERROR "interface contains embedded non-interface" "type interface { int } is not an expression"
+}
+
+func main() {
+}
--- /dev/null
+// errorcheck
+
+// Copyright 2017 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 11674: cmd/compile: does not diagnose constant division by
+// zero
+
+package p
+
+const x complex64 = 0
+const y complex128 = 0
+
+var _ = x / 1e-20
+var _ = x / 1e-50 // GC_ERROR "complex division by zero"
+var _ = x / 1e-1000 // GC_ERROR "complex division by zero"
+var _ = x / 1e-20i
+var _ = x / 1e-50i // GC_ERROR "complex division by zero"
+var _ = x / 1e-1000i // GC_ERROR "complex division by zero"
+
+var _ = x / 1e-45 // smallest positive float32
+
+var _ = x / (1e-20 + 1e-20i)
+var _ = x / (1e-50 + 1e-20i)
+var _ = x / (1e-20 + 1e-50i)
+var _ = x / (1e-50 + 1e-50i) // GC_ERROR "complex division by zero"
+var _ = x / (1e-1000 + 1e-1000i) // GC_ERROR "complex division by zero"
+
+var _ = y / 1e-50
+var _ = y / 1e-1000 // GC_ERROR "complex division by zero"
+var _ = y / 1e-50i
+var _ = y / 1e-1000i // GC_ERROR "complex division by zero"
+
+var _ = y / 5e-324 // smallest positive float64
+
+var _ = y / (1e-50 + 1e-50)
+var _ = y / (1e-1000 + 1e-50i)
+var _ = y / (1e-50 + 1e-1000i)
+var _ = y / (1e-1000 + 1e-1000i) // GC_ERROR "complex division by zero"
--- /dev/null
+// compile
+
+// Copyright 2015 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 11699; used to fail with duplicate _.args_stackmap symbols.
+
+package p
+
+func _()
+func _()
--- /dev/null
+// compile
+
+// Copyright 2015 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 11750: mkdotargslice: typecheck failed
+
+package main
+
+func main() {
+ fn := func(names string) {
+
+ }
+ func(names ...string) {
+ for _, name := range names {
+ fn(name)
+ }
+ }("one", "two")
+}
--- /dev/null
+// +build !nacl,!js
+// run
+
+// Copyright 2015 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 11771: Magic comments should ignore carriage returns.
+
+package main
+
+import (
+ "bytes"
+ "fmt"
+ "io/ioutil"
+ "log"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "runtime"
+)
+
+func main() {
+ if runtime.Compiler != "gc" {
+ return
+ }
+
+ dir, err := ioutil.TempDir("", "go-issue11771")
+ if err != nil {
+ log.Fatalf("creating temp dir: %v\n", err)
+ }
+ defer os.RemoveAll(dir)
+
+ // The go:nowritebarrier magic comment is only permitted in
+ // the runtime package. So we confirm that the compilation
+ // fails.
+
+ var buf bytes.Buffer
+ fmt.Fprintln(&buf, `
+package main
+
+func main() {
+}
+`)
+ fmt.Fprintln(&buf, "//go:nowritebarrier\r")
+ fmt.Fprintln(&buf, `
+func x() {
+}
+`)
+
+ if err := ioutil.WriteFile(filepath.Join(dir, "x.go"), buf.Bytes(), 0666); err != nil {
+ log.Fatal(err)
+ }
+
+ cmd := exec.Command("go", "tool", "compile", "x.go")
+ cmd.Dir = dir
+ output, err := cmd.CombinedOutput()
+ if err == nil {
+ log.Fatal("compile succeeded unexpectedly")
+ }
+ if !bytes.Contains(output, []byte("only allowed in runtime")) {
+ log.Fatalf("wrong error message from compiler; got:\n%s\n", output)
+ }
+}
--- /dev/null
+// compile
+
+// Copyright 2015 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 11790: Incorrect error following named pointer dereference on field
+
+package main
+
+import "fmt"
+
+type T0 struct {
+ x int
+}
+
+func (*T0) M0() {
+ fmt.Println("M0")
+}
+
+type T2 struct {
+ *T0
+}
+
+type Q *T2
+
+func main() {
+ // If run, expected output is
+ // 42
+ // M0
+ t0 := T0{42}
+ t2 := T2{&t0}
+ var q Q = &t2
+ fmt.Println(q.x) // Comment out either this line or the next line and the program works
+ (*q).T0.M0()
+}
--- /dev/null
+// run
+
+// Copyright 2017 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 "fmt"
+
+// issue 17446
+const (
+ _ = real(0) // from bug report
+ _ = imag(0) // from bug report
+
+ // if the arguments are untyped, the results must be untyped
+ // (and compatible with types that can represent the values)
+ _ int = real(1)
+ _ int = real('a')
+ _ int = real(2.0)
+ _ int = real(3i)
+
+ _ float32 = real(1)
+ _ float32 = real('a')
+ _ float32 = real(2.1)
+ _ float32 = real(3.2i)
+
+ _ float64 = real(1)
+ _ float64 = real('a')
+ _ float64 = real(2.1)
+ _ float64 = real(3.2i)
+
+ _ int = imag(1)
+ _ int = imag('a')
+ _ int = imag(2.1 + 3i)
+ _ int = imag(3i)
+
+ _ float32 = imag(1)
+ _ float32 = imag('a')
+ _ float32 = imag(2.1 + 3.1i)
+ _ float32 = imag(3i)
+
+ _ float64 = imag(1)
+ _ float64 = imag('a')
+ _ float64 = imag(2.1 + 3.1i)
+ _ float64 = imag(3i)
+)
+
+var tests = []struct {
+ code string
+ got, want interface{}
+}{
+ {"real(1)", real(1), 1.0},
+ {"real('a')", real('a'), float64('a')},
+ {"real(2.0)", real(2.0), 2.0},
+ {"real(3.2i)", real(3.2i), 0.0},
+
+ {"imag(1)", imag(1), 0.0},
+ {"imag('a')", imag('a'), 0.0},
+ {"imag(2.1 + 3.1i)", imag(2.1 + 3.1i), 3.1},
+ {"imag(3i)", imag(3i), 3.0},
+}
+
+func main() {
+ // verify compile-time evaluated constant expressions
+ for _, test := range tests {
+ if test.got != test.want {
+ panic(fmt.Sprintf("%s: %v (%T) != %v (%T)", test.code, test.got, test.got, test.want, test.want))
+ }
+ }
+}
--- /dev/null
+// run
+
+// Copyright 2015 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 11987. The ppc64 SRADCC instruction was misassembled in a way
+// lost bit 5 of the immediate so v>>32 was assembled as v>>0. SRADCC
+// is only ever inserted by peep so it's hard to be sure when it will
+// be used. This formulation worked when the bug was fixed.
+
+package main
+
+import "fmt"
+
+var v int64 = 0x80000000
+
+func main() {
+ s := fmt.Sprintf("%v", v>>32 == 0)
+ if s != "true" {
+ fmt.Printf("BUG: v>>32 == 0 evaluated as %q\n", s)
+ }
+}
--- /dev/null
+// errorcheck -0 -m -l
+
+// Copyright 2015 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.
+
+// Test escape analysis through ... parameters.
+
+package foo
+
+func FooN(vals ...*int) (s int) { // ERROR "vals does not escape"
+ for _, v := range vals {
+ s += *v
+ }
+ return s
+}
+
+// Append forces heap allocation and copies entries in vals to heap, therefore they escape to heap.
+func FooNx(x *int, vals ...*int) (s int) { // ERROR "leaking param: x" "leaking param content: vals"
+ vals = append(vals, x)
+ return FooN(vals...)
+}
+
+var sink []*int
+
+func FooNy(x *int, vals ...*int) (s int) { // ERROR "leaking param: x" "leaking param: vals"
+ vals = append(vals, x)
+ sink = vals
+ return FooN(vals...)
+}
+
+func FooNz(vals ...*int) (s int) { // ERROR "leaking param: vals"
+ sink = vals
+ return FooN(vals...)
+}
+
+func TFooN() {
+ for i := 0; i < 1000; i++ {
+ var i, j int
+ FooN(&i, &j) // ERROR "... argument does not escape"
+ }
+}
+
+func TFooNx() {
+ for i := 0; i < 1000; i++ {
+ var i, j, k int // ERROR "moved to heap: i" "moved to heap: j" "moved to heap: k"
+ FooNx(&k, &i, &j) // ERROR "... argument does not escape"
+ }
+}
+
+func TFooNy() {
+ for i := 0; i < 1000; i++ {
+ var i, j, k int // ERROR "moved to heap: i" "moved to heap: j" "moved to heap: k"
+ FooNy(&k, &i, &j) // ERROR "... argument escapes to heap"
+ }
+}
+
+func TFooNz() {
+ for i := 0; i < 1000; i++ {
+ var i, j int // ERROR "moved to heap: i" "moved to heap: j"
+ FooNz(&i, &j) // ERROR "... argument escapes to heap"
+ }
+}
+
+var isink *int32
+
+func FooI(args ...interface{}) { // ERROR "leaking param content: args"
+ for i := 0; i < len(args); i++ {
+ switch x := args[i].(type) {
+ case nil:
+ println("is nil")
+ case int32:
+ println("is int32")
+ case *int32:
+ println("is *int32")
+ isink = x
+ case string:
+ println("is string")
+ }
+ }
+}
+
+func TFooI() {
+ a := int32(1) // ERROR "moved to heap: a"
+ b := "cat"
+ c := &a
+ FooI(a, b, c) // ERROR "a escapes to heap" "b escapes to heap" "... argument does not escape"
+}
+
+func FooJ(args ...interface{}) *int32 { // ERROR "leaking param: args to result ~r1 level=1"
+ for i := 0; i < len(args); i++ {
+ switch x := args[i].(type) {
+ case nil:
+ println("is nil")
+ case int32:
+ println("is int32")
+ case *int32:
+ println("is *int32")
+ return x
+ case string:
+ println("is string")
+ }
+ }
+ return nil
+}
+
+func TFooJ1() {
+ a := int32(1)
+ b := "cat"
+ c := &a
+ FooJ(a, b, c) // ERROR "a does not escape" "b does not escape" "... argument does not escape"
+}
+
+func TFooJ2() {
+ a := int32(1) // ERROR "moved to heap: a"
+ b := "cat"
+ c := &a
+ isink = FooJ(a, b, c) // ERROR "a escapes to heap" "b escapes to heap" "... argument does not escape"
+}
+
+type fakeSlice struct {
+ l int
+ a *[4]interface{}
+}
+
+func FooK(args fakeSlice) *int32 { // ERROR "leaking param: args to result ~r1 level=1"
+ for i := 0; i < args.l; i++ {
+ switch x := (*args.a)[i].(type) {
+ case nil:
+ println("is nil")
+ case int32:
+ println("is int32")
+ case *int32:
+ println("is *int32")
+ return x
+ case string:
+ println("is string")
+ }
+ }
+ return nil
+}
+
+func TFooK2() {
+ a := int32(1) // ERROR "moved to heap: a"
+ b := "cat"
+ c := &a
+ fs := fakeSlice{3, &[4]interface{}{a, b, c, nil}} // ERROR "a escapes to heap" "b escapes to heap" "&\[4\]interface {}{...} does not escape"
+ isink = FooK(fs)
+}
+
+func FooL(args []interface{}) *int32 { // ERROR "leaking param: args to result ~r1 level=1"
+ for i := 0; i < len(args); i++ {
+ switch x := args[i].(type) {
+ case nil:
+ println("is nil")
+ case int32:
+ println("is int32")
+ case *int32:
+ println("is *int32")
+ return x
+ case string:
+ println("is string")
+ }
+ }
+ return nil
+}
+
+func TFooL2() {
+ a := int32(1) // ERROR "moved to heap: a"
+ b := "cat"
+ c := &a
+ s := []interface{}{a, b, c} // ERROR "a escapes to heap" "b escapes to heap" "\[\]interface {}{...} does not escape"
+ isink = FooL(s)
+}
--- /dev/null
+// run
+
+// Copyright 2015 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.
+
+// A generated method with a return value large enough to be
+// initialized by duffzero is not a leaf method, which violated
+// assumptions made by cmd/internal/obj/ppc64.
+
+package main
+
+const N = 9 // values > 8 cause (Super).Method to use duffzero
+
+type Base struct {
+}
+
+func (b *Base) Method() (x [N]uintptr) {
+ return
+}
+
+type Super struct {
+ Base
+}
+
+type T interface {
+ Method() [N]uintptr
+}
+
+func f(q T) {
+ q.Method()
+}
+
+func main() {
+ var s Super
+ f(&s)
+}
--- /dev/null
+// run
+
+// Copyright 2015 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 12133. The CX register was getting clobbered
+// because we did not keep track of its allocation correctly.
+
+package main
+
+import "fmt"
+
+func main() {
+ want := uint(48)
+ got := f1(48)
+ if got != want {
+ fmt.Println("got", got, ", wanted", want)
+ panic("bad")
+ }
+}
+
+//go:noinline
+func f1(v1 uint) uint {
+ return v1 >> ((1 >> v1) + (1 >> v1))
+}
--- /dev/null
+// run
+
+// Copyright 2015 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 "fmt"
+
+func main() {
+ if []byte("foo")[0] == []byte("b")[0] {
+ fmt.Println("BUG: \"foo\" and \"b\" appear to have the same first byte")
+ }
+}
--- /dev/null
+// compile
+
+// Copyright 2015 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
+
+func f_ssa(x int, p *int) {
+ if false {
+ y := x + 5
+ for {
+ *p = y
+ }
+ }
+}
--- /dev/null
+// +build !386
+// run
+
+// Copyright 2015 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 12411. Loss of AX during %.
+
+package main
+
+func main() {
+ x := f(4)
+ if x != 0 {
+ println("BUG: x=", x)
+ }
+}
+
+//go:noinline
+func f(x int) int {
+ // AX was live on entry to one of the % code generations,
+ // and the % code generation smashed it.
+ return ((2 * x) % 3) % (2 % ((x << 2) ^ (x % 3)))
+}
--- /dev/null
+// compile
+
+// Copyright 2015 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 12413: invalid variable name x in type switch: code would fail
+// to compile if the variable used in the short variable declaration was
+// previously declared as a constant.
+
+package main
+
+func main() {
+ const x = 42
+ switch x := interface{}(nil).(type) {
+ default:
+ _ = x
+ }
+}
--- /dev/null
+// compile
+
+// Copyright 2017 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 12536: compiler crashes while checking keys in a map literal for equality
+
+package p
+
+func main() {
+ m1 := map[interface{}]interface{}{
+ nil: 0,
+ true: 1,
+ }
+ m2 := map[interface{}]interface{}{
+ true: 1,
+ nil: 0,
+ }
+ println(len(m1))
+ println(len(m2))
+}
--- /dev/null
+// run
+
+// Copyright 2015 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 12577: Test that there are no -0 floating-point constants.
+
+package main
+
+import "math"
+
+const (
+ z0 = 0.0
+ z1 = -0.0
+ z2 = -z0
+ z3 = -z2
+)
+
+var (
+ x0 float32 = z0
+ x1 float32 = z1
+ x2 float32 = z2
+ x3 float32 = z3
+
+ y0 float64 = z0
+ y1 float64 = z1
+ y2 float64 = z2
+ y3 float64 = z3
+)
+
+func test32(f float32) {
+ if f != 0 || math.Signbit(float64(f)) {
+ println("BUG: got", f, "want 0.0")
+ return
+ }
+}
+
+func test64(f float64) {
+ if f != 0 || math.Signbit(f) {
+ println("BUG: got", f, "want 0.0")
+ return
+ }
+}
+
+func main() {
+ if f := -x0; f != 0 || !math.Signbit(float64(f)) {
+ println("BUG: got", f, "want -0.0")
+ }
+
+ test32(-0.0)
+ test32(x0)
+ test32(x1)
+ test32(x2)
+ test32(x3)
+
+ if f := -y0; f != 0 || !math.Signbit(f) {
+ println("BUG: got", f, "want -0.0")
+ }
+
+ test64(-0.0)
+ test64(y0)
+ test64(y1)
+ test64(y2)
+ test64(y3)
+}
--- /dev/null
+// errorcheck -0 -m -l
+
+// Copyright 2015 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.
+
+// Tests escape analysis for range of arrays.
+// Compiles but need not run. Inlining is disabled.
+
+package main
+
+type A struct {
+ b [3]uint64
+}
+
+type B struct {
+ b [3]*uint64
+}
+
+func f(a A) int {
+ for i, x := range &a.b {
+ if x != 0 {
+ return 64*i + int(x)
+ }
+ }
+ return 0
+}
+
+func g(a *A) int { // ERROR "a does not escape"
+ for i, x := range &a.b {
+ if x != 0 {
+ return 64*i + int(x)
+ }
+ }
+ return 0
+}
+
+func h(a *B) *uint64 { // ERROR "leaking param: a to result ~r1 level=1"
+ for i, x := range &a.b {
+ if i == 0 {
+ return x
+ }
+ }
+ return nil
+}
+
+func h2(a *B) *uint64 { // ERROR "leaking param: a to result ~r1 level=1"
+ p := &a.b
+ for i, x := range p {
+ if i == 0 {
+ return x
+ }
+ }
+ return nil
+}
+
+// Seems like below should be level=1, not 0.
+func k(a B) *uint64 { // ERROR "leaking param: a to result ~r1 level=0"
+ for i, x := range &a.b {
+ if i == 0 {
+ return x
+ }
+ }
+ return nil
+}
+
+var sink *uint64
+
+func main() {
+ var a1, a2 A
+ var b1, b2, b3, b4 B
+ var x1, x2, x3, x4 uint64 // ERROR "moved to heap: x1" "moved to heap: x3"
+ b1.b[0] = &x1
+ b2.b[0] = &x2
+ b3.b[0] = &x3
+ b4.b[0] = &x4
+ f(a1)
+ g(&a2)
+ sink = h(&b1)
+ h(&b2)
+ sink = h2(&b1)
+ h2(&b4)
+ x1 = 17
+ println("*sink=", *sink) // Verify that sink addresses x1
+ x3 = 42
+ sink = k(b3)
+ println("*sink=", *sink) // Verify that sink addresses x3
+}
--- /dev/null
+// Copyright 2015 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
+func Baz(f int) float64 {
+ return 1 / float64(int(1)<<(uint(f)))
+}
--- /dev/null
+// Copyright 2015 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 q
+import "./p"
+func f() { println(p.Baz(2)) }
--- /dev/null
+// compiledir
+
+// Copyright 2015 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 12677: Type loss during export/import of inlined function body.
+
+package ignored
--- /dev/null
+// compile
+
+// Copyright 2015 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.
+
+// golang.org/issue/12686.
+// interesting because it's a non-constant but ideal value
+// and we used to incorrectly attach a constant Val to the Node.
+
+package p
+
+func f(i uint) uint {
+ x := []uint{1 << i}
+ return x[0]
+}
--- /dev/null
+// run
+
+// 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.
+
+package main
+
+var a = 1
+
+func main() {
+ defer func() {
+ recover()
+ if a != 2 {
+ println("BUG a =", a)
+ }
+ }()
+ a = 2
+ b := a - a
+ c := 4
+ a = c / b
+ a = 3
+}
--- /dev/null
+// run
+
+// Copyright 2015 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 (
+ "fmt"
+ "runtime"
+)
+
+const N = 100000
+
+func main() {
+ // Allocate more Ps than processors. This raises
+ // the chance that we get interrupted by the OS
+ // in exactly the right (wrong!) place.
+ p := runtime.NumCPU()
+ runtime.GOMAXPROCS(2 * p)
+
+ // Allocate some pointers.
+ ptrs := make([]*int, p)
+ for i := 0; i < p; i++ {
+ ptrs[i] = new(int)
+ }
+
+ // Arena where we read and write pointers like crazy.
+ collider := make([]*int, p)
+
+ done := make(chan struct{}, 2*p)
+
+ // Start writers. They alternately write a pointer
+ // and nil to a slot in the collider.
+ for i := 0; i < p; i++ {
+ i := i
+ go func() {
+ for j := 0; j < N; j++ {
+ // Write a pointer using memmove.
+ copy(collider[i:i+1], ptrs[i:i+1])
+ // Write nil using memclr.
+ // (This is a magic loop that gets lowered to memclr.)
+ r := collider[i : i+1]
+ for k := range r {
+ r[k] = nil
+ }
+ }
+ done <- struct{}{}
+ }()
+ }
+ // Start readers. They read pointers from slots
+ // and make sure they are valid.
+ for i := 0; i < p; i++ {
+ i := i
+ go func() {
+ for j := 0; j < N; j++ {
+ var ptr [1]*int
+ copy(ptr[:], collider[i:i+1])
+ if ptr[0] != nil && ptr[0] != ptrs[i] {
+ panic(fmt.Sprintf("bad pointer read %p!", ptr[0]))
+ }
+ }
+ done <- struct{}{}
+ }()
+ }
+ for i := 0; i < 2*p; i++ {
+ <-done
+ }
+}
--- /dev/null
+// run
+
+// Copyright 2016 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.
+
+// Ensure that range loops over a string have the requisite side-effects.
+
+package main
+
+import (
+ "fmt"
+ "os"
+)
+
+func check(n int) {
+ var i int
+ var r rune
+
+ b := make([]byte, n)
+ for i = range b {
+ b[i] = byte(i + 1)
+ }
+ s := string(b)
+
+ // When n == 0, i is untouched by the range loop.
+ // Picking an initial value of -1 for i makes the
+ // "want" calculation below correct in all cases.
+ i = -1
+ for i = range s {
+ b[i] = s[i]
+ }
+ if want := n - 1; i != want {
+ fmt.Printf("index after range with side-effect = %d want %d\n", i, want)
+ os.Exit(1)
+ }
+
+ i = -1
+ r = '\x00'
+ for i, r = range s {
+ b[i] = byte(r)
+ }
+ if want := n - 1; i != want {
+ fmt.Printf("index after range with side-effect = %d want %d\n", i, want)
+ os.Exit(1)
+ }
+ if want := rune(n); r != want {
+ fmt.Printf("rune after range with side-effect = %q want %q\n", r, want)
+ os.Exit(1)
+ }
+
+ i = -1
+ // i is shadowed here, so its value should be unchanged.
+ for i := range s {
+ b[i] = s[i]
+ }
+ if want := -1; i != want {
+ fmt.Printf("index after range without side-effect = %d want %d\n", i, want)
+ os.Exit(1)
+ }
+
+ i = -1
+ r = -1
+ // i and r are shadowed here, so their values should be unchanged.
+ for i, r := range s {
+ b[i] = byte(r)
+ }
+ if want := -1; i != want {
+ fmt.Printf("index after range without side-effect = %d want %d\n", i, want)
+ os.Exit(1)
+ }
+ if want := rune(-1); r != want {
+ fmt.Printf("rune after range without side-effect = %q want %q\n", r, want)
+ os.Exit(1)
+ }
+}
+
+func main() {
+ check(0)
+ check(1)
+ check(15)
+}
--- /dev/null
+// run
+
+// Copyright 2015 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
+
+type T struct {
+ a, b, c int
+}
+
+func usestack() {
+ usestack1(32)
+}
+func usestack1(d int) byte {
+ if d == 0 {
+ return 0
+ }
+ var b [1024]byte
+ usestack1(d - 1)
+ return b[3]
+}
+
+const n = 100000
+
+func main() {
+ c := make(chan interface{})
+ done := make(chan bool)
+
+ for i := 0; i < 10; i++ {
+ go func() {
+ for j := 0; j < n; j++ {
+ c <- new(T)
+ }
+ done <- true
+ }()
+ go func() {
+ for j := 0; j < n; j++ {
+ _ = (<-c).(*T)
+ usestack()
+ }
+ done <- true
+ }()
+ }
+ for i := 0; i < 20; i++ {
+ <-done
+ }
+}
--- /dev/null
+// run
+
+// Copyright 2015 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
+
+// Make sure the compiler knows that DUFFCOPY clobbers X0
+
+import "fmt"
+
+//go:noinline
+func f(x float64) float64 {
+ // y is allocated to X0
+ y := x + 5
+ // marshals z before y. Marshaling z
+ // calls DUFFCOPY.
+ return g(z, y)
+}
+
+//go:noinline
+func g(b [64]byte, y float64) float64 {
+ return y
+}
+
+var z [64]byte
+
+func main() {
+ got := f(5)
+ if got != 10 {
+ panic(fmt.Sprintf("want 10, got %f", got))
+ }
+}
--- /dev/null
+// errorcheck
+
+// Copyright 2015 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.
+
+// This program caused an infinite loop with the recursive-descent parser.
+
+package main
+
+func main() {
+ foo( // GCCGO_ERROR "undefined name"
+} // ERROR "unexpected }|expected operand|missing"
--- /dev/null
+// compile
+
+// Copyright 2015 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.
+
+// Taking the address of a parenthesized composite literal is permitted.
+
+package main
+
+type T struct{}
+
+func main() {
+ _ = &T{}
+ _ = &(T{})
+ _ = &((T{}))
+
+ _ = &struct{}{}
+ _ = &(struct{}{})
+ _ = &((struct{}{}))
+
+ switch (&T{}) {}
+ switch &(T{}) {}
+ switch &((T{})) {}
+
+ switch &struct{}{} {}
+ switch &(struct{}{}) {}
+ switch &((struct{}{})) {}
+}
--- /dev/null
+// compile
+
+// Copyright 2016 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 13262: cmd/compile: bogus "fallthrough
+// statement out of place" error
+
+package p
+
+func f() int {
+ var a int
+ switch a {
+ case 0:
+ return func() int { return 1 }()
+ fallthrough
+ default:
+ }
+ return 0
+}
--- /dev/null
+// compile
+
+// Copyright 2016 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
+
+var (
+ x uint
+ y = x
+ z = uintptr(y)
+ a = uint32(y)
+ b = uint64(y)
+)
--- /dev/null
+// errorcheck
+
+// Copyright 2015 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.
+
+// Offending character % must not be interpreted as
+// start of format verb when emitting error message.
+
+package% // ERROR "unexpected %|package name must be an identifier|after package clause|expected declaration"
--- /dev/null
+// run
+
+// Copyright 2015 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.
+
+// Test error message when EOF is encountered in the
+// middle of a BOM.
+//
+// Since the error requires an EOF, we cannot use the
+// errorcheckoutput mechanism.
+
+package main
+
+import (
+ "io/ioutil"
+ "log"
+ "os"
+ "os/exec"
+ "strings"
+)
+
+func main() {
+ // create source
+ f, err := ioutil.TempFile("", "issue13268-")
+ if err != nil {
+ log.Fatalf("could not create source file: %v", err)
+ }
+ f.Write([]byte("package p\n\nfunc \xef\xef")) // if this fails, we will die later
+ f.Close()
+ defer os.Remove(f.Name())
+
+ // compile and test output
+ cmd := exec.Command("go", "tool", "compile", f.Name())
+ out, err := cmd.CombinedOutput()
+ if err == nil {
+ log.Fatalf("expected cmd/compile to fail")
+ }
+ if strings.HasPrefix(string(out), "illegal UTF-8 sequence") {
+ log.Fatalf("error %q not found", out)
+ }
+}
--- /dev/null
+// errorcheck
+
+// Copyright 2015 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.
+
+// Check that we don't ignore EOF.
+
+package p
+
+var f = func() { // ERROR "unexpected EOF|expected .*}.*"
\ No newline at end of file
--- /dev/null
+// compile
+
+// Copyright 2016 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 13337: The Go compiler limited how deeply embedded types
+// were searched for promoted fields and methods.
+
+package s
+
+type S0 struct{ f int }
+func (S0) m() {}
+
+type S1 struct{ S0 }
+type S2 struct{ S1 }
+type S3 struct{ S2 }
+type S4 struct{ S3 }
+type S5 struct{ S4 }
+type S6 struct{ S5 }
+type S7 struct{ S6 }
+type S8 struct{ S7 }
+type S9 struct{ S8 }
+type S10 struct{ S9 }
+type S11 struct{ S10 }
+type S12 struct{ S11 }
+type S13 struct{ S12 }
+
+var _ = S13{}.f
+var _ = S13.m
--- /dev/null
+// errorcheck
+
+// Copyright 2015 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 13365: confusing error message (array vs slice)
+
+package main
+
+var t struct{}
+
+func main() {
+ _ = []int{-1: 0} // ERROR "index must be non\-negative integer constant|index expression is negative"
+ _ = [10]int{-1: 0} // ERROR "index must be non\-negative integer constant|index expression is negative"
+ _ = [...]int{-1: 0} // ERROR "index must be non\-negative integer constant|index expression is negative"
+
+ _ = []int{100: 0}
+ _ = [10]int{100: 0} // ERROR "array index 100 out of bounds|out of range"
+ _ = [...]int{100: 0}
+
+ _ = []int{t} // ERROR "cannot use .* as type int in slice literal|incompatible type"
+ _ = [10]int{t} // ERROR "cannot use .* as type int in array literal|incompatible type"
+ _ = [...]int{t} // ERROR "cannot use .* as type int in array literal|incompatible type"
+}
--- /dev/null
+// errorcheck
+
+// Copyright 2015 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.
+
+// Verify that error message regarding := appears on
+// correct line (and not on the line of the 2nd :=).
+
+package p
+
+func f() {
+ select {
+ case x, x := <-func() chan int { // ERROR "x repeated on left side of :=|redefinition|declared but not used"
+ c := make(chan int)
+ return c
+ }():
+ }
+}
--- /dev/null
+// errorcheck
+
+// Copyright 2015 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.
+
+// Tests for golang.org/issue/13471
+
+package main
+
+func main() {
+ const _ int64 = 1e646456992 // ERROR "integer too large|floating-point constant truncated to integer"
+ const _ int32 = 1e64645699 // ERROR "integer too large|floating-point constant truncated to integer"
+ const _ int16 = 1e6464569 // ERROR "integer too large|floating-point constant truncated to integer"
+ const _ int8 = 1e646456 // ERROR "integer too large|floating-point constant truncated to integer"
+ const _ int = 1e64645 // ERROR "integer too large|floating-point constant truncated to integer"
+
+ const _ uint64 = 1e646456992 // ERROR "integer too large|floating-point constant truncated to integer"
+ const _ uint32 = 1e64645699 // ERROR "integer too large|floating-point constant truncated to integer"
+ const _ uint16 = 1e6464569 // ERROR "integer too large|floating-point constant truncated to integer"
+ const _ uint8 = 1e646456 // ERROR "integer too large|floating-point constant truncated to integer"
+ const _ uint = 1e64645 // ERROR "integer too large|floating-point constant truncated to integer"
+
+ const _ rune = 1e64645 // ERROR "integer too large|floating-point constant truncated to integer"
+}
--- /dev/null
+// errorcheck
+
+// Copyright 2015 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.
+
+// Verify that comparisons of slice/map/func values against converted nil
+// values are properly rejected.
+
+package p
+
+func bug() {
+ type S []byte
+ type M map[int]int
+ type F func()
+
+ var s S
+ var m M
+ var f F
+
+ _ = s == S(nil) // ERROR "compare.*to nil"
+ _ = S(nil) == s // ERROR "compare.*to nil"
+ switch s {
+ case S(nil): // ERROR "compare.*to nil"
+ }
+
+ _ = m == M(nil) // ERROR "compare.*to nil"
+ _ = M(nil) == m // ERROR "compare.*to nil"
+ switch m {
+ case M(nil): // ERROR "compare.*to nil"
+ }
+
+ _ = f == F(nil) // ERROR "compare.*to nil"
+ _ = F(nil) == f // ERROR "compare.*to nil"
+ switch f {
+ case F(nil): // ERROR "compare.*to nil"
+ }
+}
--- /dev/null
+// errorcheck
+
+// Copyright 2010 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 (
+ _ [10]int
+ _ [10.0]int
+ _ [float64(10)]int // ERROR "invalid array bound"
+ _ [10 + 0i]int
+ _ [complex(10, 0)]int
+ _ [complex128(complex(10, 0))]int // ERROR "invalid array bound"
+ _ ['a']int
+ _ [rune(65)]int
+)
--- /dev/null
+// errorcheck
+
+// Copyright 2015 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.
+
+// Verify that a label named like a package is recognized
+// as a label rather than a package and that the package
+// remains unused.
+
+package main
+
+import "math" // ERROR "imported and not used"
+
+func main() {
+math:
+ for {
+ break math
+ }
+}
--- /dev/null
+// run
+
+// Copyright 2015 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.
+
+// Verify that a label name matching a constant name
+// is permitted.
+
+package main
+
+const labelname = 1
+
+func main() {
+ goto labelname
+labelname:
+}
--- /dev/null
+package burnin
+
+type sendCmdFunc func(string)
+
+func sendCommand(c string) {}
+
+func NewSomething() {
+ // This works...
+ // var sendCmd sendCmdFunc
+ // sendCmd = sendCommand
+
+ // So does this...
+ //sendCmd := sendCmdFunc(sendCommand)
+
+ // This fails...
+ sendCmd := sendCommand
+
+ _ = sendCmd
+}
--- /dev/null
+// build
+
+package main
+
+import (
+ x "./burnin"
+)
+
+func main() {
+ x.NewSomething()
+}
--- /dev/null
+// rundir
+
+// Copyright 2015 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 ignored
--- /dev/null
+// errorcheck -0 -m -l
+
+// Copyright 2015 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.
+
+// Test, using compiler diagnostic flags, that the escape analysis is working.
+// Compiles but does not run. Inlining is disabled.
+// Registerization is disabled too (-N), which should
+// have no effect on escape analysis.
+
+package main
+
+import "fmt"
+
+func main() {
+ // Just run test over and over again. This main func is just for
+ // convenience; if test were the main func, we could also trigger
+ // the panic just by running the program over and over again
+ // (sometimes it takes 1 time, sometimes it takes ~4,000+).
+ for iter := 0; ; iter++ {
+ if iter%50 == 0 {
+ fmt.Println(iter) // ERROR "iter escapes to heap$" "... argument does not escape$"
+ }
+ test1(iter)
+ test2(iter)
+ test3(iter)
+ test4(iter)
+ test5(iter)
+ test6(iter)
+ }
+}
+
+func test1(iter int) {
+
+ const maxI = 500
+ m := make(map[int][]int) // ERROR "make\(map\[int\]\[\]int\) escapes to heap$"
+
+ // The panic seems to be triggered when m is modified inside a
+ // closure that is both recursively called and reassigned to in a
+ // loop.
+
+ // Cause of bug -- escape of closure failed to escape (shared) data structures
+ // of map. Assign to fn declared outside of loop triggers escape of closure.
+ // Heap -> stack pointer eventually causes badness when stack reallocation
+ // occurs.
+
+ var fn func() // ERROR "moved to heap: fn$"
+ for i := 0; i < maxI; i++ { // ERROR "moved to heap: i$"
+ // var fn func() // this makes it work, because fn stays off heap
+ j := 0 // ERROR "moved to heap: j$"
+ fn = func() { // ERROR "func literal escapes to heap$"
+ m[i] = append(m[i], 0)
+ if j < 25 {
+ j++
+ fn()
+ }
+ }
+ fn()
+ }
+
+ if len(m) != maxI {
+ panic(fmt.Sprintf("iter %d: maxI = %d, len(m) = %d", iter, maxI, len(m))) // ERROR "iter escapes to heap$" "len\(m\) escapes to heap$" "maxI escapes to heap$" "... argument does not escape$"
+ }
+}
+
+func test2(iter int) {
+
+ const maxI = 500
+ m := make(map[int][]int) // ERROR "make\(map\[int\]\[\]int\) does not escape$"
+
+ // var fn func()
+ for i := 0; i < maxI; i++ {
+ var fn func() // this makes it work, because fn stays off heap
+ j := 0
+ fn = func() { // ERROR "func literal does not escape$"
+ m[i] = append(m[i], 0)
+ if j < 25 {
+ j++
+ fn()
+ }
+ }
+ fn()
+ }
+
+ if len(m) != maxI {
+ panic(fmt.Sprintf("iter %d: maxI = %d, len(m) = %d", iter, maxI, len(m))) // ERROR "iter escapes to heap$" "len\(m\) escapes to heap$" "maxI escapes to heap$" "... argument does not escape$"
+ }
+}
+
+func test3(iter int) {
+
+ const maxI = 500
+ var x int // ERROR "moved to heap: x$"
+ m := &x
+
+ var fn func() // ERROR "moved to heap: fn$"
+ for i := 0; i < maxI; i++ {
+ // var fn func() // this makes it work, because fn stays off heap
+ j := 0 // ERROR "moved to heap: j$"
+ fn = func() { // ERROR "func literal escapes to heap$"
+ if j < 100 {
+ j++
+ fn()
+ } else {
+ *m = *m + 1
+ }
+ }
+ fn()
+ }
+
+ if *m != maxI {
+ panic(fmt.Sprintf("iter %d: maxI = %d, *m = %d", iter, maxI, *m)) // ERROR "\*m escapes to heap$" "iter escapes to heap$" "maxI escapes to heap$" "... argument does not escape$"
+ }
+}
+
+func test4(iter int) {
+
+ const maxI = 500
+ var x int
+ m := &x
+
+ // var fn func()
+ for i := 0; i < maxI; i++ {
+ var fn func() // this makes it work, because fn stays off heap
+ j := 0
+ fn = func() { // ERROR "func literal does not escape$"
+ if j < 100 {
+ j++
+ fn()
+ } else {
+ *m = *m + 1
+ }
+ }
+ fn()
+ }
+
+ if *m != maxI {
+ panic(fmt.Sprintf("iter %d: maxI = %d, *m = %d", iter, maxI, *m)) // ERROR "\*m escapes to heap$" "iter escapes to heap$" "maxI escapes to heap$" "... argument does not escape$"
+ }
+}
+
+type str struct {
+ m *int
+}
+
+func recur1(j int, s *str) { // ERROR "s does not escape"
+ if j < 100 {
+ j++
+ recur1(j, s)
+ } else {
+ *s.m++
+ }
+}
+
+func test5(iter int) {
+
+ const maxI = 500
+ var x int // ERROR "moved to heap: x$"
+ m := &x
+
+ var fn *str
+ for i := 0; i < maxI; i++ {
+ // var fn *str // this makes it work, because fn stays off heap
+ fn = &str{m} // ERROR "&str{...} escapes to heap"
+ recur1(0, fn)
+ }
+
+ if *m != maxI {
+ panic(fmt.Sprintf("iter %d: maxI = %d, *m = %d", iter, maxI, *m)) // ERROR "\*m escapes to heap$" "iter escapes to heap$" "maxI escapes to heap$" "... argument does not escape$"
+ }
+}
+
+func test6(iter int) {
+
+ const maxI = 500
+ var x int
+ m := &x
+
+ // var fn *str
+ for i := 0; i < maxI; i++ {
+ var fn *str // this makes it work, because fn stays off heap
+ fn = &str{m} // ERROR "&str{...} does not escape"
+ recur1(0, fn)
+ }
+
+ if *m != maxI {
+ panic(fmt.Sprintf("iter %d: maxI = %d, *m = %d", iter, maxI, *m)) // ERROR "\*m escapes to heap$" "iter escapes to heap$" "maxI escapes to heap$" "... argument does not escape$"
+ }
+}
--- /dev/null
+// compile
+
+// Copyright 2015 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 13821. Compiler rejected "bool(true)" as not a constant.
+
+package p
+
+const (
+ A = true
+ B = bool(A)
+ C = bool(true)
+)
--- /dev/null
+// errorcheck
+
+// Copyright 2015 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 13821. Additional regress tests.
+
+package p
+
+type B bool
+type B2 bool
+
+var b B
+var b2 B2
+var x1 = b && 1 < 2 // x1 has type B, not ideal bool
+var x2 = 1 < 2 && b // x2 has type B, not ideal bool
+var x3 = b && b2 // ERROR "mismatched types B and B2|incompatible types"
+var x4 = x1 && b2 // ERROR "mismatched types B and B2|incompatible types"
+var x5 = x2 && b2 // ERROR "mismatched types B and B2|incompatible types"
+var x6 = b2 && x1 // ERROR "mismatched types B2 and B|incompatible types"
+var x7 = b2 && x2 // ERROR "mismatched types B2 and B|incompatible types"
+
+var x8 = b && !B2(true) // ERROR "mismatched types B and B2|incompatible types"
--- /dev/null
+// errorcheck
+
+// Copyright 2016 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.
+
+// Literals that happen to resolve to named constants
+// may be used as label names (see issue 13684). Make
+// sure that other literals don't crash the compiler.
+
+package main
+
+const labelname = 1
+
+func main() {
+ goto labelname
+labelname:
+}
+
+func f() {
+ var x int
+ switch x {
+ case 1:
+ 2: // ERROR "unexpected :|expected .*;.* or .*}.* or newline|value computed is not used"
+ case 2:
+ }
+
+ switch x {
+ case 1:
+ 2: ; // ERROR "unexpected :|expected .*;.* or .*}.* or newline|value computed is not used"
+ case 2:
+ }
+
+ var y string
+ switch y {
+ case "foo":
+ "bar": // ERROR "unexpected :|expected .*;.* or .*}.* or newline|value computed is not used"
+ case "bar":
+ }
+
+ switch y {
+ case "foo":
+ "bar": ; // ERROR "unexpected :|expected .*;.* or .*}.* or newline|value computed is not used"
+ case "bar":
+ }
+
+ var z bool
+ switch {
+ case z:
+ labelname: // ERROR "missing statement after label"
+ case false:
+ }
+}
+
+func g() {
+ var z bool
+ switch {
+ case z:
+ labelname: // ERROR "label labelname defined and not used|previous definition|defined and not used"
+ }
+
+ switch {
+ case z:
+ labelname: ; // ERROR "label labelname already defined at LINE-5|label .*labelname.* already defined"
+ case false:
+ }
+}
--- /dev/null
+// errorcheck
+
+// Copyright 2016 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.
+
+// Verify that built-in types don't get printed with
+// (empty) package qualification.
+
+package main
+
+func main() {
+ true = false // ERROR "cannot assign to true|invalid left hand side"
+ byte = 0 // ERROR "not an expression|invalid left hand side|invalid use of type"
+}
--- /dev/null
+// errorcheck
+
+// Copyright 2016 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.
+
+// Test that > 10 non-syntax errors on the same line
+// don't lead to early exit. Specifically, here test
+// that we see the initialization error for variable
+// s.
+
+package main
+
+type T struct{}
+
+func main() {
+ t := T{X: 1, X: 1, X: 1, X: 1, X: 1, X: 1, X: 1, X: 1, X: 1, X: 1} // ERROR "unknown field 'X' in struct literal of type T|unknown field .*X.* in .*T.*"
+ var s string = 1 // ERROR "cannot use 1|incompatible type"
+}
--- /dev/null
+// Copyright 2016 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
+
+// F is an exported function, small enough to be inlined.
+// It defines a local interface with an unexported method
+// f, which will appear with a package-qualified method
+// name in the export data.
+func F(x interface{}) bool {
+ _, ok := x.(interface {
+ f()
+ })
+ return ok
+}
+
+// Like F but with the unexported interface method f
+// defined via an embedded interface t. The compiler
+// always flattens embedded interfaces so there should
+// be no difference between F and G. Alas, currently
+// G is not inlineable (at least via export data), so
+// the issue is moot, here.
+func G(x interface{}) bool {
+ type t0 interface {
+ f()
+ }
+ _, ok := x.(interface {
+ t0
+ })
+ return ok
+}
+
+// Like G but now the embedded interface is declared
+// at package level. This function is inlineable via
+// export data. The export data representation is like
+// for F.
+func H(x interface{}) bool {
+ _, ok := x.(interface {
+ t1
+ })
+ return ok
+}
+
+type t1 interface {
+ f()
+}
--- /dev/null
+// Copyright 2016 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
+
+// Verify that we can import package "a" containing an inlineable
+// function F that declares a local interface with a non-exported
+// method f.
+import _ "./a"
+
+func main() {}
--- /dev/null
+// compiledir
+
+// Copyright 2016 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.
+
+ignored
--- /dev/null
+// Copyright 2016 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
+
+var S struct {
+ Str string `tag`
+}
+
+func F() string {
+ v := S
+ return v.Str
+}
--- /dev/null
+// Copyright 2016 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 G() string {
+ return a.F()
+}
--- /dev/null
+// compiledir
+
+// Copyright 2016 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.
+
+// Inline function misses struct tags.
+
+package ignored
--- /dev/null
+// compile
+
+// Copyright 2016 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.
+
+// Mention of field with large offset in struct literal causes crash
+package p
+
+type T struct {
+ Slice [1 << 20][]int
+ Ptr *int
+}
+
+func New(p *int) *T {
+ return &T{Ptr: p}
+}
--- /dev/null
+// errorcheck
+
+// Copyright 2016 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 f
+
+import /* // ERROR "import path" */ `
+bogus`
+
+func f(x int /* // GC_ERROR "unexpected newline"
+
+*/) // GCCGO_ERROR "expected .*\).*|expected declaration"
--- /dev/null
+// run
+
+// Copyright 2016 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.
+
+// This test checks if the compiler's internal constant
+// arithmetic correctly rounds denormal float32 values.
+
+package main
+
+import (
+ "fmt"
+ "math"
+)
+
+func main() {
+ for _, t := range []struct {
+ value float32
+ bits uint32
+ }{
+ {0e+00, 0x00000000},
+ {1e-46, 0x00000000},
+ {0.5e-45, 0x00000000},
+ {0.8e-45, 0x00000001},
+ {1e-45, 0x00000001},
+ {2e-45, 0x00000001},
+ {3e-45, 0x00000002},
+ {4e-45, 0x00000003},
+ {5e-45, 0x00000004},
+ {6e-45, 0x00000004},
+ {7e-45, 0x00000005},
+ {8e-45, 0x00000006},
+ {9e-45, 0x00000006},
+ {1.0e-44, 0x00000007},
+ {1.1e-44, 0x00000008},
+ {1.2e-44, 0x00000009},
+ } {
+ got := math.Float32bits(t.value)
+ want := t.bits
+ if got != want {
+ panic(fmt.Sprintf("bits(%g) = 0x%08x; want 0x%08x", t.value, got, want))
+ }
+ }
+}
--- /dev/null
+// run
+
+// Copyright 2016 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.
+
+// Test to make sure we don't think values are dead
+// when they are assigned to a PPARAMOUT slot before
+// the last GC safepoint.
+
+package main
+
+import (
+ "fmt"
+ "runtime"
+)
+
+// When a T is deallocated, T[1] is certain to
+// get clobbered (the runtime writes 0xdeaddeaddeaddead there).
+type T [4]int
+
+func f() (r, s *T) {
+ r = &T{0x30, 0x31, 0x32, 0x33}
+ runtime.GC()
+ s = &T{0x40, 0x41, 0x42, 0x43}
+ runtime.GC()
+ return
+}
+
+func main() {
+ r, s := f()
+ if r[1] != 0x31 {
+ fmt.Printf("bad r[1], want 0x31 got %x\n", r[1])
+ }
+ if s[1] != 0x41 {
+ fmt.Printf("bad s[1], want 0x41 got %x\n", s[1])
+ }
+}
--- /dev/null
+// +build !nacl,!js,!android
+// run
+
+// Copyright 2016 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 (
+ "bytes"
+ "log"
+ "os/exec"
+ "strings"
+)
+
+func main() {
+ checkLinkOutput("", "-B argument must start with 0x")
+ checkLinkOutput("0", "-B argument must start with 0x")
+ checkLinkOutput("0x", "usage")
+ checkLinkOutput("0x0", "-B argument must have even number of digits")
+ checkLinkOutput("0x00", "usage")
+ checkLinkOutput("0xYZ", "-B argument contains invalid hex digit")
+ checkLinkOutput("0x"+strings.Repeat("00", 32), "usage")
+ checkLinkOutput("0x"+strings.Repeat("00", 33), "-B option too long (max 32 digits)")
+}
+
+func checkLinkOutput(buildid string, message string) {
+ cmd := exec.Command("go", "tool", "link", "-B", buildid)
+ out, err := cmd.CombinedOutput()
+ if err == nil {
+ log.Fatalf("expected cmd/link to fail")
+ }
+
+ firstLine := string(bytes.SplitN(out, []byte("\n"), 2)[0])
+ if strings.HasPrefix(firstLine, "panic") {
+ log.Fatalf("cmd/link panicked:\n%s", out)
+ }
+
+ if !strings.Contains(firstLine, message) {
+ log.Fatalf("cmd/link output did not include expected message %q: %s", message, firstLine)
+ }
+}
--- /dev/null
+// run
+
+// Copyright 2016 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 "runtime"
+
+func main() {
+ var file string
+ var line int
+ func() {
+ defer func() {
+ _, file, line, _ = runtime.Caller(1)
+ }()
+ }() // this is the expected line
+ const EXPECTED = 18
+ if line != EXPECTED {
+ println("Expected line =", EXPECTED, "but got line =", line, "and file =", file)
+ }
+}
--- /dev/null
+// run
+
+// Copyright 2016 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.
+
+// This test checks if the compiler's internal constant
+// arithmetic correctly rounds up floating-point values
+// that become the smallest denormal value.
+//
+// See also related issue 14553 and test issue14553.go.
+
+package main
+
+import (
+ "fmt"
+ "math"
+)
+
+const (
+ p149 = 1.0 / (1 << 149) // 1p-149
+ p500 = 1.0 / (1 << 500) // 1p-500
+ p1074 = p500 * p500 / (1<<74) // 1p-1074
+)
+
+const (
+ m0000p149 = 0x0 / 16.0 * p149 // = 0.0000p-149
+ m1000p149 = 0x8 / 16.0 * p149 // = 0.1000p-149
+ m1001p149 = 0x9 / 16.0 * p149 // = 0.1001p-149
+ m1011p149 = 0xb / 16.0 * p149 // = 0.1011p-149
+ m1100p149 = 0xc / 16.0 * p149 // = 0.1100p-149
+
+ m0000p1074 = 0x0 / 16.0 * p1074 // = 0.0000p-1074
+ m1000p1074 = 0x8 / 16.0 * p1074 // = 0.1000p-1074
+ m1001p1074 = 0x9 / 16.0 * p1074 // = 0.1001p-1074
+ m1011p1074 = 0xb / 16.0 * p1074 // = 0.1011p-1074
+ m1100p1074 = 0xc / 16.0 * p1074 // = 0.1100p-1074
+)
+
+func main() {
+ test32(float32(m0000p149), f32(m0000p149))
+ test32(float32(m1000p149), f32(m1000p149))
+ test32(float32(m1001p149), f32(m1001p149))
+ test32(float32(m1011p149), f32(m1011p149))
+ test32(float32(m1100p149), f32(m1100p149))
+
+ test64(float64(m0000p1074), f64(m0000p1074))
+ test64(float64(m1000p1074), f64(m1000p1074))
+ test64(float64(m1001p1074), f64(m1001p1074))
+ test64(float64(m1011p1074), f64(m1011p1074))
+ test64(float64(m1100p1074), f64(m1100p1074))
+}
+
+func f32(x float64) float32 { return float32(x) }
+func f64(x float64) float64 { return float64(x) }
+
+func test32(a, b float32) {
+ abits := math.Float32bits(a)
+ bbits := math.Float32bits(b)
+ if abits != bbits {
+ panic(fmt.Sprintf("%08x != %08x\n", abits, bbits))
+ }
+}
+
+func test64(a, b float64) {
+ abits := math.Float64bits(a)
+ bbits := math.Float64bits(b)
+ if abits != bbits {
+ panic(fmt.Sprintf("%016x != %016x\n", abits, bbits))
+ }
+}
--- /dev/null
+// errorcheck
+
+// Copyright 2016 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 x any // ERROR "undefined: any|undefined type .*any.*"
--- /dev/null
+// run
+
+// Copyright 2016 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 "fmt"
+
+func f1() (x int) {
+ for {
+ defer func() {
+ recover()
+ x = 1
+ }()
+ panic(nil)
+ }
+}
+
+var sink *int
+
+func f2() (x int) {
+ sink = &x
+ defer func() {
+ recover()
+ x = 1
+ }()
+ panic(nil)
+}
+
+func f3(b bool) (x int) {
+ sink = &x
+ defer func() {
+ recover()
+ x = 1
+ }()
+ if b {
+ panic(nil)
+ }
+ return
+}
+
+func main() {
+ if x := f1(); x != 1 {
+ panic(fmt.Sprintf("f1 returned %d, wanted 1", x))
+ }
+ if x := f2(); x != 1 {
+ panic(fmt.Sprintf("f2 returned %d, wanted 1", x))
+ }
+ if x := f3(true); x != 1 {
+ panic(fmt.Sprintf("f3(true) returned %d, wanted 1", x))
+ }
+ if x := f3(false); x != 1 {
+ panic(fmt.Sprintf("f3(false) returned %d, wanted 1", x))
+ }
+}
--- /dev/null
+// errorcheck
+
+// Copyright 2016 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 14729: structs cannot embed unsafe.Pointer per the spec.
+
+package main
+
+import "unsafe"
+
+type s struct { unsafe.Pointer } // ERROR "embedded type cannot be a pointer|embedded type may not be a pointer"
+type s1 struct { p unsafe.Pointer }
--- /dev/null
+// errorcheck
+
+// Copyright 2016 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 14988: defining a map with an invalid forward declaration array
+// key doesn't cause a fatal.
+
+package main
+
+type m map[k]int // ERROR "invalid map key type"
+type k [1]m
--- /dev/null
+// compile
+
+// Copyright 2016 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.
+
+// CL 21202 introduced a compiler crash in the handling of a varargs
+// function in the same recursive group as a function that calls it.
+// Nothing in the standard library caught the problem, so adding a test.
+
+package p
+
+func F1(p *int, a ...*int) (int, *int) {
+ if p == nil {
+ return F2(), a[0]
+ }
+ return 0, a[0]
+}
+
+func F2() int {
+ var i0, i1 int
+ a, _ := F1(&i0, &i1)
+ return a
+}
--- /dev/null
+// run
+
+// Copyright 2016 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
+
+func main() {
+ const fffd = "\uFFFD"
+
+ // runtime.intstring used to convert int64 to rune without checking
+ // for truncation.
+ u := uint64(0x10001f4a9)
+ big := string(u)
+ if big != fffd {
+ panic("big != bad")
+ }
+
+ // cmd/compile used to require integer constants to fit into an "int".
+ const huge = string(1<<100)
+ if huge != fffd {
+ panic("huge != bad")
+ }
+}
--- /dev/null
+// run
+
+// Copyright 2016 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.
+
+// Exchanging two struct fields was compiled incorrectly.
+
+package main
+
+type S struct {
+ i int
+}
+
+func F(c bool, s1, s2 S) (int, int) {
+ if c {
+ s1.i, s2.i = s2.i, s1.i
+ }
+ return s1.i, s2.i
+}
+
+func main() {
+ i, j := F(true, S{1}, S{20})
+ if i != 20 || j != 1 {
+ panic(i+j)
+ }
+}
--- /dev/null
+// Copyright 2016 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 exp
+
+func Exported(x int) int {
+ return inlined(x)
+}
+
+func inlined(x int) int {
+ y := 0
+ switch {
+ case x > 0:
+ y += 5
+ return 0 + y
+ case x < 1:
+ y += 6
+ fallthrough
+ default:
+ y += 7
+ return 2 + y
+ }
+}
--- /dev/null
+// run
+
+// Copyright 2016 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 "os"
+import "./exp"
+
+func main() {
+ _ = exp.Exported(len(os.Args))
+}
--- /dev/null
+// rundir
+
+// 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.
+
+package ignored
--- /dev/null
+// compile
+
+// Copyright 2016 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 x
+
+type T struct {
+ i int
+ e interface{}
+}
+
+func (t *T) F() bool {
+ if t.i != 0 {
+ return false
+ }
+ _, ok := t.e.(string)
+ return ok
+}
+
+var x int
+
+func g(t *T) {
+ if t.F() || true {
+ if t.F() {
+ x = 0
+ }
+ }
+}
--- /dev/null
+// compile
+
+// Copyright 2016 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
+
+func main() {
+ a := f(1, 99)
+ b := g(0xFFFFFFe, 98)
+ c := h(0xFFFFFFe, 98)
+ println(a[1], b[1], c[1], a[0xFFFFFFe], b[0xFFFFFFe], c[0xFFFFFFe])
+}
+
+//go:noinline
+func f(i, y int) (a [0xFFFFFFF]byte) {
+ a[i] = byte(y)
+ return
+}
+
+//go:noinline
+func g(i, y int) [0xFFFFFFF]byte {
+ var a [0xFFFFFFF]byte
+ a[i] = byte(y)
+ return a
+}
+
+//go:noinline
+func h(i, y int) (a [0xFFFFFFF]byte) {
+ a[i] = byte(y)
+ return a
+}
--- /dev/null
+// run
+
+// Copyright 2016 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.
+
+// Make sure unsigned shift results get sign-extended correctly.
+package main
+
+import "fmt"
+
+func main() {
+ failed := false
+ a6 := uint8(253)
+ if got := a6 >> 0; got != 253 {
+ fmt.Printf("uint8(253)>>0 = %v, wanted 253\n", got)
+ failed = true
+ }
+ if got := f1(0, 2, 1, 0, 0, 1, true); got != 255 {
+ fmt.Printf("f1(...) = %v, wanted 255\n", got)
+ failed = true
+ }
+ if got := f2(1); got != 242 {
+ fmt.Printf("f2(...) = %v, wanted 242\n", got)
+ failed = true
+ }
+ if got := f3(false, 0, 0); got != 254 {
+ fmt.Printf("f3(...) = %v, wanted 254\n", got)
+ failed = true
+ }
+ if failed {
+ panic("bad")
+ }
+}
+
+func f1(a1 uint, a2 int8, a3 int8, a4 int8, a5 uint8, a6 int, a7 bool) uint8 {
+ a5--
+ a4 += (a2 << a1 << 2) | (a4 ^ a4<<(a1&a1)) - a3 // int8
+ a6 -= a6 >> (2 + uint32(a2)>>3) // int
+ a1 += a1 // uint
+ a3 *= a4 << (a1 | a1) << (uint16(3) >> 2 & (1 - 0) & (uint16(1) << a5 << 3)) // int8
+ a7 = a7 || ((a2 == a4) || (a7 && a7) || ((a5 == a5) || (a7 || a7))) // bool
+ return a5 >> a1
+}
+
+func f2(a1 uint8) uint8 {
+ a1--
+ a1--
+ a1 -= a1 + (a1 << 1) - (a1*a1*a1)<<(2-0+(3|3)-1) // uint8
+ v1 := 0 * ((2 * 1) ^ 1) & ((uint(0) >> a1) + (2+0)*(uint(2)+0)) // uint
+ _ = v1
+ return a1 >> (((2 ^ 2) >> (v1 | 2)) + 0)
+}
+
+func f3(a1 bool, a2 uint, a3 int64) uint8 {
+ a3--
+ v1 := 1 & (2 & 1 * (1 ^ 2) & (uint8(3*1) >> 0)) // uint8
+ _ = v1
+ v1 += v1 - (v1 >> a2) + (v1 << (a2 ^ a2) & v1) // uint8
+ v1 *= v1 // uint8
+ a3--
+ v1 += v1 & v1 // uint8
+ v1--
+ v1 = ((v1 << 0) | v1>>0) + v1 // uint8
+ return v1 >> 0
+}
--- /dev/null
+// run
+
+// Copyright 2016 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.
+
+// This test makes sure that we use all 64 bits of an
+// index, even on 32 bit machines. It also tests that nacl
+// can compile 64 bit indexes loaded from ODOTPTR properly.
+
+package main
+
+type T struct {
+ i int64
+}
+
+func f(t *T) byte {
+ b := [2]byte{3, 4}
+ return b[t.i]
+}
+
+func main() {
+ t := &T{0x100000001}
+ defer func() {
+ r := recover()
+ if r == nil {
+ panic("panic wasn't recoverable")
+ }
+ }()
+ f(t)
+ panic("index didn't panic")
+}
--- /dev/null
+// run
+
+// Copyright 2016 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.
+// +build amd64
+
+package main
+
+import "runtime"
+
+type big [10 << 20]byte
+
+func f(x *big, start int64) {
+ if delta := inuse() - start; delta < 9<<20 {
+ println("after alloc: expected delta at least 9MB, got: ", delta)
+ }
+ runtime.KeepAlive(x)
+ x = nil
+ if delta := inuse() - start; delta > 1<<20 {
+ println("after drop: expected delta below 1MB, got: ", delta)
+ }
+ x = new(big)
+ if delta := inuse() - start; delta < 9<<20 {
+ println("second alloc: expected delta at least 9MB, got: ", delta)
+ }
+ runtime.KeepAlive(x)
+}
+
+func main() {
+ x := inuse()
+ f(new(big), x)
+}
+
+func inuse() int64 {
+ runtime.GC()
+ var st runtime.MemStats
+ runtime.ReadMemStats(&st)
+ return int64(st.Alloc)
+}
--- /dev/null
+// run
+
+// Copyright 2016 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.
+
+// Ensure that inlined struct/array comparisons have the right side-effects.
+
+package main
+
+import "os"
+
+func main() {
+ var x int
+ f := func() (r [4]int) {
+ x++
+ return
+ }
+ _ = f() == f()
+ if x != 2 {
+ println("f evaluated ", x, " times, want 2")
+ os.Exit(1)
+ }
+}
--- /dev/null
+// run
+
+// Copyright 2016 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.
+
+// Previously, cmd/compile would rewrite
+//
+// check(unsafe.Pointer(testMeth(1).Pointer()), unsafe.Pointer(testMeth(2).Pointer()))
+//
+// to
+//
+// var autotmp_1 uintptr = testMeth(1).Pointer()
+// var autotmp_2 uintptr = testMeth(2).Pointer()
+// check(unsafe.Pointer(autotmp_1), unsafe.Pointer(autotmp_2))
+//
+// However, that means autotmp_1 is the only reference to the int
+// variable containing the value "1", but it's not a pointer type,
+// so it was at risk of being garbage collected by the evaluation of
+// testMeth(2).Pointer(), even though package unsafe's documentation
+// says the original code was allowed.
+//
+// Now cmd/compile rewrites it to
+//
+// var autotmp_1 unsafe.Pointer = unsafe.Pointer(testMeth(1).Pointer())
+// var autotmp_2 unsafe.Pointer = unsafe.Pointer(testMeth(2).Pointer())
+// check(autotmp_1, autotmp_2)
+//
+// to ensure the pointed-to variables are visible to the GC.
+
+package main
+
+import (
+ "fmt"
+ "reflect"
+ "runtime"
+ "unsafe"
+)
+
+func main() {
+ // Test all the different ways we can invoke reflect.Value.Pointer.
+
+ // Direct method invocation.
+ check(unsafe.Pointer(testMeth(1).Pointer()), unsafe.Pointer(testMeth(2).Pointer()))
+
+ // Invocation via method expression.
+ check(unsafe.Pointer(reflect.Value.Pointer(testMeth(1))), unsafe.Pointer(reflect.Value.Pointer(testMeth(2))))
+
+ // Invocation via interface.
+ check(unsafe.Pointer(testInter(1).Pointer()), unsafe.Pointer(testInter(2).Pointer()))
+
+ // Invocation via method value.
+ check(unsafe.Pointer(testFunc(1)()), unsafe.Pointer(testFunc(2)()))
+}
+
+func check(p, q unsafe.Pointer) {
+ a, b := *(*int)(p), *(*int)(q)
+ if a != 1 || b != 2 {
+ fmt.Printf("got %v, %v; expected 1, 2\n", a, b)
+ }
+}
+
+func testMeth(x int) reflect.Value {
+ // Force GC to run.
+ runtime.GC()
+ return reflect.ValueOf(&x)
+}
+
+type Pointerer interface {
+ Pointer() uintptr
+}
+
+func testInter(x int) Pointerer {
+ return testMeth(x)
+}
+
+func testFunc(x int) func() uintptr {
+ return testMeth(x).Pointer
+}
--- /dev/null
+// run
+
+// Copyright 2016 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"
+
+func main() {
+ a := &struct{ x int }{}
+ b := &struct{ x int "" }{}
+
+ ta := reflect.TypeOf(a)
+ tb := reflect.TypeOf(b)
+
+ // Ensure cmd/compile treats absent and empty tags as equivalent.
+ a = b
+
+ // Ensure package reflect treats absent and empty tags as equivalent.
+ if !tb.AssignableTo(ta) {
+ panic("fail")
+ }
+}
--- /dev/null
+package a
+
+import "io"
+
+type T interface {
+ M0(_ int)
+ M1(x, _ int) // _ (blank) caused crash
+ M2() (x, _ int)
+}
+
+type S struct{}
+
+func (S) M0(_ int) {}
+func (S) M1(x, _ int) {}
+func (S) M2() (x, _ int) { return }
+func (_ S) M3() {}
+
+// Snippet from x/tools/godoc/analysis/analysis.go.
+// Offending code from #5470.
+type Link interface {
+ Start() int
+ End() int
+ Write(w io.Writer, _ int, start bool) // _ (blank) caused crash
+}
--- /dev/null
+package b
+
+import _ "./a" // must not fail
--- /dev/null
+// compiledir
+
+// Copyright 2016 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 15470: Make sure special-case signatures can
+// be exported and imported w/o problems.
+
+package ignored
--- /dev/null
+// Copyright 2016 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 A struct{ _ int32 }
--- /dev/null
+// Copyright 2016 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
+
+func B() (_ struct{ _ int32 }) { return }
--- /dev/null
+// Copyright 2016 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 c
+
+import "./a"
+import "./b"
+
+var _ a.A = b.B() // ERROR "cannot use b\.B|incompatible type"
--- /dev/null
+// errorcheckdir
+
+// Copyright 2016 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 ignored
--- /dev/null
+// run
+
+// Copyright 2016 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 (
+ "fmt"
+ "io"
+ "os"
+ "reflect"
+ "unsafe"
+)
+
+type RWS struct{}
+
+func (x *RWS) Read(p []byte) (n int, err error) { return }
+func (x *RWS) Write(p []byte) (n int, err error) { return }
+func (x *RWS) Seek(offset int64, whence int) (n int64, err error) { return }
+func (x *RWS) String() string { return "rws" }
+
+func makeRWS() io.ReadWriteSeeker { return &RWS{} }
+func makeStringer() fmt.Stringer { return &RWS{} }
+
+// Test correct construction of static empty interface values
+var efaces = [...]struct {
+ x interface{}
+ s string
+}{
+ {nil, "<nil> <nil>"},
+ {1, "int 1"},
+ {int(1), "int 1"},
+ {Int(int(2)), "main.Int Int=2"},
+ {int(Int(3)), "int 3"},
+ {[1]int{2}, "[1]int [2]"},
+ {io.Reader(io.ReadWriter(io.ReadWriteSeeker(nil))), "<nil> <nil>"},
+ {io.Reader(io.ReadWriter(io.ReadWriteSeeker(&RWS{}))), "*main.RWS rws"},
+ {makeRWS(), "*main.RWS rws"},
+ {map[string]string{"here": "there"}, "map[string]string map[here:there]"},
+ {chan bool(nil), "chan bool <nil>"},
+ {unsafe.Pointer(uintptr(0)), "unsafe.Pointer <nil>"},
+ {(*byte)(nil), "*uint8 <nil>"},
+ {io.Writer((*os.File)(nil)), "*os.File <nil>"},
+ {(interface{})(io.Writer((*os.File)(nil))), "*os.File <nil>"},
+ {fmt.Stringer(Strunger(((*Int)(nil)))), "*main.Int <nil>"},
+}
+
+type Int int
+
+func (i Int) String() string { return fmt.Sprintf("Int=%d", i) }
+func (i Int) Strung() {}
+
+type Strunger interface {
+ fmt.Stringer
+ Strung()
+}
+
+// Test correct construction of static non-empty interface values
+var ifaces = [...]struct {
+ x fmt.Stringer
+ s string
+}{
+ {nil, "<nil> <nil> %!s(<nil>)"},
+ {Int(3), "main.Int 3 Int=3"},
+ {Int(int(Int(4))), "main.Int 4 Int=4"},
+ {Strunger(Int(5)), "main.Int 5 Int=5"},
+ {makeStringer(), "*main.RWS &main.RWS{} rws"},
+ {fmt.Stringer(nil), "<nil> <nil> %!s(<nil>)"},
+ {(*RWS)(nil), "*main.RWS (*main.RWS)(nil) rws"},
+}
+
+// Test correct handling of direct interface values
+var (
+ one int = 1
+ iptr interface{} = &one
+ clos int
+ f interface{} = func() { clos++ }
+ deep interface{} = [1]struct{ a *[2]byte }{{a: &[2]byte{'z', 'w'}}}
+ ch interface{} = make(chan bool, 1)
+)
+
+func main() {
+ var fail bool
+ for i, test := range efaces {
+ s := fmt.Sprintf("%[1]T %[1]v", test.x)
+ if s != test.s {
+ fmt.Printf("eface(%d)=%q want %q\n", i, s, test.s)
+ fail = true
+ }
+ }
+
+ for i, test := range ifaces {
+ s := fmt.Sprintf("%[1]T %#[1]v %[1]s", test.x)
+ if s != test.s {
+ fmt.Printf("iface(%d)=%q want %q\n", i, s, test.s)
+ fail = true
+ }
+ }
+
+ if got := *(iptr.(*int)); got != 1 {
+ fmt.Printf("bad int ptr %d\n", got)
+ fail = true
+ }
+
+ f.(func())()
+ f.(func())()
+ f.(func())()
+ if clos != 3 {
+ fmt.Printf("bad closure exec %d\n", clos)
+ fail = true
+ }
+
+ if !reflect.DeepEqual(*(deep.([1]struct{ a *[2]byte })[0].a), [2]byte{'z', 'w'}) {
+ fmt.Printf("bad deep directiface\n")
+ fail = true
+ }
+
+ cc := ch.(chan bool)
+ cc <- true
+ if got := <-cc; !got {
+ fmt.Printf("bad chan\n")
+ fail = true
+ }
+
+ if fail {
+ fmt.Println("BUG")
+ os.Exit(1)
+ }
+}
--- /dev/null
+// Copyright 2016 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 I0 interface {
+ I1
+}
+
+type T struct {
+ I1
+}
+
+type I1 interface {
+ M(*T) // removing * makes crash go away
+}
--- /dev/null
+// Copyright 2016 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"
+
+var X a.T
--- /dev/null
+// Copyright 2016 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 c
+
+import (
+ _ "./b"
+ _ "./a"
+)
--- /dev/null
+// compiledir
+
+// Copyright 2016 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 ignored
--- /dev/null
+// run
+
+// Copyright 2017 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 "unsafe"
+
+const (
+ _ = unsafe.Sizeof(func() int {
+ const (
+ _ = 1
+ _
+ _
+ )
+ return 0
+ }())
+
+ y = iota
+)
+
+func main() {
+ if y != 1 {
+ panic(y)
+ }
+}
--- /dev/null
+// Copyright 2016 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 T struct {
+}
+
+func F() []T {
+ return []T{T{}}
+}
+
+func Fi() []T {
+ return []T{{}} // element with implicit composite literal type
+}
+
+func Fp() []*T {
+ return []*T{&T{}}
+}
+
+func Fip() []*T {
+ return []*T{{}} // element with implicit composite literal type
+}
+
+func Gp() map[int]*T {
+ return map[int]*T{0: &T{}}
+}
+
+func Gip() map[int]*T {
+ return map[int]*T{0: {}} // element with implicit composite literal type
+}
+
+func Hp() map[*T]int {
+ return map[*T]int{&T{}: 0}
+}
+
+func Hip() map[*T]int {
+ return map[*T]int{{}: 0} // key with implicit composite literal type
+}
--- /dev/null
+// Copyright 2016 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() {
+ a.F()
+ a.Fi()
+}
+
+func Fp() {
+ a.Fp()
+ a.Fip()
+}
+
+func Gp() {
+ a.Gp()
+ a.Gip()
+}
+
+func Hp() {
+ a.Hp()
+ a.Hip()
+}
--- /dev/null
+// compiledir
+
+// Copyright 2016 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.
+
+// Test that exporting composite literals with implicit
+// types doesn't crash the typechecker when running over
+// inlined function bodies containing such literals.
+
+package ignored
--- /dev/null
+// compile
+
+// Copyright 2016 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 bug
+
+func example(n int) (rc int) {
+ var cc, ll, pp, rr [27]int
+ for q0 := 0; q0 < n-2; q0++ {
+ for q1 := q0 + 2; q1 < n; q1++ {
+ var c, d, l, p, r int
+ b0 := 1 << uint(q0)
+ b1 := 1 << uint(q1)
+ l = ((b0 << 1) | b1) << 1
+ c = b0 | b1 | (-1 << uint(n))
+ r = ((b0 >> 1) | b1) >> 1
+ E:
+ if c != -1 {
+ p = ^(l | c | r)
+ } else {
+ rc++
+ goto R
+ }
+ L:
+ if p != 0 {
+ lsb := p & -p
+ p &^= lsb
+ ll[d], cc[d], rr[d], pp[d] = l, c, r, p
+ l, c, r = (l|lsb)<<1, c|lsb, (r|lsb)>>1
+ d++
+ goto E
+ }
+ R:
+ d--
+ if d >= 0 {
+ l, c, r, p = ll[d], cc[d], rr[d], pp[d]
+ goto L
+ }
+ }
+ }
+ rc <<= 1
+ return
+}
--- /dev/null
+// compile
+
+// Copyright 2016 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
+
+func f(i interface{}) {
+ i, _ = i.(error)
+}
--- /dev/null
+// compile
+
+// Copyright 2016 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 bug
+
+import "os"
+
+func f(err error) {
+ var ok bool
+ if err, ok = err.(*os.PathError); ok {
+ if err == os.ErrNotExist {
+ }
+ }
+}
--- /dev/null
+// +build !amd64,!386
+
+package main
+
+func jump() {
+ target()
+}
--- /dev/null
+#include "textflag.h"
+
+DATA ·pointer(SB)/4, $·target(SB)
+GLOBL ·pointer(SB),RODATA,$4
+
+TEXT ·jump(SB),NOSPLIT,$4
+ CALL *·pointer(SB)
+ RET
--- /dev/null
+#include "textflag.h"
+
+DATA ·pointer(SB)/8, $·target(SB)
+GLOBL ·pointer(SB),RODATA,$8
+
+TEXT ·jump(SB),NOSPLIT,$8
+ CALL *·pointer(SB)
+ RET
--- /dev/null
+// +build amd64 386
+
+package main
+
+func jump()
--- /dev/null
+package main
+
+var called bool
+
+func target() {
+ called = true
+}
+
+func main() {
+ jump()
+ if !called {
+ panic("target not called")
+ }
+}
--- /dev/null
+// Copyright 2016 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 T struct{}
+
+func (T) m() string {
+ return "m"
+}
+
+func (*T) mp() string {
+ return "mp"
+}
+
+func F() func(T) string {
+ return T.m // method expression
+}
+
+func Fp() func(*T) string {
+ return (*T).mp // method expression
+}
--- /dev/null
+// Copyright 2016 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 "./a" // import must succeed
+
+func main() {
+ if a.F()(a.T{}) != "m" {
+ panic(0)
+ }
+ if a.Fp()(nil) != "mp" {
+ panic(1)
+ }
+}
--- /dev/null
+// rundir
+
+// Copyright 2016 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.
+
+// Test that method expressions are correctly encoded
+// in binary export data and can be imported again.
+package ignore
\ No newline at end of file
--- /dev/null
+// errorcheck
+
+// Copyright 2016 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 to make sure that the compiler can catch a specific invalid
+// method type expression. NB: gccgo and gc have slightly different
+// error messages, hence the generic test for 'method' and not something
+// more specific.
+
+package issue15722
+
+type T int
+type P *T
+
+func (T) t() {}
+
+func _(p P) {
+ P.t(p) // ERROR "method"
+}
--- /dev/null
+// compile
+
+// Copyright 2016 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
+
+type S struct {
+ a [1 << 16]byte
+}
+
+func f1() {
+ p := &S{}
+ _ = p
+}
+
+type T [1 << 16]byte
+
+func f2() {
+ p := &T{}
+ _ = p
+}
--- /dev/null
+// Copyright 2016 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
+
+func F1() {
+L:
+ goto L
+}
+
+func F2() {
+L:
+ for {
+ break L
+ }
+}
+
+func F3() {
+L:
+ for {
+ continue L
+ }
+}
+
+func F4() {
+ switch {
+ case true:
+ fallthrough
+ default:
+ }
+}
+
+type T struct{}
+
+func (T) M1() {
+L:
+ goto L
+}
+
+func (T) M2() {
+L:
+ for {
+ break L
+ }
+}
+
+func (T) M3() {
+L:
+ for {
+ continue L
+ }
+}
+
+func (T) M4() {
+ switch {
+ case true:
+ fallthrough
+ default:
+ }
+}
--- /dev/null
+// Copyright 2016 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"
+
+type T struct{ a.T }
--- /dev/null
+// compiledir
+
+// Copyright 2016 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.
+
+// Test cases for issue #15838, and related failures.
+// Make sure the importer correctly sets up nodes for
+// label decls, goto, continue, break, and fallthrough
+// statements.
+
+package ignored
--- /dev/null
+// compile
+
+// Copyright 2016 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.
+
+// func bad used to fail to compile.
+
+package p
+
+type A [1]int
+
+func bad(x A) {
+ switch x {
+ case A([1]int{1}):
+ case A([1]int{1}):
+ }
+}
+
+func good(x A) {
+ y := A([1]int{1})
+ z := A([1]int{1})
+ switch x {
+ case y:
+ case z:
+ }
+}
--- /dev/null
+// errorcheck
+
+// Copyright 2016 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
+
+func f(e interface{}) {
+ switch e.(type) {
+ case nil, nil: // ERROR "multiple nil cases in type switch|duplicate type in switch"
+ }
+
+ switch e.(type) {
+ case nil:
+ case nil: // ERROR "multiple nil cases in type switch|duplicate type in switch"
+ }
+}
--- /dev/null
+// run
+
+// Copyright 2016 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.
+
+// This test makes sure we don't use 4-byte unaligned writes
+// to zero memory on architectures that don't support them.
+
+package main
+
+type T struct {
+ a byte
+ b [10]byte
+}
+
+//go:noinline
+func f(t *T) {
+ // t will be aligned, so &t.b won't be.
+ t.b = [10]byte{}
+}
+
+var t T
+
+func main() {
+ f(&t)
+}
--- /dev/null
+// Copyright 2016 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 Error error
+
+func F() Error { return nil }
--- /dev/null
+// Copyright 2016 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"
--- /dev/null
+// compiledir
+
+// Copyright 2016 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 ignored
--- /dev/null
+// build
+
+// Copyright 2016 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 15926: linker was adding .def to the end of symbols, causing
+// a name collision with a method actually named def.
+
+package main
+
+type S struct{}
+
+func (s S) def() {}
+
+var I = S.def
+
+func main() {
+ I(S{})
+}
--- /dev/null
+// compile
+
+// Copyright 2016 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 y
+
+type symSet []int
+
+//go:noinline
+func (s symSet) len() (r int) {
+ return 0
+}
+
+func f(m map[int]symSet) {
+ var symSet []int
+ for _, x := range symSet {
+ m[x] = nil
+ }
+}
--- /dev/null
+// compile
+
+// Copyright 2016 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
+
+func f(p, q []int) {
+ p = append(q, 5)
+ sink = &p
+}
+
+var sink *[]int
--- /dev/null
+// run
+
+// Copyright 2018 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 (
+ "fmt"
+)
+
+func f(a []byte) ([]byte, []byte) {
+ return a, []byte("abc")
+}
+
+func g(a []byte) ([]byte, string) {
+ return a, "abc"
+}
+
+func h(m map[int]int) (map[int]int, int) {
+ return m, 0
+}
+
+func main() {
+ a := []byte{1, 2, 3}
+ n := copy(f(a))
+ fmt.Println(n, a)
+
+ b := []byte{1, 2, 3}
+ n = copy(g(b))
+ fmt.Println(n, b)
+
+ m := map[int]int{0: 0}
+ fmt.Println(len(m))
+ delete(h(m))
+ fmt.Println(len(m))
+}
--- /dev/null
+3 [97 98 99]
+3 [97 98 99]
+1
+0
--- /dev/null
+// run
+
+// Copyright 2016 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 "time"
+
+type T struct{}
+
+func (*T) Foo(vals []interface{}) {
+ switch v := vals[0].(type) {
+ case string:
+ _ = v
+ }
+}
+
+type R struct{ *T }
+
+type Q interface {
+ Foo([]interface{})
+}
+
+func main() {
+ var q Q = &R{&T{}}
+ for i := 0; i < 10000; i++ {
+ go func() {
+ defer q.Foo([]interface{}{"meow"})
+ time.Sleep(100 * time.Millisecond)
+ }()
+ }
+ time.Sleep(1 * time.Second)
+}
--- /dev/null
+// +build !nacl,!js,!android
+// run
+
+// Copyright 2016 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 (
+ "bytes"
+ "fmt"
+ "html/template"
+ "io/ioutil"
+ "log"
+ "os"
+ "os/exec"
+ "path/filepath"
+)
+
+var tmpl = template.Must(template.New("main").Parse(`
+package main
+
+type T struct {
+ {{range .Names}}
+ {{.Name}} *string
+ {{end}}
+}
+
+{{range .Names}}
+func (t *T) Get{{.Name}}() string {
+ if t.{{.Name}} == nil {
+ return ""
+ }
+ return *t.{{.Name}}
+}
+{{end}}
+
+func main() {}
+`))
+
+func main() {
+ const n = 5000
+
+ type Name struct{ Name string }
+ var t struct{ Names []Name }
+ for i := 0; i < n; i++ {
+ t.Names = append(t.Names, Name{Name: fmt.Sprintf("H%06X", i)})
+ }
+
+ buf := new(bytes.Buffer)
+ if err := tmpl.Execute(buf, t); err != nil {
+ log.Fatal(err)
+ }
+
+ dir, err := ioutil.TempDir("", "issue16037-")
+ if err != nil {
+ log.Fatal(err)
+ }
+ defer os.RemoveAll(dir)
+ path := filepath.Join(dir, "ridiculous_number_of_fields.go")
+ if err := ioutil.WriteFile(path, buf.Bytes(), 0664); err != nil {
+ log.Fatal(err)
+ }
+
+ out, err := exec.Command("go", "build", "-o="+filepath.Join(dir, "out"), path).CombinedOutput()
+ if err != nil {
+ log.Fatalf("build failed: %v\n%s", err, out)
+ }
+}
--- /dev/null
+// run
+
+// Copyright 2016 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 (
+ "fmt"
+ "runtime"
+)
+
+var sink *[20]byte
+
+func f() (x [20]byte) {
+ // Initialize x.
+ for i := range x {
+ x[i] = byte(i)
+ }
+
+ // Force x to be allocated on the heap.
+ sink = &x
+ sink = nil
+
+ // Go to deferreturn after the panic below.
+ defer func() {
+ recover()
+ }()
+
+ // This call collects the heap-allocated version of x (oops!)
+ runtime.GC()
+
+ // Allocate that same object again and clobber it.
+ y := new([20]byte)
+ for i := 0; i < 20; i++ {
+ y[i] = 99
+ }
+ // Make sure y is heap allocated.
+ sink = y
+
+ panic(nil)
+
+ // After the recover we reach the deferreturn, which
+ // copies the heap version of x back to the stack.
+ // It gets the pointer to x from a stack slot that was
+ // not marked as live during the call to runtime.GC().
+}
+
+var sinkint int
+
+func g(p *int) (x [20]byte) {
+ // Initialize x.
+ for i := range x {
+ x[i] = byte(i)
+ }
+
+ // Force x to be allocated on the heap.
+ sink = &x
+ sink = nil
+
+ // Go to deferreturn after the panic below.
+ defer func() {
+ recover()
+ }()
+
+ // This call collects the heap-allocated version of x (oops!)
+ runtime.GC()
+
+ // Allocate that same object again and clobber it.
+ y := new([20]byte)
+ for i := 0; i < 20; i++ {
+ y[i] = 99
+ }
+ // Make sure y is heap allocated.
+ sink = y
+
+ // panic with a non-call (with no fallthrough)
+ for {
+ sinkint = *p
+ }
+
+ // After the recover we reach the deferreturn, which
+ // copies the heap version of x back to the stack.
+ // It gets the pointer to x from a stack slot that was
+ // not marked as live during the call to runtime.GC().
+}
+
+func main() {
+ x := f()
+ for i, v := range x {
+ if v != byte(i) {
+ fmt.Printf("%v\n", x)
+ panic("bad f")
+ }
+ }
+ x = g(nil)
+ for i, v := range x {
+ if v != byte(i) {
+ fmt.Printf("%v\n", x)
+ panic("bad g")
+ }
+ }
+}
--- /dev/null
+// run
+
+// Copyright 2016 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.
+
+// Test that an interface conversion error panics with an "interface
+// conversion" run-time error. It was (incorrectly) panicking with a
+// "nil pointer dereference."
+
+package main
+
+import (
+ "fmt"
+ "runtime"
+ "strings"
+)
+
+type I interface {
+ Get() int
+}
+
+func main() {
+ defer func() {
+ r := recover()
+ if r == nil {
+ panic("expected panic")
+ }
+ re, ok := r.(runtime.Error)
+ if !ok {
+ panic(fmt.Sprintf("got %T, expected runtime.Error", r))
+ }
+ if !strings.Contains(re.Error(), "interface conversion") {
+ panic(fmt.Sprintf("got %q, expected interface conversion error", re.Error()))
+ }
+ }()
+ e := (interface{})(0)
+ if _, ok := e.(I); ok {
+ panic("unexpected interface conversion success")
+ }
+ fmt.Println(e.(I))
+ panic("unexpected interface conversion success")
+}
--- /dev/null
+package a
+
+type X string
+
+func NewX() X {
+ return ""
+}
--- /dev/null
+package a
+
+type X string
+
+func NewX() X {
+ return ""
+}
--- /dev/null
+package b
+
+import "./a2"
+
+type T struct {
+ X a.X
+}
--- /dev/null
+package p
+
+import (
+ "./a1"
+ "./b"
+)
+
+var _ = b.T{
+ X: a.NewX(), // ERROR `cannot use "a1"\.NewX\(\)`
+}
--- /dev/null
+// compile
+
+// Copyright 2016 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.
+
+// The compiler used the name "glob" as the function holding a global
+// function literal, colliding with an actual function named "glob".
+
+package main
+
+func glob() {
+ func() {
+ }()
+}
+
+var c1 = func() {
+}
+
+var c2 = func() {
+}
+
+func main() {
+ glob()
+ c1()
+ c2()
+}
--- /dev/null
+// run
+
+// Copyright 2016 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.
+
+// Liveness calculations were wrong for a result parameter pushed onto
+// the heap in a function that used defer. Program would crash with
+// runtime: bad pointer in frame main.A at 0xc4201e6838: 0x1
+
+package main
+
+import "errors"
+
+var sink interface{}
+
+//go:noinline
+func f(err *error) {
+ if err != nil {
+ sink = err
+ }
+}
+
+//go:noinline
+func A(n, m int64) (res int64, err error) {
+ defer f(&err) // output parameter's address escapes to a defer.
+ if n < 0 {
+ err = errors.New("No negative")
+ return
+ }
+ if n <= 1 {
+ res = n
+ return
+ }
+ res = B(m) // This call to B drizzles a little junk on the stack.
+ res, err = A(n-1, m)
+ res++
+ return
+}
+
+// B does a little bit of recursion dribbling not-zero onto the stack.
+//go:noinline
+func B(n int64) (res int64) {
+ if n <= 1 { // Prefer to leave a 1 on the stack.
+ return n
+ }
+ return 1 + B(n-1)
+}
+
+func main() {
+ x, e := A(0, 0)
+ for j := 0; j < 4; j++ { // j controls amount of B's stack dribble
+ for i := 0; i < 1000; i++ { // try more and more recursion until stack growth occurs in newobject in prologue
+ x, e = A(int64(i), int64(j))
+ }
+ }
+ _, _ = x, e
+}
--- /dev/null
+// compile
+
+// Copyright 2016 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 "unsafe"
+
+var x = unsafe.Pointer(uintptr(0))
+
+func main() {
+ _ = map[unsafe.Pointer]int{unsafe.Pointer(uintptr(0)): 0}
+}
--- /dev/null
+// Copyright 2016 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
+
+import "unsafe"
+
+func ConstUnsafePointer() unsafe.Pointer {
+ return unsafe.Pointer(uintptr(0))
+}
--- /dev/null
+// Copyright 2016 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 "./a"
+
+func main() {
+ _ = a.ConstUnsafePointer()
+}
--- /dev/null
+// compiledir
+
+// Copyright 2016 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 16317: cmd/compile: internal compiler error:
+// unhandled OCONV INT -> TUNSAFEPTR
+
+package ignored
--- /dev/null
+// run
+
+// Copyright 2016 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.
+
+// Perform tracebackdefers with a deferred reflection method.
+
+package main
+
+import "reflect"
+
+type T struct{}
+
+func (T) M() {
+}
+
+func F(args []reflect.Value) (results []reflect.Value) {
+ return nil
+}
+
+func main() {
+ done := make(chan bool)
+ go func() {
+ // Test reflect.makeFuncStub.
+ t := reflect.TypeOf((func())(nil))
+ f := reflect.MakeFunc(t, F).Interface().(func())
+ defer f()
+ growstack(10000)
+ done <- true
+ }()
+ <-done
+ go func() {
+ // Test reflect.methodValueCall.
+ f := reflect.ValueOf(T{}).Method(0).Interface().(func())
+ defer f()
+ growstack(10000)
+ done <- true
+ }()
+ <-done
+}
+
+func growstack(x int) {
+ if x == 0 {
+ return
+ }
+ growstack(x - 1)
+}
--- /dev/null
+// compile
+
+// Copyright 2016 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 T interface {
+ M(interface {
+ T
+ })
+}
--- /dev/null
+// errorcheck
+
+// Copyright 2016 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 (
+ b = [...]byte("abc") // ERROR "outside of array literal"
+ s = len(b)
+)
--- /dev/null
+// errorcheck
+
+// Copyright 2016 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 a []int = []int{1: 1}
+var b []int = []int{-1: 1} // ERROR "must be non-negative integer constant|index expression is negative"
+
+var c []int = []int{2.0: 2}
+var d []int = []int{-2.0: 2} // ERROR "must be non-negative integer constant|index expression is negative"
+
+var e []int = []int{3 + 0i: 3}
+var f []int = []int{3i: 3} // ERROR "truncated to integer|index expression is not integer constant"
+
+var g []int = []int{"a": 4} // ERROR "must be non-negative integer constant|index expression is not integer constant"
--- /dev/null
+// run
+
+// Copyright 2016 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 16515: spilled Duff-adjusted address may be invalid
+
+package main
+
+import "runtime"
+
+type T [62]int // DUFFZERO with non-zero adjustment on AMD64
+
+var sink interface{}
+
+//go:noinline
+func zero(x *T) {
+ // Two DUFFZEROs on the same address with a function call in between.
+ // Duff-adjusted address will be spilled and loaded
+
+ *x = T{} // DUFFZERO
+ runtime.GC()
+ (*x)[0] = 1
+ g() // call a function with large frame, trigger a stack move
+ *x = T{} // DUFFZERO again
+}
+
+//go:noinline
+// a function with large frame
+func g() {
+ var x [1000]int
+ _ = x
+}
+
+func main() {
+ var s struct { a T; b [8192-62]int } // allocate 64K, hopefully it's in a new span and a few bytes before it is garbage
+ sink = &s // force heap allocation
+ s.a[0] = 2
+ zero(&s.a)
+ if s.a[0] != 0 {
+ println("s.a[0] =", s.a[0])
+ panic("zeroing failed")
+ }
+
+ var a T // on stack
+ a[0] = 2
+ zero(&a)
+ if a[0] != 0 {
+ println("a[0] =", a[0])
+ panic("zeroing failed")
+ }
+}
--- /dev/null
+// Copyright 2016 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 V struct{ i int }
--- /dev/null
+// Copyright 2016 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"
+
+var V struct{ i int }
+
+var U struct {
+ a.V
+ j int
+}
--- /dev/null
+// Copyright 2016 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"
+
+ _ "./a"
+ "./b"
+)
+
+var V struct{ i int }
+
+func main() {
+ if got := reflect.ValueOf(b.V).Type().Field(0).PkgPath; got != "b" {
+ panic(`PkgPath=` + got + ` for first field of b.V, want "b"`)
+ }
+ if got := reflect.ValueOf(V).Type().Field(0).PkgPath; got != "main" {
+ panic(`PkgPath=` + got + ` for first field of V, want "main"`)
+ }
+ if got := reflect.ValueOf(b.U).Type().Field(0).PkgPath; got != "b" {
+ panic(`PkgPath=` + got + ` for first field of b.U, want "b"`)
+ }
+}
--- /dev/null
+// compiledir
+
+// Copyright 2016 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.
+
+// Tests that unexported fields of unnamed types have different PkgPath values.
+
+package ignored
--- /dev/null
+// compile
+
+// Copyright 2016 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 16733: don't fold constant factors into a multiply
+// beyond the capacity of a MULQ instruction (32 bits).
+
+package p
+
+func f(n int64) int64 {
+ n *= 1000000
+ n *= 1000000
+ return n
+}
--- /dev/null
+// compile
+
+// Copyright 2016 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.
+
+// Make sure CSE of multi-output opcodes works correctly
+// with select0/1 operations.
+
+package main
+
+func div(d, r int64) int64 {
+ if m := d % r; m > 0 {
+ return d/r + 1
+ }
+ return d / r
+}
--- /dev/null
+// run
+
+// Copyright 2016 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.
+
+// Make sure we don't start marshaling (writing to the stack)
+// arguments until those arguments are evaluated and known
+// not to unconditinally panic. If they unconditionally panic,
+// we write some args but never do the call. That messes up
+// the logic which decides how big the argout section needs to be.
+
+package main
+
+type W interface {
+ Write([]byte)
+}
+
+type F func(W)
+
+func foo(f F) {
+ defer func() {
+ if r := recover(); r != nil {
+ usestack(1000)
+ }
+ }()
+ f(nil)
+}
+
+func main() {
+ foo(func(w W) {
+ var x []string
+ w.Write([]byte(x[5]))
+ })
+}
+
+func usestack(n int) {
+ if n == 0 {
+ return
+ }
+ usestack(n - 1)
+}
--- /dev/null
+// compile
+
+// Copyright 2016 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 16804: internal error for math.Sqrt as statement
+// rather than expression
+
+package main
+
+import "math"
+
+func sqrt() {
+ math.Sqrt(2.0)
+}
--- /dev/null
+// run
+
+// Copyright 2016 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 16948: make sure intrinsified atomic ops won't
+// confuse the scheduler.
+
+package main
+
+import "sync/atomic"
+
+func main() {
+ f()
+}
+
+var x int32
+
+type T [10]int
+var sink *T
+
+func f() (t T) {
+ atomic.AddInt32(&x, 1)
+ g(42, 42, 42, 42, 42, &t) // use int values that is invalid pointer to smash the stack slot of return value of runtime.newobject
+ return
+}
+
+//go:noinline
+func g(a, b, c, d, e int, p *T) {
+ var t [10000]int // a large stack frame to trigger stack growing
+ _ = t
+ sink = p // force p (in caller) heap allocated
+}
--- /dev/null
+// run
+
+// Copyright 2016 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 16985: intrinsified AMD64 atomic ops should clobber flags
+
+package main
+
+import "sync/atomic"
+
+var count uint32
+
+func main() {
+ buffer := []byte("T")
+ for i := 0; i < len(buffer); {
+ atomic.AddUint32(&count, 1)
+ _ = buffer[i]
+ i++
+ i++
+ }
+
+ for i := 0; i < len(buffer); {
+ atomic.CompareAndSwapUint32(&count, 0, 1)
+ _ = buffer[i]
+ i++
+ i++
+ }
+
+ for i := 0; i < len(buffer); {
+ atomic.SwapUint32(&count, 1)
+ _ = buffer[i]
+ i++
+ i++
+ }
+}
--- /dev/null
+// compile
+
+// Copyright 2016 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.
+
+// This tickles (a version of) the PPC64 back end to
+// emit a BVS instruction.
+
+package foo
+
+type Flag int
+
+const (
+ Identity Flag = iota - 2 // H is the identity matrix; no rotation is needed.
+ Rescaling // H specifies rescaling.
+)
+
+type DrotmParams struct {
+ Flag
+}
+
+func Drotmg(d1, d2, x1, y1 float64) (p DrotmParams, rd1, rd2, rx1 float64) {
+
+ const (
+ gam = 4.0
+ gamsq = 16.0
+ rgamsq = 5e-8
+ )
+
+ if d1 < 0 {
+ p.Flag = Rescaling
+ return
+ }
+
+ for rd1 <= rgamsq || rd1 >= gamsq {
+ if rd1 <= rgamsq {
+ rd1 *= gam * gam
+ rx1 /= gam
+ } else {
+ rd1 /= gam * gam
+ rx1 *= gam
+ }
+ }
+ return
+}
--- /dev/null
+// compile
+
+// Copyright 2016 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
+
+type I int
+
+var (
+ i int
+ x = I(i)
+
+ e interface{} = x
+)
--- /dev/null
+// compile
+
+// Copyright 2016 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 foo
+
+func f(x []interface{}) (err error) {
+ for _, d := range x {
+ _, ok := d.(*int)
+ if ok {
+ return
+ }
+ }
+ return
+}
--- /dev/null
+// compile
+
+// Copyright 2016 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"
+
+const _ = (unsafe.Sizeof)(0)
--- /dev/null
+// errorcheck
+
+// Copyright 2017 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
+
+func main() {
+ i := 0
+ for ; ; i++) { // ERROR "unexpected \), expecting { after for clause|expected .*{.*|expected .*;.*"
+ }
+} // GCCGO_ERROR "expected declaration"
--- /dev/null
+// run
+
+// Copyright 2016 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 17381: make sure leave function with non-empty frame
+// saves link register, so that traceback will work.
+
+package main
+
+import (
+ "runtime"
+ "unsafe"
+)
+
+func main() {
+ defer func() {
+ if recover() == nil {
+ panic("did not panic")
+ }
+ pcs := make([]uintptr, 20)
+ n := runtime.Callers(1, pcs)
+ for _, pc := range pcs[:n] {
+ if runtime.FuncForPC(pc).Name() == "main.main" {
+ return
+ }
+ }
+ panic("cannot find main.main in backtrace")
+ }()
+
+ prep()
+ f() // should panic
+}
+
+func funcPC(f interface{}) uintptr {
+ var ptr uintptr
+ return **(**uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&f)) + unsafe.Sizeof(ptr)))
+}
+
+//go:noinline
+func f() {
+ var t [1]int // non-empty frame
+ *(*int)(nil) = t[0]
+}
+
+var p = funcPC(runtime.GC) + 8
+
+//go:noinline
+func prep() {
+ // put some garbage on stack
+ var x = [20]uintptr{p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p, p}
+ _ = x
+}
--- /dev/null
+// compile
+
+// Copyright 2016 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 17551: inrange optimization failed to preserve type information.
+
+package main
+
+import "fmt"
+
+func main() {
+ _, x := X()
+ fmt.Printf("x = %v\n", x)
+}
+
+func X() (i int, ok bool) {
+ ii := int(1)
+ return ii, 0 <= ii && ii <= 0x7fffffff
+}
--- /dev/null
+// errorcheck
+
+// Copyright 2016 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 17588: internal compiler error in typecheckclosure()
+// because in case of Func.Nname.Type == nil, Decldepth
+// is not initialized in typecheckfunc(). This test
+// produces that case.
+
+package p
+
+type F func(b T) // ERROR "T is not a type|expected type"
+
+func T(fn F) {
+ func() {
+ fn(nil) // If Decldepth is not initialized properly, typecheckclosure() Fatals here.
+ }()
+}
--- /dev/null
+// compile
+
+// Copyright 2016 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 foo
+
+type T interface {
+ foo()
+}
+
+func f() (T, int)
+
+func g(v interface{}) (interface{}, int) {
+ var x int
+ v, x = f()
+ return v, x
+}
--- /dev/null
+// errorcheck
+
+// Copyright 2016 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 "time"
+
+func main() {
+ _ = struct {
+ about string
+ before map[string]uint
+ update map[string]int
+ updateTime time.Time
+ expect map[string]int
+ }{
+ about: "this one",
+ updates: map[string]int{"gopher": 10}, // ERROR "unknown field 'updates' in struct literal of type|unknown field .*updates.* in .*unnamed struct.*"
+ }
+}
--- /dev/null
+// run
+
+// Copyright 2016 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 "fmt"
+
+var results string
+
+type TwoInts struct {
+ x, y int
+}
+
+func f(x int) int { results = results + fmt.Sprintf("_%d", x); return x }
+
+func main() {
+ _ = [19]int{1: f(1), 0: f(0), 2: f(2), 6, 7}
+ _ = [2]int{1: f(4), 0: f(3)}
+ _ = TwoInts{y: f(6), x: f(5)}
+ _ = map[int]int{f(f(9) + 1): f(8), 0: f(7), f(22): -1}
+ if results != "_1_0_2_4_3_6_5_9_10_8_7_22" {
+ fmt.Printf("unexpected: %s\n", results)
+ panic("fail")
+ }
+}
--- /dev/null
+// errorcheck
+
+// Copyright 2016 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
+
+type Foo struct {
+ X int
+}
+
+func main() {
+ var s []int
+ var _ string = append(s, Foo{""}) // ERROR "cannot use .. \(type untyped string\) as type int in field value|incompatible type" "cannot use Foo{...} \(type Foo\) as type int in append" "cannot use append\(s\, Foo{...}\) \(type \[\]int\) as type string in assignment"
+}
--- /dev/null
+// compile
+
+// Copyright 2016 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 "runtime"
+
+func f(x interface{}) {
+ runtime.KeepAlive(x)
+}
--- /dev/null
+// run
+
+// Copyright 2016 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
+
+func f(m map[string]int) int {
+ return m["a"]
+}
+
+func g(m map[[8]string]int) int {
+ return m[[8]string{"a", "a", "a", "a", "a", "a", "a", "a"}]
+}
+
+func main() {
+ m := map[[8]string]int{}
+ g(m)
+}
--- /dev/null
+// 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 main
+
+func foo() {
+ _ = func() {}
+}
+
+func foo() { // ERROR "foo redeclared in this block|redefinition of .*foo.*"
+ _ = func() {}
+}
+
+func main() {}
--- /dev/null
+// compile
+
+// Copyright 2016 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 17918: slice out-of-bounds in ssa/cse
+
+package dead
+
+import (
+ "fmt"
+ "time"
+)
+
+var (
+ units = []struct {
+ divisor time.Duration
+ unit rune
+ }{
+ {1000000, 's'},
+ {60, 'm'},
+ {60, 'h'},
+ {24, 'd'},
+ {7, 'w'},
+ }
+)
+
+func foobar(d time.Duration) string {
+ d /= time.Microsecond
+ unit := 'u'
+
+ for _, f := range units {
+ if d%f.divisor != 0 {
+ break
+ }
+ d /= f.divisor
+ unit = f.unit
+ }
+ return fmt.Sprintf("%d%c", d, unit)
+}
--- /dev/null
+// compile
+
+// Copyright 2017 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 foo
+
+type T struct {
+ x int
+ _ int
+}
+
+func main() {
+ _ = T{0, 0}
+
+ x := T{1, 1}
+ _ = x
+}
--- /dev/null
+// errorcheck
+
+// Copyright 2016 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
+
+func _() {
+ var ch chan bool
+ select {
+ default:
+ case <-ch { // GCCGO_ERROR "expected colon"
+ } // GC_ERROR "expecting :"
+}
--- /dev/null
+// errorcheck
+
+// Copyright 2017 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.
+
+// Test that error message for composite literals with
+// missing type is at the right place.
+
+package p
+
+type T struct {
+ f map[string]string
+}
+
+var _ = T{
+ f: { // ERROR "missing type in composite literal|may only omit types within"
+ "a": "b",
+ },
+}
--- /dev/null
+// errorcheck
+
+// Copyright 2017 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.
+
+// Test that compiler directives are ignored if they
+// don't start at the beginning of the line.
+
+package p
+
+//line issue18393.go:20
+import 42 // error on line 20
+
+
+/* //line not at start of line: ignored */ //line issue18393.go:30
+var x // error on line 24, not 30
+
+
+// ERROR "import path must be a string"
+
+
+
+// ERROR "syntax error: unexpected newline, expecting type|expected type"
--- /dev/null
+// run
+
+// Copyright 2016 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.
+
+// This checks partially initialized structure literals
+// used to create value.method functions have their
+// non-initialized fields properly zeroed/nil'd
+
+package main
+
+type X struct {
+ A, B, C *int
+}
+
+//go:noinline
+func (t X) Print() {
+ if t.B != nil {
+ panic("t.B must be nil")
+ }
+}
+
+//go:noinline
+func caller(f func()) {
+ f()
+}
+
+//go:noinline
+func test() {
+ var i, j int
+ x := X{A: &i, C: &j}
+ caller(func() { X{A: &i, C: &j}.Print() })
+ caller(X{A: &i, C: &j}.Print)
+ caller(x.Print)
+}
+
+func main() {
+ test()
+}
--- /dev/null
+// Copyright 2017 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 other
+
+type Exported struct {
+ Member int
+}
+
+func (e *Exported) member() int { return 1 }
--- /dev/null
+// errorcheck -0 -m -l
+
+// Copyright 2017 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 "./other"
+
+func InMyCode(e *other.Exported) {
+ e.member() // ERROR "e\.member undefined .cannot refer to unexported field or method other\.\(\*Exported\)\.member.|unexported field or method"
+}
+
+func main() {}
--- /dev/null
+// errorcheckdir
+
+// Copyright 2015 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 ignored
--- /dev/null
+// run
+
+// Copyright 2017 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.
+
+// This test makes sure that itabs are unique.
+// More explicitly, we require that only one itab structure exists for the pair of
+// a given compile-time interface type and underlying concrete type.
+// Ensuring this invariant enables fixes for 18492 (improve type switch code).
+
+package main
+
+type I interface {
+ M()
+}
+type J interface {
+ M()
+}
+
+type T struct{}
+
+func (*T) M() {}
+
+func main() {
+ test1()
+ test2()
+}
+
+func test1() {
+ t := new(T)
+ var i1, i2 I
+ var j interface {
+ M()
+ }
+ i1 = t
+ j = t
+ i2 = j
+ if i1 != i2 {
+ panic("interfaces not equal")
+ }
+}
+
+func test2() {
+ t := new(T)
+ i1 := (I)(t)
+ i2 := (I)((interface {
+ M()
+ })((J)(t)))
+ if i1 != i2 {
+ panic("interfaces not equal")
+ }
+}
--- /dev/null
+// run
+
+// Copyright 2017 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 "runtime/debug"
+
+type Foo struct {
+ A [1 << 20]byte
+ B string
+}
+
+func run(c chan bool) {
+ f := new(Foo)
+ *f = Foo{B: "hello"}
+ c <- true
+}
+
+func main() {
+ debug.SetMaxStack(1 << 16)
+ c := make(chan bool)
+ go run(c)
+ <-c
+}
--- /dev/null
+// compile
+
+// Copyright 2017 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 (
+ a = b
+ b struct {
+ *a
+ }
+)
+
+type (
+ c struct {
+ *d
+ }
+ d = c
+)
+
+// The compiler cannot handle these cases. Disabled for now.
+// See issue #25838.
+/*
+type (
+ e = f
+ f = g
+ g = []h
+ h i
+ i = j
+ j = e
+)
+
+type (
+ a1 struct{ *b1 }
+ b1 = c1
+ c1 struct{ *b1 }
+)
+
+type (
+ a2 struct{ b2 }
+ b2 = c2
+ c2 struct{ *b2 }
+)
+*/
--- /dev/null
+// errorcheck
+
+// Copyright 2017 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 T struct{}
+type A = T
+type B = T
+
+func (T) m() {}
+func (T) m() {} // ERROR "redeclared|redefinition"
+func (A) m() {} // ERROR "redeclared|redefinition"
+func (A) m() {} // ERROR "redeclared|redefinition"
+func (B) m() {} // ERROR "redeclared|redefinition"
+func (B) m() {} // ERROR "redeclared|redefinition"
+
+func (*T) m() {} // ERROR "redeclared|redefinition"
+func (*A) m() {} // ERROR "redeclared|redefinition"
+func (*B) m() {} // ERROR "redeclared|redefinition"
--- /dev/null
+// run
+
+// Copyright 2017 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 (
+ "fmt"
+ "os"
+)
+
+var (
+ e interface{}
+ s = struct{ a *int }{}
+ b = e == s
+)
+
+func test(obj interface{}) {
+ if obj != struct{ a *string }{} {
+ }
+}
+
+var x int
+
+func f() [2]string {
+ x++
+ return [2]string{"abc", "def"}
+}
+
+func main() {
+ var e interface{} = [2]string{"abc", "def"}
+ _ = e == f()
+ if x != 1 {
+ fmt.Println("x=", x)
+ os.Exit(1)
+ }
+}
--- /dev/null
+// run
+
+// Copyright 2017 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 "os"
+
+func panicWhenNot(cond bool) {
+ if cond {
+ os.Exit(0)
+ } else {
+ panic("nilcheck elim failed")
+ }
+}
+
+func main() {
+ e := (*string)(nil)
+ panicWhenNot(e == e)
+ // Should never reach this line.
+ panicWhenNot(*e == *e)
+}
--- /dev/null
+// run
+
+// Copyright 2017 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
+
+const lim = 0x80000000
+
+//go:noinline
+func eq(x uint32) {
+ if x == lim {
+ return
+ }
+ panic("x == lim returned false")
+}
+
+//go:noinline
+func neq(x uint32) {
+ if x != lim {
+ panic("x != lim returned true")
+ }
+}
+
+//go:noinline
+func gt(x uint32) {
+ if x > lim {
+ return
+ }
+ panic("x > lim returned false")
+}
+
+//go:noinline
+func gte(x uint32) {
+ if x >= lim {
+ return
+ }
+ panic("x >= lim returned false")
+}
+
+//go:noinline
+func lt(x uint32) {
+ if x < lim {
+ panic("x < lim returned true")
+ }
+}
+
+//go:noinline
+func lte(x uint32) {
+ if x <= lim {
+ panic("x <= lim returned true")
+ }
+}
+
+func main() {
+ eq(lim)
+ neq(lim)
+ gt(lim+1)
+ gte(lim+1)
+ lt(lim+1)
+ lte(lim+1)
+}
--- /dev/null
+// run
+
+// Copyright 2017 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 f(x int) {
+}
+
+//go:noinline
+func val() int8 {
+ return -1
+}
+
+var (
+ array = [257]int{}
+ slice = array[1:]
+)
+
+func init() {
+ for i := range array {
+ array[i] = i - 1
+ }
+}
+
+func main() {
+ x := val()
+ y := int(uint8(x))
+ f(y) // try and force y to be calculated and spilled
+ if slice[y] != 255 {
+ panic("incorrect value")
+ }
+}
--- /dev/null
+// errorcheck
+
+// Copyright 2017 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.
+
+// Make sure error message for invalid conditions
+// or tags are consistent with earlier Go versions.
+
+package p
+
+func _() {
+ if a := 10 { // ERROR "cannot use a := 10 as value|expected .*;|declared but not used"
+ }
+
+ for b := 10 { // ERROR "cannot use b := 10 as value|parse error|declared but not used"
+ }
+
+ switch c := 10 { // ERROR "cannot use c := 10 as value|expected .*;|declared but not used"
+ }
+}
--- /dev/null
+// run
+
+// Copyright 2017 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 18994: SSA didn't handle DOT STRUCTLIT for zero-valued
+// STRUCTLIT.
+
+package main
+
+// large struct - not SSA-able
+type T struct {
+ a, b, c, d, e, f, g, h int
+}
+
+func main() {
+ x := T{}.a
+ if x != 0 {
+ panic("FAIL")
+ }
+}
--- /dev/null
+// errorcheck
+
+// Copyright 2017 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 19012: if we have any unknown type at a call site,
+// we must ensure that we return to the user a suppressed
+// error message saying instead of including <T> in
+// the message.
+
+package main
+
+func f(x int, y uint) {
+ if true {
+ return "a" > 10 // ERROR "^too many arguments to return$|return with value in function with no return|mismatched types"
+ }
+ return "gopher" == true, 10 // ERROR "^too many arguments to return$|return with value in function with no return|mismatched types"
+}
+
+func main() {
+ f(2, 3 < "x", 10) // ERROR "too many arguments|invalid operation|incompatible type"
+
+ f(10, 10, "a") // ERROR "too many arguments"
+}
--- /dev/null
+// Copyright 2017 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 reflect
+
+import "reflect"
+
+type Type reflect.Type
--- /dev/null
+// Copyright 2017 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"
+ fake "./a" // 2nd package with name "reflect"
+)
+
+type T struct {
+ _ fake.Type
+}
+
+func (T) f() {}
+func (T) G() (_ int) { return }
+func (T) H() (_, _ int) { return }
+
+func main() {
+ var x T
+ typ := reflect.TypeOf(x)
+ for i := 0; i < typ.NumMethod(); i++ {
+ _ = typ.Method(i) // must not crash
+ }
+}
--- /dev/null
+// rundir
+
+// Copyright 2017 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.
+
+// This test failed when the compiler didn't use the
+// correct code to identify the type reflect.Method.
+// The failing code relied on Type.String() which had
+// formatting that depended on whether a package (in
+// this case "reflect") was imported more than once.
+
+package ignored
--- /dev/null
+// run
+
+// Copyright 2017 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.
+
+// Check the text of the panic that comes from
+// a nil pointer passed to automatically generated method wrapper.
+
+package main
+
+import "fmt"
+
+type T int
+
+type I interface {
+ F()
+}
+
+func (t T) F() {}
+
+var (
+ t *T
+ i I = t
+)
+
+func main() {
+ defer func() {
+ got := recover().(error).Error()
+ want := "value method main.T.F called using nil *T pointer"
+ if got != want {
+ fmt.Printf("panicwrap error text:\n\t%q\nwant:\n\t%q\n", got, want)
+ }
+ }()
+ i.F()
+}
--- /dev/null
+// errorcheck
+
+// Copyright 2017 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 _ = ... . // ERROR "unexpected ...|expected operand|expected .*;"
--- /dev/null
+// run
+
+// Copyright 2017 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 19078: liveness & zero-initialization of results
+// when there is a defer.
+package main
+
+import "unsafe"
+
+func main() {
+ // Construct an invalid pointer. We do this by
+ // making a pointer which points to the unused space
+ // between the last 48-byte object in a span and the
+ // end of the span (there are 32 unused bytes there).
+ p := new([48]byte) // make a 48-byte object
+ sink = &p // escape it, so it allocates for real
+ u := uintptr(unsafe.Pointer(p)) // get its address
+ u = u >> 13 << 13 // round down to page size
+ u += 1<<13 - 1 // add almost a page
+
+ for i := 0; i < 1000000; i++ {
+ _ = identity(u) // installs u at return slot
+ _ = liveReturnSlot(nil) // incorrectly marks return slot as live
+ }
+}
+
+//go:noinline
+func liveReturnSlot(x *int) *int {
+ defer func() {}() // causes return slot to be marked live
+ sink = &x // causes x to be moved to the heap, triggering allocation
+ return x
+}
+
+//go:noinline
+func identity(x uintptr) uintptr {
+ return x
+}
+
+var sink interface{}
--- /dev/null
+// compile
+
+// Copyright 2017 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 19084: SSA doesn't handle CONVNOP STRUCTLIT
+
+package p
+
+type T struct {
+ a, b, c, d, e, f, g, h int // big, not SSA-able
+}
+
+func f() {
+ _ = T(T{})
+}
--- /dev/null
+// compile
+
+// Copyright 2017 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 19137: folding address into load/store causes
+// odd offset on ARM64.
+
+package p
+
+type T struct {
+ p *int
+ a [2]byte
+ b [6]byte // not 4-byte aligned
+}
+
+func f(b [6]byte) T {
+ var x [1000]int // a large stack frame
+ _ = x
+ return T{b: b}
+}
+
+// Arg symbol's base address may be not at an aligned offset to
+// SP. Folding arg's address into load/store may cause odd offset.
+func move(a, b [20]byte) [20]byte {
+ var x [1000]int // a large stack frame
+ _ = x
+ return b // b is not 8-byte aligned to SP
+}
+func zero() ([20]byte, [20]byte) {
+ var x [1000]int // a large stack frame
+ _ = x
+ return [20]byte{}, [20]byte{} // the second return value is not 8-byte aligned to SP
+}
+
+// Issue 21992: unaligned offset between 256 and 504 and handled
+// incorrectly.
+type T2 struct {
+ a [257]byte
+ // fields below are not 8-, 4-, 2-byte aligned
+ b [8]byte
+ c [4]byte
+ d [2]byte
+}
+
+func f2(x *T2) {
+ x.b = [8]byte{}
+ x.c = [4]byte{}
+ x.d = [2]byte{}
+}
--- /dev/null
+// run
+// +build !js
+
+// Copyright 2017 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 (
+ "fmt"
+ "runtime"
+ "sync/atomic"
+ "time"
+)
+
+var a uint64 = 0
+
+func main() {
+ runtime.GOMAXPROCS(2) // With just 1, infinite loop never yields
+
+ go func() {
+ for {
+ atomic.AddUint64(&a, uint64(1))
+ }
+ }()
+
+ time.Sleep(10 * time.Millisecond) // Short sleep is enough in passing case
+ i, val := 0, atomic.LoadUint64(&a)
+ for ; val == 0 && i < 100; val, i = atomic.LoadUint64(&a), i+1 {
+ time.Sleep(100 * time.Millisecond)
+ }
+ if val == 0 {
+ fmt.Printf("Failed to observe atomic increment after %d tries\n", i)
+ }
+
+}
--- /dev/null
+// run
+
+// Copyright 2017 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 (
+ "encoding/binary"
+)
+
+var (
+ ch1 = make(chan int)
+ ch2 = make(chan int)
+
+ bin = []byte("a\000\000\001")
+ want = binary.BigEndian.Uint32(bin)
+
+ c consumer = noopConsumer{}
+)
+
+type msg struct {
+ code uint32
+}
+
+type consumer interface {
+ consume(msg)
+}
+
+type noopConsumer struct{}
+
+func (noopConsumer) consume(msg) {}
+
+func init() {
+ close(ch1)
+}
+
+func main() {
+ var m msg
+ m.code = binary.BigEndian.Uint32(bin)
+
+ select {
+ case <-ch1:
+ c.consume(m)
+ if m.code != want {
+ // can not use m.code here, or it will work
+ panic("BigEndian read failed")
+ }
+ case <-ch2:
+ }
+}
--- /dev/null
+// compile
+
+// Copyright 2017 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 foo
+
+import (
+ "encoding/binary"
+)
+
+type DbBuilder struct {
+ arr []int
+}
+
+func (bld *DbBuilder) Finish() error {
+ defer bld.Finish()
+
+ var hash []byte
+ for _, ixw := range bld.arr {
+ for {
+ if ixw != 0 {
+ panic("ixw != 0")
+ }
+ ixw--
+ insertOne:
+ for {
+ for i := 0; i < 1; i++ {
+ if binary.LittleEndian.Uint16(hash[i:]) == 0 {
+ break insertOne
+ }
+ }
+ }
+ }
+ }
+
+ return nil
+}
--- /dev/null
+// run
+
+// Copyright 2017 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 (
+ "fmt"
+)
+
+type PI struct {
+ Enabled bool
+}
+
+type SI struct {
+ M map[string]*PI
+}
+
+//go:noinline
+func (s *SI) test(name string) (*int, error) {
+ n := new(int)
+ *n = 99
+ if err := addUpdate(n, s.M[name].Enabled, "enabled"); err != nil { // this was miscompiled
+ return nil, fmt.Errorf(" error adding update for enable flag %t : %s",
+ s.M[name].Enabled, err)
+ }
+ return n, nil
+}
+
+//go:noinline
+func addUpdate(n *int, in interface{}, s ...string) error {
+ if *n != 99 {
+ println("FAIL, *n should be 99, not", *n)
+ }
+ return nil
+}
+
+func main1() {
+ s := &SI{make(map[string]*PI)}
+ s.M["dog"] = &PI{}
+ s.test("dog")
+}
+
+//go:noinline
+func g(b *byte, i interface{}) error {
+ if *b != 17 {
+ println("FAIL, *b should be 17, not", *b)
+ }
+ return nil
+}
+
+//go:noinline
+func f(x *byte, m map[string]*bool) {
+ if err := g(x, *m["hello"]); err != nil { // this was miscompiled
+ return
+ }
+}
+
+func main2() {
+ m := make(map[string]*bool)
+ x := false
+ m["hello"] = &x
+ b := byte(17)
+ f(&b, m)
+}
+
+func main() {
+ main2()
+ main1()
+}
--- /dev/null
+// errorcheck
+
+// Copyright 2017 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
+
+func g() {}
+
+func f() {
+ g()[:] // ERROR "g.. used as value|attempt to slice object that is not"
+}
+
+func g2() ([]byte, []byte) { return nil, nil }
+
+func f2() {
+ g2()[:] // ERROR "multiple-value g2.. in single-value context|attempt to slice object that is not"
+}
--- /dev/null
+// run
+
+// Copyright 2017 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 "fmt"
+
+func set(m map[interface{}]interface{}, key interface{}) (err error) {
+ defer func() {
+ if r := recover(); r != nil {
+ err = fmt.Errorf("set failed: %v", r)
+ }
+ }()
+ m[key] = nil
+ return nil
+}
+
+func del(m map[interface{}]interface{}, key interface{}) (err error) {
+ defer func() {
+ if r := recover(); r != nil {
+ err = fmt.Errorf("del failed: %v", r)
+ }
+ }()
+ delete(m, key)
+ return nil
+}
+
+func addInt(m map[interface{}]int, key interface{}) (err error) {
+ defer func() {
+ if r := recover(); r != nil {
+ err = fmt.Errorf("addInt failed: %v", r)
+ }
+ }()
+ m[key] += 2018
+ return nil
+}
+
+func addStr(m map[interface{}]string, key interface{}) (err error) {
+ defer func() {
+ if r := recover(); r != nil {
+ err = fmt.Errorf("addStr failed: %v", r)
+ }
+ }()
+ m[key] += "hello, go"
+ return nil
+}
+
+func appendInt(m map[interface{}][]int, key interface{}) (err error) {
+ defer func() {
+ if r := recover(); r != nil {
+ err = fmt.Errorf("appendInt failed: %v", r)
+ }
+ }()
+ m[key] = append(m[key], 2018)
+ return nil
+}
+
+func appendStr(m map[interface{}][]string, key interface{}) (err error) {
+ defer func() {
+ if r := recover(); r != nil {
+ err = fmt.Errorf("addStr failed: %v", r)
+ }
+ }()
+ m[key] = append(m[key], "hello, go")
+ return nil
+}
+
+func main() {
+ m := make(map[interface{}]interface{})
+ set(m, []int{1, 2, 3})
+ set(m, "abc") // used to throw
+ del(m, []int{1, 2, 3})
+ del(m, "abc") // used to throw
+
+ mi := make(map[interface{}]int)
+ addInt(mi, []int{1, 2, 3})
+ addInt(mi, "abc") // used to throw
+
+ ms := make(map[interface{}]string)
+ addStr(ms, []int{1, 2, 3})
+ addStr(ms, "abc") // used to throw
+
+ mia := make(map[interface{}][]int)
+ appendInt(mia, []int{1, 2, 3})
+
+ msa := make(map[interface{}][]string)
+ appendStr(msa, "abc") // used to throw
+}
--- /dev/null
+// errorcheck
+
+// Copyright 2017 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.
+
+// Compiler rejected initialization of structs to composite literals
+// in a non-static setting (e.g. in a function)
+// when the struct contained a field named _.
+
+package p
+
+type T struct {
+ _ string
+}
+
+func ok() {
+ var x = T{"check"}
+ _ = x
+ _ = T{"et"}
+}
+
+var (
+ y = T{"stare"}
+ w = T{_: "look"} // ERROR "invalid field name _ in struct initializer|expected struct field name"
+ _ = T{"page"}
+ _ = T{_: "out"} // ERROR "invalid field name _ in struct initializer|expected struct field name"
+)
+
+func bad() {
+ var z = T{_: "verse"} // ERROR "invalid field name _ in struct initializer|expected struct field name"
+ _ = z
+ _ = T{_: "itinerary"} // ERROR "invalid field name _ in struct initializer|expected struct field name"
+}
--- /dev/null
+// Copyright 2017 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.
+
+TEXT ·f(SB),0,$0-8
+ MOVW x+0(FP), R1
+ MOVW x+4(FP), R2
+ DIVU R1, R2
+ DIV R1, R2
+ MODU R1, R2
+ MOD R1, R2
+ RET
--- /dev/null
+// +build arm
+
+// Copyright 2017 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.
+
+// Make sure we can compile assembly with DIV and MOD in it.
+// They get rewritten to runtime calls on GOARM=5.
+
+package main
+
+func f(x, y uint32)
+
+func main() {
+ f(5, 8)
+}
--- /dev/null
+// +build arm
+// builddir
+
+// Copyright 2017 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 ignored
--- /dev/null
+// compile
+
+// Copyright 2017 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 19515: compiler panics on spilling int128 constant.
+
+package x
+
+type VScrollPanel struct {
+ x, y int
+}
+
+type Color struct {
+ R, G, B, A float32
+}
+
+func maxF(a, b float32) float32 {
+ if a > b {
+ return 0
+ }
+ return 1
+}
+
+type TransformMatrix [6]float32
+
+type Paint struct {
+ xform TransformMatrix
+ feather float32
+ innerColor Color
+ outerColor Color
+}
+
+func BoxGradient(x, y, w, h, f float32, iColor, oColor Color) Paint {
+ return Paint{
+ xform: TransformMatrix{9, 0, 0, 0, x, y},
+ feather: maxF(1.0, f),
+ innerColor: iColor,
+ outerColor: oColor,
+ }
+}
+
+func (v *VScrollPanel) Draw() {
+ x := float32(v.x)
+ y := float32(v.y)
+
+ BoxGradient(x+x-2, y-1, 0, 0, 0, Color{}, Color{})
+ BoxGradient(x+y-2, y-1, 0, 0, 0, Color{}, Color{})
+}
+
--- /dev/null
+// Copyright 2016 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 Mode uint
+
+func (m Mode) String() string { return "mode string" }
+func (m *Mode) Addr() *Mode { return m }
+
+type Stringer interface {
+ String() string
+}
+
+var global Stringer
+var m Mode
+
+func init() {
+ // force compilation of the (*Mode).String() wrapper
+ global = &m
+}
+
+func String() string {
+ return global.String() + Mode(0).String()
+}
--- /dev/null
+// Copyright 2016 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 "./a"
+
+type Value interface {
+ a.Stringer
+ Addr() *a.Mode
+}
+
+var global a.Mode
+
+func f() int {
+ var v Value
+ v = &global
+ return int(v.String()[0])
+}
+
+func main() {
+ f()
+}
--- /dev/null
+// rundir
+
+// Copyright 2017 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.
+
+// Test that interface wrappers can be compiled successfully
+// in multiple translation units.
+package ignore
--- /dev/null
+// compile
+
+// Copyright 2017 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 NodeLink struct{}
+
+// A role our end of NodeLink is intended to play
+type LinkRole int64
+
+const (
+ LinkServer LinkRole = iota // link created as server
+ LinkClient // link created as client
+
+ // for testing:
+ linkNoRecvSend LinkRole = 1 << 16 // do not spawn serveRecv & serveSend
+ linkFlagsMask LinkRole = (1<<32 - 1) << 16
+)
+
+func NewNodeLink(role LinkRole) *NodeLink {
+ var nextConnId uint32
+ switch role &^ linkFlagsMask {
+ case LinkServer:
+ nextConnId = 0 // all initiated by us connId will be even
+ case LinkClient:
+ nextConnId = 1 // ----//---- odd
+ default:
+ panic("invalid conn role")
+ }
+
+ _ = nextConnId
+ return nil
+}
--- /dev/null
+// compile
+
+// Copyright 2017 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.
+
+// Check that we don't crash due to "lost track of variable in
+// liveness" errors against unused variables.
+
+package p
+
+import "strings"
+
+// Minimized test case from github.com/mvdan/sh/syntax.
+func F() {
+ var _ = []string{
+ strings.Repeat("\n\n\t\t \n", 10) +
+ "# " + strings.Repeat("foo bar ", 10) + "\n" +
+ strings.Repeat("longlit_", 10) + "\n",
+ }
+}
--- /dev/null
+// +build !nacl,!js
+// run
+
+// Copyright 2017 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.
+
+// ensure that panic(x) where x is a numeric type displays a readable number
+package main
+
+import (
+ "bytes"
+ "fmt"
+ "io/ioutil"
+ "log"
+ "os"
+ "os/exec"
+ "path/filepath"
+)
+
+const fn = `
+package main
+
+import "errors"
+type S struct {
+
+}
+func (s S) String() string {
+ return "s-stringer"
+}
+func main() {
+ _ = errors.New
+ panic(%s(%s))
+}
+`
+
+func main() {
+ tempDir, err := ioutil.TempDir("", "")
+ if err != nil {
+ log.Fatal(err)
+ }
+ defer os.RemoveAll(tempDir)
+ tmpFile := filepath.Join(tempDir, "tmp.go")
+
+ for _, tc := range []struct {
+ Type string
+ Input string
+ Expect string
+ }{{"", "nil", "panic: nil"},
+ {"errors.New", `"test"`, "panic: test"},
+ {"S", "S{}", "panic: s-stringer"},
+ {"byte", "8", "panic: 8"},
+ {"rune", "8", "panic: 8"},
+ {"int", "8", "panic: 8"},
+ {"int8", "8", "panic: 8"},
+ {"int16", "8", "panic: 8"},
+ {"int32", "8", "panic: 8"},
+ {"int64", "8", "panic: 8"},
+ {"uint", "8", "panic: 8"},
+ {"uint8", "8", "panic: 8"},
+ {"uint16", "8", "panic: 8"},
+ {"uint32", "8", "panic: 8"},
+ {"uint64", "8", "panic: 8"},
+ {"uintptr", "8", "panic: 8"},
+ {"bool", "true", "panic: true"},
+ {"complex64", "8 + 16i", "panic: (+8.000000e+000+1.600000e+001i)"},
+ {"complex128", "8+16i", "panic: (+8.000000e+000+1.600000e+001i)"},
+ {"string", `"test"`, "panic: test"}} {
+
+ b := bytes.Buffer{}
+ fmt.Fprintf(&b, fn, tc.Type, tc.Input)
+
+ err = ioutil.WriteFile(tmpFile, b.Bytes(), 0644)
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ cmd := exec.Command("go", "run", tmpFile)
+ var buf bytes.Buffer
+ cmd.Stdout = &buf
+ cmd.Stderr = &buf
+ cmd.Env = os.Environ()
+ cmd.Run() // ignore err as we expect a panic
+
+ out := buf.Bytes()
+ panicIdx := bytes.Index(out, []byte("panic: "))
+ if panicIdx == -1 {
+ log.Fatalf("expected a panic in output for %s, got: %s", tc.Type, out)
+ }
+ eolIdx := bytes.IndexByte(out[panicIdx:], '\n') + panicIdx
+ if panicIdx == -1 {
+ log.Fatalf("expected a newline in output for %s after the panic, got: %s", tc.Type, out)
+ }
+ out = out[0:eolIdx]
+ if string(out) != tc.Expect {
+ log.Fatalf("expected '%s' for panic(%s(%s)), got %s", tc.Expect, tc.Type, tc.Input, out)
+ }
+ }
+}
--- /dev/null
+// errorcheck
+
+// Copyright 2017 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.
+
+// Make sure we don't crash when reporting this error.
+
+package p
+
+func f() {
+ if err := http.ListenAndServe( // GCCGO_ERROR "undefined name"
+} // ERROR "unexpected }, expecting expression|expected operand|missing .*\)|expected .*;|expected .*{"
--- /dev/null
+// compile
+
+// Copyright 2017 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.
+
+// Used to crash when compiling assignments involving [0]T,
+// where T is not SSA-able.
+
+package a
+
+func f() {
+ var i int
+ arr := [0][2]int{}
+ arr[i][0] = 0
+}
--- /dev/null
+// compile
+
+// Copyright 2017 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.
+
+// Used to crash when compiling functions containing
+// forward refs in dead code.
+
+package p
+
+var f func(int)
+
+func g() {
+l1:
+ i := 0
+ goto l1
+l2:
+ f(i)
+ goto l2
+}
--- /dev/null
+// compile
+
+// Copyright 2017 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.
+
+// Used to crash when a type switch was present in dead code
+// in an inlineable function.
+
+package p
+
+func Then() {
+ var i interface{}
+ if false {
+ switch i.(type) {
+ }
+ }
+}
+
+func Else() {
+ var i interface{}
+ if true {
+ _ = i
+ } else {
+ switch i.(type) {
+ }
+ }
+}
+
+func Switch() {
+ var i interface{}
+ switch 5 {
+ case 3:
+ switch i.(type) {
+ }
+ case 5:
+ }
+}
--- /dev/null
+// compile
+
+// Copyright 2017 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.
+
+// Used to crash when compiling assignments involving [0]T,
+// where T is not SSA-able.
+
+package p
+
+type s struct {
+ a, b, c, d, e int
+}
+
+func f() {
+ var i int
+ arr := [0]s{}
+ arr[i].a++
+}
--- /dev/null
+// errorcheck
+
+// Copyright 2017 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
+
+func f() bool {
+ if false {
+ } else {
+ return true
+ }
+} // ERROR "missing return at end of function"
--- /dev/null
+// compile
+
+// Copyright 2017 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
+
+func f1() {
+ f2()
+}
+
+func f2() {
+ if false {
+ _ = func() {}
+ }
+}
--- /dev/null
+// run
+
+// Copyright 2017 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 19710: mishandled defer delete(...)
+
+package main
+
+func main() {
+ if n := len(f()); n != 0 {
+ println("got", n, "want 0")
+ panic("bad defer delete")
+ }
+}
+
+func f() map[int]bool {
+ m := map[int]bool{}
+ for i := 0; i < 3; i++ {
+ m[i] = true
+ defer delete(m, i)
+ }
+ return m
+}
--- /dev/null
+// errorcheck -0 -m -l
+
+// Copyright 2017 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 foo
+
+// Escape analysis needs to treat the uintptr-typed reflect.*Header fields as pointers.
+
+import (
+ "reflect"
+ "unsafe"
+)
+
+type immutableBytes []byte
+
+// Bug was failure to leak param b.
+func toString(b immutableBytes) string { // ERROR "leaking param: b$"
+ var s string
+ if len(b) == 0 {
+ return s
+ }
+
+ strHeader := (*reflect.StringHeader)(unsafe.Pointer(&s))
+ strHeader.Data = (*reflect.SliceHeader)(unsafe.Pointer(&b)).Data
+
+ l := len(b)
+ strHeader.Len = l
+ return s
+}
--- /dev/null
+// Copyright 2017 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 T struct{ _ int }
+func (t T) M() {}
+
+type I interface { M() }
+
+func F() {
+ var t I = &T{}
+ t.M() // call to the wrapper (*T).M
+}
--- /dev/null
+// Copyright 2017 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 "./a"
+
+func main() {
+ var x a.I = &a.T{}
+ x.M() // call to the wrapper (*T).M
+ a.F() // make sure a.F is not dead, which also calls (*T).M inside package a
+}
--- /dev/null
+// rundir
+
+// Copyright 2017 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 19764: test that the linker's trampoline insertion
+// pass is happy with direct calls to interface wrappers that
+// may be defined in multiple packages.
+package ignore
--- /dev/null
+// compile
+
+// Copyright 2017 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
+
+func Spin() {
+l1:
+ for true {
+ goto l1
+ l2:
+ if true {
+ goto l2
+ }
+ }
+}
--- /dev/null
+// run
+
+// Copyright 2017 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 (
+ "os"
+ "runtime"
+)
+
+func foo(x int) int {
+ return x + 1
+}
+
+func test() {
+ defer func() {
+ if r := recover(); r != nil {
+ pcs := make([]uintptr, 10)
+ n := runtime.Callers(0, pcs)
+ pcs = pcs[:n]
+ frames := runtime.CallersFrames(pcs)
+ for {
+ f, more := frames.Next()
+ if f.Function == "main.foo" {
+ println("did not expect to see call to foo in stack trace")
+ os.Exit(1)
+ }
+ if !more {
+ break
+ }
+ }
+ }
+ }()
+ var v []int
+ foo(v[0])
+}
+
+func bar(x ...int) int {
+ return x[0] + 1
+}
+
+func testVariadic() {
+ defer func() {
+ if r := recover(); r != nil {
+ pcs := make([]uintptr, 10)
+ n := runtime.Callers(0, pcs)
+ pcs = pcs[:n]
+ frames := runtime.CallersFrames(pcs)
+ for {
+ f, more := frames.Next()
+ if f.Function == "main.bar" {
+ println("did not expect to see call to bar in stack trace")
+ os.Exit(1)
+ }
+ if !more {
+ break
+ }
+ }
+ }
+ }()
+ var v []int
+ bar(v[0])
+}
+
+func main() {
+ test()
+ testVariadic()
+}
--- /dev/null
+// errorcheck
+
+// Copyright 2017 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 T struct {
+ f [1]int
+}
+
+func a() {
+ _ = T // ERROR "type T is not an expression|invalid use of type"
+}
+
+func b() {
+ var v [len(T{}.f)]int // ok
+ _ = v
+}
--- /dev/null
+// run
+
+// Copyright 2017 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 (
+ "fmt"
+ "strings"
+)
+
+type ET struct{}
+
+func (*ET) Error() string { return "err" }
+
+func main() {
+ check("false", fmt.Sprintf("(*ET)(nil) == error(nil): %v", (*ET)(nil) == error(nil)))
+ check("true", fmt.Sprintf("(*ET)(nil) != error(nil): %v", (*ET)(nil) != error(nil)))
+
+ nilET := (*ET)(nil)
+ nilError := error(nil)
+
+ check("false", fmt.Sprintf("nilET == nilError: %v", nilET == nilError))
+ check("true", fmt.Sprintf("nilET != nilError: %v", nilET != nilError))
+}
+
+func check(want, gotfull string) {
+ got := gotfull[strings.Index(gotfull, ": ")+len(": "):]
+ if got != want {
+ panic("want " + want + " got " + got + " from " + gotfull)
+ }
+}
--- /dev/null
+// errorcheck
+
+// Copyright 2017 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 19977: multiple error messages when type switching on an undefined
+
+package foo
+
+func Foo() {
+ switch x := a.(type) { // ERROR "undefined: a|reference to undefined name .*a"
+ default:
+ _ = x
+ }
+}