Roll gofrontend to 15a24202fa42.

Takes us to Go 1.4.2 plus a number of bug fixes.

Differential Revision: http://reviews.llvm.org/D8830

llvm-svn: 234136
This commit is contained in:
Peter Collingbourne 2015-04-05 23:32:10 +00:00
parent cac325993a
commit d35a6aff92
56 changed files with 414 additions and 2157 deletions

View File

@ -80,6 +80,7 @@ add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/bin/llgo-go${CMAKE_EXECUTABLE_SUFF
COMMAND ${CMAKE_BINARY_DIR}/bin/llgo -static-libgo
-o ${CMAKE_BINARY_DIR}/bin/llgo-go${CMAKE_EXECUTABLE_SUFFIX}
${LLGO_GO_SOURCES}
${CMAKE_CURRENT_BINARY_DIR}/libgo/zstdpkglist.go
DEPENDS llgo libgo ${LLGO_GO_SOURCES}
COMMENT "Building Go executable llgo-go"
VERBATIM)

View File

@ -14,7 +14,7 @@
package irgen
const (
goVersion = "go1.4"
goVersion = "go1.4.2"
)
// GoVersion returns the version of Go that we are targeting.

View File

@ -1,4 +1,4 @@
14854533dcc7
883bc6ed0ea815293fe6309d66f967ea60630e87
The first line of this file holds the Mercurial revision number of the
The first line of this file holds the git revision number of the
last merge done from the master library sources.

View File

@ -971,13 +971,27 @@ s-version: Makefile
rm -f version.go.tmp
echo "package runtime" > version.go.tmp
echo 'const defaultGoroot = "$(prefix)"' >> version.go.tmp
echo 'const theVersion = "'`$(GOC) --version | sed 1q`'"' >> version.go.tmp
echo 'const theVersion = "'`cat $(srcdir)/VERSION | sed 1q`' '`$(GOC) --version | sed 1q`'"' >> version.go.tmp
echo 'const theGoarch = "'$(GOARCH)'"' >> version.go.tmp
echo 'const theGoos = "'$(GOOS)'"' >> version.go.tmp
echo 'const theGccgoToolDir = "$(libexecsubdir)"' >> version.go.tmp
$(SHELL) $(srcdir)/mvifdiff.sh version.go.tmp version.go
$(STAMP) $@
noinst_DATA = zstdpkglist.go
# Generate the list of go std packages that were included in libgo
zstdpkglist.go: s-zstdpkglist; @true
s-zstdpkglist: Makefile
rm -f zstdpkglist.go.tmp
echo 'package main' > zstdpkglist.go.tmp
echo "" >> zstdpkglist.go.tmp
echo 'var stdpkg = map[string]bool{' >> zstdpkglist.go.tmp
echo $(libgo_go_objs) 'unsafe.lo' 'runtime/cgo.lo' | sed 's/\.lo /\": true,\n/g' | sed 's/\.lo/\": true,/' | sed 's/-go//' | grep -v _c | sed 's/^/\t\"/' | sort | uniq >> zstdpkglist.go.tmp
echo '}' >> zstdpkglist.go.tmp
$(SHELL) $(srcdir)/mvifdiff.sh zstdpkglist.go.tmp zstdpkglist.go
$(STAMP) $@
go_sort_files = \
go/sort/search.go \
go/sort/sort.go

View File

@ -269,23 +269,24 @@ RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
install-pdf-recursive install-ps-recursive install-recursive \
installcheck-recursive installdirs-recursive pdf-recursive \
ps-recursive uninstall-recursive
DATA = $(toolexeclibgo_DATA) $(toolexeclibgoarchive_DATA) \
$(toolexeclibgocompress_DATA) $(toolexeclibgocontainer_DATA) \
$(toolexeclibgocrypto_DATA) $(toolexeclibgocryptox509_DATA) \
$(toolexeclibgodatabase_DATA) $(toolexeclibgodatabasesql_DATA) \
$(toolexeclibgodebug_DATA) $(toolexeclibgoencoding_DATA) \
$(toolexeclibgoexp_DATA) $(toolexeclibgogo_DATA) \
$(toolexeclibgohash_DATA) $(toolexeclibgohtml_DATA) \
$(toolexeclibgoimage_DATA) $(toolexeclibgoimagecolor_DATA) \
$(toolexeclibgoindex_DATA) $(toolexeclibgoio_DATA) \
$(toolexeclibgolog_DATA) $(toolexeclibgomath_DATA) \
$(toolexeclibgomime_DATA) $(toolexeclibgonet_DATA) \
$(toolexeclibgonethttp_DATA) $(toolexeclibgonetrpc_DATA) \
$(toolexeclibgoold_DATA) $(toolexeclibgoos_DATA) \
$(toolexeclibgopath_DATA) $(toolexeclibgoregexp_DATA) \
$(toolexeclibgoruntime_DATA) $(toolexeclibgosync_DATA) \
$(toolexeclibgotesting_DATA) $(toolexeclibgotext_DATA) \
$(toolexeclibgotexttemplate_DATA) $(toolexeclibgounicode_DATA)
DATA = $(noinst_DATA) $(toolexeclibgo_DATA) \
$(toolexeclibgoarchive_DATA) $(toolexeclibgocompress_DATA) \
$(toolexeclibgocontainer_DATA) $(toolexeclibgocrypto_DATA) \
$(toolexeclibgocryptox509_DATA) $(toolexeclibgodatabase_DATA) \
$(toolexeclibgodatabasesql_DATA) $(toolexeclibgodebug_DATA) \
$(toolexeclibgoencoding_DATA) $(toolexeclibgoexp_DATA) \
$(toolexeclibgogo_DATA) $(toolexeclibgohash_DATA) \
$(toolexeclibgohtml_DATA) $(toolexeclibgoimage_DATA) \
$(toolexeclibgoimagecolor_DATA) $(toolexeclibgoindex_DATA) \
$(toolexeclibgoio_DATA) $(toolexeclibgolog_DATA) \
$(toolexeclibgomath_DATA) $(toolexeclibgomime_DATA) \
$(toolexeclibgonet_DATA) $(toolexeclibgonethttp_DATA) \
$(toolexeclibgonetrpc_DATA) $(toolexeclibgoold_DATA) \
$(toolexeclibgoos_DATA) $(toolexeclibgopath_DATA) \
$(toolexeclibgoregexp_DATA) $(toolexeclibgoruntime_DATA) \
$(toolexeclibgosync_DATA) $(toolexeclibgotesting_DATA) \
$(toolexeclibgotext_DATA) $(toolexeclibgotexttemplate_DATA) \
$(toolexeclibgounicode_DATA)
RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \
distclean-recursive maintainer-clean-recursive
AM_RECURSIVE_TARGETS = $(RECURSIVE_TARGETS:-recursive=) \
@ -1154,6 +1155,7 @@ go_runtime_files = \
go/runtime/softfloat64.go \
version.go
noinst_DATA = zstdpkglist.go
go_sort_files = \
go/sort/search.go \
go/sort/sort.go
@ -4385,13 +4387,25 @@ s-version: Makefile
rm -f version.go.tmp
echo "package runtime" > version.go.tmp
echo 'const defaultGoroot = "$(prefix)"' >> version.go.tmp
echo 'const theVersion = "'`$(GOC) --version | sed 1q`'"' >> version.go.tmp
echo 'const theVersion = "'`cat $(srcdir)/VERSION | sed 1q`' '`$(GOC) --version | sed 1q`'"' >> version.go.tmp
echo 'const theGoarch = "'$(GOARCH)'"' >> version.go.tmp
echo 'const theGoos = "'$(GOOS)'"' >> version.go.tmp
echo 'const theGccgoToolDir = "$(libexecsubdir)"' >> version.go.tmp
$(SHELL) $(srcdir)/mvifdiff.sh version.go.tmp version.go
$(STAMP) $@
# Generate the list of go std packages that were included in libgo
zstdpkglist.go: s-zstdpkglist; @true
s-zstdpkglist: Makefile
rm -f zstdpkglist.go.tmp
echo 'package main' > zstdpkglist.go.tmp
echo "" >> zstdpkglist.go.tmp
echo 'var stdpkg = map[string]bool{' >> zstdpkglist.go.tmp
echo $(libgo_go_objs) 'unsafe.lo' 'runtime/cgo.lo' | sed 's/\.lo /\": true,\n/g' | sed 's/\.lo/\": true,/' | sed 's/-go//' | grep -v _c | sed 's/^/\t\"/' | sort | uniq >> zstdpkglist.go.tmp
echo '}' >> zstdpkglist.go.tmp
$(SHELL) $(srcdir)/mvifdiff.sh zstdpkglist.go.tmp zstdpkglist.go
$(STAMP) $@
libcalls.go: s-libcalls; @true
s-libcalls: libcalls-list go/syscall/mksyscall.awk $(go_base_syscall_files)
rm -f libcalls.go.tmp

View File

@ -3,25 +3,24 @@ See ../README.
This is the runtime support library for the Go programming language.
This library is intended for use with the Go frontend.
The library has only been tested on GNU/Linux using glibc. It should
not be difficult to port to other operating systems.
This library should not be stripped when it is installed. Go code
relies on being able to look up file/line information, which comes
from the debugging info using the libbacktrace library.
The library has only been tested on x86/x86_64 systems. It should not
be difficult to port to other architectures.
The library has only been tested on GNU/Linux using glibc, and on
Solaris. It should not be difficult to port to other operating
systems.
Directories:
go
A copy of the Go library from http://golang.org/, with a few
changes for gccgo. Notably, the reflection interface is different.
A copy of the Go library from http://golang.org/, with several
changes for gccgo.
runtime
Runtime functions, written in C, which are called directly by the
compiler or by the library.
syscalls
System call support.
Contributing
============

View File

@ -0,0 +1 @@
go1.4.2

View File

@ -130,21 +130,43 @@ func usage() {
}
var ptrSizeMap = map[string]int64{
"386": 4,
"amd64": 8,
"arm": 4,
"ppc64": 8,
"386": 4,
"alpha": 8,
"amd64": 8,
"arm": 4,
"arm64": 8,
"m68k": 4,
"mipso32": 4,
"mipsn32": 4,
"mipso64": 8,
"mipsn64": 8,
"ppc": 4,
"ppc64": 8,
"ppc64le": 8,
"s390x": 8,
"s390": 4,
"s390x": 8,
"sparc": 4,
"sparc64": 8,
}
var intSizeMap = map[string]int64{
"386": 4,
"amd64": 8,
"arm": 4,
"ppc64": 8,
"386": 4,
"alpha": 8,
"amd64": 8,
"arm": 4,
"arm64": 8,
"m68k": 4,
"mipso32": 4,
"mipsn32": 4,
"mipso64": 8,
"mipsn64": 8,
"ppc": 4,
"ppc64": 8,
"ppc64le": 8,
"s390x": 8,
"s390": 4,
"s390x": 8,
"sparc": 4,
"sparc64": 8,
}
var cPrefix string

View File

@ -132,7 +132,8 @@ var buildLdflags []string // -ldflags flag
var buildGccgoflags []string // -gccgoflags flag
var buildRace bool // -race flag
var reqPkgSrc bool // req src for Imports
// Require the source for go std packages
var reqStdPkgSrc bool
var buildContext = build.Default
var buildToolchain toolchain = noToolchain{}
@ -187,9 +188,9 @@ func addBuildFlags(cmd *Command) {
cmd.Flag.BoolVar(&buildRace, "race", false, "")
switch build.Default.Compiler {
case "gc":
reqPkgSrc = true
reqStdPkgSrc = true
case "gccgo":
reqPkgSrc = false
reqStdPkgSrc = false
}
}
@ -579,7 +580,7 @@ func (b *builder) action(mode buildMode, depMode buildMode, p *Package) *action
// are writing is not the cgo we need to use.
if goos == runtime.GOOS && goarch == runtime.GOARCH && !buildRace {
if reqPkgSrc {
if reqStdPkgSrc {
if len(p.CgoFiles) > 0 || p.Standard && p.ImportPath == "runtime/cgo" {
var stk importStack
p1 := loadPackage("cmd/cgo", &stk)
@ -1920,6 +1921,7 @@ func (tools gccgoToolchain) ld(b *builder, p *Package, out string, allactions []
// and all LDFLAGS from cgo dependencies.
apackagesSeen := make(map[*Package]bool)
afiles := []string{}
xfiles := []string{}
ldflags := b.gccArchArgs()
cgoldflags := []string{}
usesCgo := false
@ -1935,7 +1937,12 @@ func (tools gccgoToolchain) ld(b *builder, p *Package, out string, allactions []
if !a.p.Standard {
if a.p != nil && !apackagesSeen[a.p] {
apackagesSeen[a.p] = true
if a.p.fake {
if a.p.fake && a.p.external {
// external _tests, if present must come before
// internal _tests. Store these on a seperate list
// and place them at the head after this loop.
xfiles = append(xfiles, a.target)
} else if a.p.fake {
// move _test files to the top of the link order
afiles = append([]string{a.target}, afiles...)
} else {
@ -1944,6 +1951,7 @@ func (tools gccgoToolchain) ld(b *builder, p *Package, out string, allactions []
}
}
}
afiles = append(xfiles, afiles...)
for _, a := range allactions {
if a.p != nil {

View File

@ -308,6 +308,7 @@ The generator is run in the package's source directory.
Go generate accepts one specific flag:
-run=""
TODO: This flag is unimplemented.
if non-empty, specifies a regular expression to
select directives whose command matches the expression.

View File

@ -106,6 +106,7 @@ The generator is run in the package's source directory.
Go generate accepts one specific flag:
-run=""
TODO: This flag is unimplemented.
if non-empty, specifies a regular expression to
select directives whose command matches the expression.
@ -255,6 +256,10 @@ func (g *Generator) split(line string) []string {
// Parse line, obeying quoted strings.
var words []string
line = line[len("//go:generate ") : len(line)-1] // Drop preamble and final newline.
// There may still be a carriage return.
if len(line) > 0 && line[len(line)-1] == '\r' {
line = line[:len(line)-1]
}
// One (possibly quoted) word per iteration.
Words:
for {

View File

@ -40,9 +40,15 @@ func TestGenerateCommandParse(t *testing.T) {
}
g.setShorthand([]string{"-command", "yacc", "go", "tool", "yacc"})
for _, test := range splitTests {
// First with newlines.
got := g.split("//go:generate " + test.in + "\n")
if !reflect.DeepEqual(got, test.out) {
t.Errorf("split(%q): got %q expected %q", test.in, got, test.out)
}
// Then with CRLFs, thank you Windows.
got = g.split("//go:generate " + test.in + "\r\n")
if !reflect.DeepEqual(got, test.out) {
t.Errorf("split(%q): got %q expected %q", test.in, got, test.out)
}
}
}

View File

@ -290,7 +290,7 @@ func downloadPackage(p *Package) error {
}
}
if remote != repo {
return fmt.Errorf("%s is from %s, should be from %s", dir, remote, repo)
return fmt.Errorf("%s is a custom import path for %s, but %s is checked out from %s", rr.root, repo, dir, remote)
}
}
}

View File

@ -83,6 +83,7 @@ type Package struct {
allgofiles []string // gofiles + IgnoredGoFiles, absolute paths
target string // installed file for this package (may be executable)
fake bool // synthesized package
external bool // synthesized external test package
forceBuild bool // this package must be rebuilt
forceLibrary bool // this package is a library (even if named "main")
cmdline bool // defined by files listed on command line
@ -112,7 +113,11 @@ func (p *Package) copyBuild(pp *build.Package) {
p.ConflictDir = pp.ConflictDir
// TODO? Target
p.Goroot = pp.Goroot
p.Standard = p.Goroot && p.ImportPath != "" && !strings.Contains(p.ImportPath, ".")
if buildContext.Compiler == "gccgo" {
p.Standard = stdpkg[p.ImportPath]
} else {
p.Standard = p.Goroot && p.ImportPath != "" && !strings.Contains(p.ImportPath, ".")
}
p.GoFiles = pp.GoFiles
p.CgoFiles = pp.CgoFiles
p.IgnoredGoFiles = pp.IgnoredGoFiles
@ -582,7 +587,7 @@ func (p *Package) load(stk *importStack, bp *build.Package, err error) *Package
continue
}
p1 := loadImport(path, p.Dir, stk, p.build.ImportPos[path])
if !reqPkgSrc && p1.Root == "" {
if !reqStdPkgSrc && p1.Standard {
continue
}
if p1.local {

View File

@ -384,17 +384,18 @@ func runTest(cmd *Command, args []string) {
delete(deps, "unsafe")
all := []string{}
if reqPkgSrc {
for path := range deps {
if !build.IsLocalImport(path) {
all = append(all, path)
}
for path := range deps {
if !build.IsLocalImport(path) {
all = append(all, path)
}
}
sort.Strings(all)
a := &action{}
for _, p := range packagesForBuild(all) {
if !reqStdPkgSrc && p.Standard {
continue
}
a.deps = append(a.deps, b.action(modeInstall, modeInstall, p))
}
b.do(a)
@ -563,7 +564,7 @@ func (b *builder) test(p *Package) (buildAction, runAction, printAction *action,
stk.push(p.ImportPath + " (test)")
for _, path := range p.TestImports {
p1 := loadImport(path, p.Dir, &stk, p.build.TestImportPos[path])
if !reqPkgSrc && p1.Root == "" {
if !reqStdPkgSrc && p1.Standard {
continue
}
if p1.Error != nil {
@ -591,7 +592,7 @@ func (b *builder) test(p *Package) (buildAction, runAction, printAction *action,
continue
}
p1 := loadImport(path, p.Dir, &stk, p.build.XTestImportPos[path])
if !reqPkgSrc && p1.Root == "" {
if !reqStdPkgSrc && p1.Standard {
continue
}
if p1.Error != nil {
@ -691,10 +692,11 @@ func (b *builder) test(p *Package) (buildAction, runAction, printAction *action,
build: &build.Package{
ImportPos: p.build.XTestImportPos,
},
imports: ximports,
pkgdir: testDir,
fake: true,
Stale: true,
imports: ximports,
pkgdir: testDir,
fake: true,
external: true,
Stale: true,
}
if pxtestNeedsPtest {
pxtest.imports = append(pxtest.imports, ptest)
@ -722,7 +724,7 @@ func (b *builder) test(p *Package) (buildAction, runAction, printAction *action,
pmain.imports = append(pmain.imports, ptest)
} else {
p1 := loadImport(dep, "", &stk, nil)
if !reqPkgSrc && p1.Root == "" {
if !reqStdPkgSrc && p1.Standard {
continue
}
if p1.Error != nil {

View File

@ -532,6 +532,9 @@ func (f *File) applyRelocations(dst []byte, rels []byte) error {
if f.Class == ELFCLASS64 && f.Machine == EM_AARCH64 {
return f.applyRelocationsARM64(dst, rels)
}
if f.Class == ELFCLASS32 && f.Machine == EM_PPC {
return f.applyRelocationsPPC(dst, rels)
}
if f.Class == ELFCLASS64 && f.Machine == EM_PPC64 {
return f.applyRelocationsPPC64(dst, rels)
}
@ -677,6 +680,46 @@ func (f *File) applyRelocationsARM64(dst []byte, rels []byte) error {
return nil
}
func (f *File) applyRelocationsPPC(dst []byte, rels []byte) error {
// 12 is the size of Rela32.
if len(rels)%12 != 0 {
return errors.New("length of relocation section is not a multiple of 12")
}
symbols, _, err := f.getSymbols(SHT_SYMTAB)
if err != nil {
return err
}
b := bytes.NewReader(rels)
var rela Rela32
for b.Len() > 0 {
binary.Read(b, f.ByteOrder, &rela)
symNo := rela.Info >> 8
t := R_PPC(rela.Info & 0xff)
if symNo == 0 || symNo > uint32(len(symbols)) {
continue
}
sym := &symbols[symNo-1]
if SymType(sym.Info&0xf) != STT_SECTION {
// We don't handle non-section relocations for now.
continue
}
switch t {
case R_PPC_ADDR32:
if rela.Off+4 >= uint32(len(dst)) || rela.Addend < 0 {
continue
}
f.ByteOrder.PutUint32(dst[rela.Off:rela.Off+4], uint32(rela.Addend))
}
}
return nil
}
func (f *File) applyRelocationsPPC64(dst []byte, rels []byte) error {
// 24 is the size of Rela64.
if len(rels)%24 != 0 {
@ -785,7 +828,7 @@ func (f *File) DWARF() (*dwarf.Data, error) {
// If there's a relocation table for .debug_info, we have to process it
// now otherwise the data in .debug_info is invalid for x86-64 objects.
rela := f.Section(".rela.debug_info")
if rela != nil && rela.Type == SHT_RELA && (f.Machine == EM_X86_64 || f.Machine == EM_AARCH64 || f.Machine == EM_PPC64 || f.Machine == EM_S390) {
if rela != nil && rela.Type == SHT_RELA && (f.Machine == EM_X86_64 || f.Machine == EM_AARCH64 || f.Machine == EM_PPC || f.Machine == EM_PPC64 || f.Machine == EM_S390) {
data, err := rela.Data()
if err != nil {
return nil, err

View File

@ -260,6 +260,12 @@ var relocationTests = []relocationTest{
{0, &dwarf.Entry{Offset: 0xb, Tag: dwarf.TagCompileUnit, Children: true, Field: []dwarf.Field{{Attr: dwarf.AttrProducer, Val: "GNU C 4.2.4 (Ubuntu 4.2.4-1ubuntu4)"}, {Attr: dwarf.AttrLanguage, Val: int64(1)}, {Attr: dwarf.AttrName, Val: "go-relocation-test-gcc424.c"}, {Attr: dwarf.AttrCompDir, Val: "/tmp"}, {Attr: dwarf.AttrLowpc, Val: uint64(0x0)}, {Attr: dwarf.AttrHighpc, Val: uint64(0x6)}, {Attr: dwarf.AttrStmtList, Val: int64(0)}}}},
},
},
{
"testdata/go-relocation-test-gcc5-ppc.obj",
[]relocationTestEntry{
{0, &dwarf.Entry{Offset: 0xb, Tag: dwarf.TagCompileUnit, Children: true, Field: []dwarf.Field{dwarf.Field{Attr: dwarf.AttrProducer, Val: "GNU C11 5.0.0 20150116 (experimental) -Asystem=linux -Asystem=unix -Asystem=posix -g"}, dwarf.Field{Attr: dwarf.AttrLanguage, Val: int64(12)}, dwarf.Field{Attr: dwarf.AttrName, Val: "go-relocation-test-gcc5-ppc.c"}, dwarf.Field{Attr: dwarf.AttrCompDir, Val: "/tmp"}, dwarf.Field{Attr: dwarf.AttrLowpc, Val: uint64(0x0)}, dwarf.Field{Attr: dwarf.AttrHighpc, Val: int64(0x44)}, dwarf.Field{Attr: dwarf.AttrStmtList, Val: int64(0)}}}},
},
},
{
"testdata/go-relocation-test-gcc482-ppc64le.obj",
[]relocationTestEntry{

View File

@ -268,6 +268,8 @@ var cgoEnabled = map[string]bool{
"linux/alpha": true,
"linux/amd64": true,
"linux/arm": true,
"linux/arm64": true,
"linux/ppc": true,
"linux/ppc64": true,
"linux/ppc64le": true,
"linux/s390": true,

View File

@ -1,302 +0,0 @@
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// builtin calls
package builtins
import "unsafe"
func _append() {
var x int
var s []byte
_0 := append /* ERROR "argument" */ ()
_1 := append("foo" /* ERROR "not a typed slice" */)
_2 := append(nil /* ERROR "not a typed slice" */, s)
_3 := append(x /* ERROR "not a typed slice" */, s)
_4 := append(s)
append /* ERROR "not used" */ (s)
}
func _cap() {
var a [10]bool
var p *[20]int
var s []int
var c chan string
_0 := cap /* ERROR "argument" */ ()
_1 := cap /* ERROR "argument" */ (1, 2)
_2 := cap(42 /* ERROR "invalid" */)
const _3 = cap(a)
assert(_3 == 10)
const _4 = cap(p)
assert(_4 == 20)
_5 := cap(c)
cap /* ERROR "not used" */ (c)
}
func _close() {
var c chan int
var r <-chan int
close /* ERROR "argument" */ ()
close /* ERROR "argument" */ (1, 2)
close(42 /* ERROR "not a channel" */)
close(r /* ERROR "receive-only channel" */)
close(c)
}
func _complex() {
var i32 int32
var f32 float32
var f64 float64
var c64 complex64
_ = complex /* ERROR "argument" */ ()
_ = complex /* ERROR "argument" */ (1)
_ = complex(true /* ERROR "invalid argument" */ , 0)
_ = complex(i32 /* ERROR "invalid argument" */ , 0)
_ = complex("foo" /* ERROR "invalid argument" */ , 0)
_ = complex(c64 /* ERROR "invalid argument" */ , 0)
_ = complex(0, true /* ERROR "invalid argument" */ )
_ = complex(0, i32 /* ERROR "invalid argument" */ )
_ = complex(0, "foo" /* ERROR "invalid argument" */ )
_ = complex(0, c64 /* ERROR "invalid argument" */ )
_ = complex(f32, f32)
_ = complex(f32, 1)
_ = complex(f32, 1.0)
_ = complex(f32, 'a')
_ = complex(f64, f64)
_ = complex(f64, 1)
_ = complex(f64, 1.0)
_ = complex(f64, 'a')
_ = complex(f32 /* ERROR "mismatched types" */, f64)
_ = complex(f64 /* ERROR "mismatched types" */, f32)
_ = complex(1, 1)
_ = complex(1, 1.1)
_ = complex(1, 'a')
complex /* ERROR "not used" */ (1, 2)
}
func _copy() {
copy /* ERROR "not enough arguments" */ ()
copy /* ERROR "not enough arguments" */ ("foo")
copy([ /* ERROR "copy expects slice arguments" */ ...]int{}, []int{})
copy([ /* ERROR "copy expects slice arguments" */ ]int{}, [...]int{})
copy([ /* ERROR "different element types" */ ]int8{}, "foo")
// spec examples
var a = [...]int{0, 1, 2, 3, 4, 5, 6, 7}
var s = make([]int, 6)
var b = make([]byte, 5)
n1 := copy(s, a[0:]) // n1 == 6, s == []int{0, 1, 2, 3, 4, 5}
n2 := copy(s, s[2:]) // n2 == 4, s == []int{2, 3, 4, 5, 4, 5}
n3 := copy(b, "Hello, World!") // n3 == 5, b == []byte("Hello")
}
func _delete() {
var m map[string]int
var s string
delete /* ERROR "argument" */ ()
delete /* ERROR "argument" */ (1)
delete /* ERROR "argument" */ (1, 2, 3)
delete(m, 0 /* ERROR "not assignable" */)
delete(m, s)
}
func _imag() {
var f32 float32
var f64 float64
var c64 complex64
var c128 complex128
_ = imag /* ERROR "argument" */ ()
_ = imag /* ERROR "argument" */ (1, 2)
_ = imag(10 /* ERROR "must be a complex number" */)
_ = imag(2.7182818 /* ERROR "must be a complex number" */)
_ = imag("foo" /* ERROR "must be a complex number" */)
const _5 = imag(1 + 2i)
assert(_5 == 2)
f32 = _5
f64 = _5
const _6 = imag(0i)
assert(_6 == 0)
f32 = imag(c64)
f64 = imag(c128)
f32 = imag /* ERROR "cannot assign" */ (c128)
f64 = imag /* ERROR "cannot assign" */ (c64)
imag /* ERROR "not used" */ (c64)
}
func _len() {
const c = "foobar"
var a [10]bool
var p *[20]int
var s []int
var m map[string]complex128
_ = len /* ERROR "argument" */ ()
_ = len /* ERROR "argument" */ (1, 2)
_ = len(42 /* ERROR "invalid" */)
const _3 = len(c)
assert(_3 == 6)
const _4 = len(a)
assert(_4 == 10)
const _5 = len(p)
assert(_5 == 20)
_ = len(m)
len /* ERROR "not used" */ (c)
// esoteric case
var t string
var hash map[interface{}][]*[10]int
const n = len /* ERROR "not constant" */ (hash[recover()][len(t)])
assert /* ERROR "failed" */ (n == 10)
var ch <-chan int
const nn = len /* ERROR "not constant" */ (hash[<-ch][len(t)])
_ = nn // TODO(gri) remove this once unused constants get type-checked
}
func _make() {
n := 0
_ = make /* ERROR "argument" */ ()
_ = make(1 /* ERROR "not a type" */)
_ = make(int /* ERROR "cannot make" */)
// slices
_ = make/* ERROR "arguments" */ ([]int)
_ = make/* ERROR "arguments" */ ([]int, 2, 3, 4)
_ = make([]int, int /* ERROR "not an expression" */)
_ = make([]int, 10, float32 /* ERROR "not an expression" */)
_ = make([]int, "foo" /* ERROR "must be an integer" */)
_ = make([]int, 10, 2.3 /* ERROR "must be an integer" */)
_ = make([]int, 5, 10.0)
_ = make([]int, 0i)
_ = make([]int, - /* ERROR "must not be negative" */ 1, 10)
_ = make([]int, 0, - /* ERROR "must not be negative" */ 1)
_ = make([]int, - /* ERROR "must not be negative" */ 1, - /* ERROR "must not be negative" */ 1)
_ = make([]int, 1<<100, 1<<100) // run-time panic
_ = make([]int, 1 /* ERROR "length and capacity swapped" */ <<100 + 1, 1<<100)
_ = make([]int, 1 /* ERROR "length and capacity swapped" */ <<100, 12345)
// maps
_ = make /* ERROR "arguments" */ (map[int]string, 10, 20)
_ = make(map[int]float32, int /* ERROR "not an expression" */)
_ = make(map[int]float32, "foo" /* ERROR "must be an integer" */)
_ = make(map[int]float32, 10)
_ = make(map[int]float32, n)
_ = make(map[int]float32, int64(n))
// channels
_ = make /* ERROR "arguments" */ (chan int, 10, 20)
_ = make(chan int, int /* ERROR "not an expression" */)
_ = make(chan<- int, "foo" /* ERROR "must be an integer" */)
_ = make(<-chan float64, 10)
_ = make(chan chan int, n)
_ = make(chan string, int64(n))
make /* ERROR "not used" */ ([]int, 10)
}
func _new() {
_ = new /* ERROR "argument" */ ()
_ = new /* ERROR "argument" */ (1, 2)
_ = new("foo" /* ERROR "not a type" */)
p := new(float64)
_ = new(struct{ x, y int })
q := new(*float64)
_ = *p == **q
new /* ERROR "not used" */ (int)
}
func _real() {
var f32 float32
var f64 float64
var c64 complex64
var c128 complex128
_ = real /* ERROR "argument" */ ()
_ = real /* ERROR "argument" */ (1, 2)
_ = real(10 /* ERROR "must be a complex number" */)
_ = real(2.7182818 /* ERROR "must be a complex number" */)
_ = real("foo" /* ERROR "must be a complex number" */)
const _5 = real(1 + 2i)
assert(_5 == 1)
f32 = _5
f64 = _5
const _6 = real(0i)
assert(_6 == 0)
f32 = real(c64)
f64 = real(c128)
f32 = real /* ERROR "cannot assign" */ (c128)
f64 = real /* ERROR "cannot assign" */ (c64)
real /* ERROR "not used" */ (c64)
}
func _recover() {
_ = recover()
_ = recover /* ERROR "argument" */ (10)
recover()
}
func _Alignof() {
var x int
_ = unsafe /* ERROR "argument" */ .Alignof()
_ = unsafe /* ERROR "argument" */ .Alignof(1, 2)
_ = unsafe.Alignof(int /* ERROR "not an expression" */)
_ = unsafe.Alignof(42)
_ = unsafe.Alignof(new(struct{}))
unsafe /* ERROR "not used" */ .Alignof(x)
}
func _Offsetof() {
var x struct{ f int }
_ = unsafe /* ERROR "argument" */ .Offsetof()
_ = unsafe /* ERROR "argument" */ .Offsetof(1, 2)
_ = unsafe.Offsetof(int /* ERROR "not an expression" */)
_ = unsafe.Offsetof(x /* ERROR "not a selector" */)
_ = unsafe.Offsetof(x.f)
_ = unsafe.Offsetof((x.f))
_ = unsafe.Offsetof((((((((x))).f)))))
unsafe /* ERROR "not used" */ .Offsetof(x.f)
}
func _Sizeof() {
var x int
_ = unsafe /* ERROR "argument" */ .Sizeof()
_ = unsafe /* ERROR "argument" */ .Sizeof(1, 2)
_ = unsafe.Sizeof(int /* ERROR "not an expression" */)
_ = unsafe.Sizeof(42)
_ = unsafe.Sizeof(new(complex128))
unsafe /* ERROR "not used" */ .Sizeof(x)
// basic types have size guarantees
assert(unsafe.Sizeof(byte(0)) == 1)
assert(unsafe.Sizeof(uint8(0)) == 1)
assert(unsafe.Sizeof(int8(0)) == 1)
assert(unsafe.Sizeof(uint16(0)) == 2)
assert(unsafe.Sizeof(int16(0)) == 2)
assert(unsafe.Sizeof(uint32(0)) == 4)
assert(unsafe.Sizeof(int32(0)) == 4)
assert(unsafe.Sizeof(float32(0)) == 4)
assert(unsafe.Sizeof(uint64(0)) == 8)
assert(unsafe.Sizeof(int64(0)) == 8)
assert(unsafe.Sizeof(float64(0)) == 8)
assert(unsafe.Sizeof(complex64(0)) == 8)
assert(unsafe.Sizeof(complex128(0)) == 16)
}
// self-testing only
func _assert() {
var x int
assert /* ERROR "argument" */ ()
assert /* ERROR "argument" */ (1, 2)
assert("foo" /* ERROR "boolean constant" */ )
assert(x /* ERROR "boolean constant" */)
assert(true)
assert /* ERROR "failed" */ (false)
}
// self-testing only
func _trace() {
// Uncomment the code below to test trace - will produce console output
// _ = trace /* ERROR "no value" */ ()
// _ = trace(1)
// _ = trace(true, 1.2, '\'', "foo", 42i, "foo" <= "bar")
}

View File

@ -1,215 +0,0 @@
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// constant declarations
package const0
// constants declarations must be initialized by constants
var x = 0
const c0 = x /* ERROR "not constant" */
// untyped constants
const (
// boolean values
ub0 = false
ub1 = true
ub2 = 2 < 1
ub3 = ui1 == uf1
ub4 = true /* ERROR "cannot convert" */ == 0
// integer values
ui0 = 0
ui1 = 1
ui2 = 42
ui3 = 3141592653589793238462643383279502884197169399375105820974944592307816406286
ui4 = -10
ui5 = ui0 + ui1
ui6 = ui1 - ui1
ui7 = ui2 * ui1
ui8 = ui3 / ui3
ui9 = ui3 % ui3
ui10 = 1 / 0 /* ERROR "division by zero" */
ui11 = ui1 / 0 /* ERROR "division by zero" */
ui12 = ui3 / ui0 /* ERROR "division by zero" */
ui13 = 1 % 0 /* ERROR "division by zero" */
ui14 = ui1 % 0 /* ERROR "division by zero" */
ui15 = ui3 % ui0 /* ERROR "division by zero" */
ui16 = ui2 & ui3
ui17 = ui2 | ui3
ui18 = ui2 ^ ui3
// floating point values
uf0 = 0.
uf1 = 1.
uf2 = 4.2e1
uf3 = 3.141592653589793238462643383279502884197169399375105820974944592307816406286
uf4 = 1e-1
uf5 = uf0 + uf1
uf6 = uf1 - uf1
uf7 = uf2 * uf1
uf8 = uf3 / uf3
uf9 = uf3 /* ERROR "not defined" */ % uf3
uf10 = 1 / 0 /* ERROR "division by zero" */
uf11 = uf1 / 0 /* ERROR "division by zero" */
uf12 = uf3 / uf0 /* ERROR "division by zero" */
uf16 = uf2 /* ERROR "not defined" */ & uf3
uf17 = uf2 /* ERROR "not defined" */ | uf3
uf18 = uf2 /* ERROR "not defined" */ ^ uf3
// complex values
uc0 = 0.i
uc1 = 1.i
uc2 = 4.2e1i
uc3 = 3.141592653589793238462643383279502884197169399375105820974944592307816406286i
uc4 = 1e-1i
uc5 = uc0 + uc1
uc6 = uc1 - uc1
uc7 = uc2 * uc1
uc8 = uc3 / uc3
uc9 = uc3 /* ERROR "not defined" */ % uc3
uc10 = 1 / 0 /* ERROR "division by zero" */
uc11 = uc1 / 0 /* ERROR "division by zero" */
uc12 = uc3 / uc0 /* ERROR "division by zero" */
uc16 = uc2 /* ERROR "not defined" */ & uc3
uc17 = uc2 /* ERROR "not defined" */ | uc3
uc18 = uc2 /* ERROR "not defined" */ ^ uc3
)
type (
mybool bool
myint int
myfloat float64
mycomplex complex128
)
// typed constants
const (
// boolean values
tb0 bool = false
tb1 bool = true
tb2 mybool = 2 < 1
tb3 mybool = ti1 /* ERROR "cannot compare" */ == tf1
// integer values
ti0 int8 = ui0
ti1 int32 = ui1
ti2 int64 = ui2
ti3 myint = ui3 /* ERROR "overflows" */
ti4 myint = ui4
ti5 = ti0 /* ERROR "mismatched types" */ + ti1
ti6 = ti1 - ti1
ti7 = ti2 /* ERROR "mismatched types" */ * ti1
//ti8 = ti3 / ti3 // TODO(gri) enable this
//ti9 = ti3 % ti3 // TODO(gri) enable this
ti10 = 1 / 0 /* ERROR "division by zero" */
ti11 = ti1 / 0 /* ERROR "division by zero" */
ti12 = ti3 /* ERROR "mismatched types" */ / ti0
ti13 = 1 % 0 /* ERROR "division by zero" */
ti14 = ti1 % 0 /* ERROR "division by zero" */
ti15 = ti3 /* ERROR "mismatched types" */ % ti0
ti16 = ti2 /* ERROR "mismatched types" */ & ti3
ti17 = ti2 /* ERROR "mismatched types" */ | ti4
ti18 = ti2 ^ ti5 // no mismatched types error because the type of ti5 is unknown
// floating point values
tf0 float32 = 0.
tf1 float32 = 1.
tf2 float64 = 4.2e1
tf3 myfloat = 3.141592653589793238462643383279502884197169399375105820974944592307816406286
tf4 myfloat = 1e-1
tf5 = tf0 + tf1
tf6 = tf1 - tf1
tf7 = tf2 /* ERROR "mismatched types" */ * tf1
// tf8 = tf3 / tf3 // TODO(gri) enable this
tf9 = tf3 /* ERROR "not defined" */ % tf3
tf10 = 1 / 0 /* ERROR "division by zero" */
tf11 = tf1 / 0 /* ERROR "division by zero" */
tf12 = tf3 /* ERROR "mismatched types" */ / tf0
tf16 = tf2 /* ERROR "mismatched types" */ & tf3
tf17 = tf2 /* ERROR "mismatched types" */ | tf3
tf18 = tf2 /* ERROR "mismatched types" */ ^ tf3
// complex values
tc0 = 0.i
tc1 = 1.i
tc2 = 4.2e1i
tc3 = 3.141592653589793238462643383279502884197169399375105820974944592307816406286i
tc4 = 1e-1i
tc5 = tc0 + tc1
tc6 = tc1 - tc1
tc7 = tc2 * tc1
tc8 = tc3 / tc3
tc9 = tc3 /* ERROR "not defined" */ % tc3
tc10 = 1 / 0 /* ERROR "division by zero" */
tc11 = tc1 / 0 /* ERROR "division by zero" */
tc12 = tc3 / tc0 /* ERROR "division by zero" */
tc16 = tc2 /* ERROR "not defined" */ & tc3
tc17 = tc2 /* ERROR "not defined" */ | tc3
tc18 = tc2 /* ERROR "not defined" */ ^ tc3
)
// initialization cycles
const (
a /* ERROR "cycle" */ = a
b /* ERROR "cycle" */ , c /* ERROR "cycle" */, d, e = e, d, c, b // TODO(gri) should only have one cycle error
f float64 = d
)
// multiple initialization
const (
a1, a2, a3 = 7, 3.1415926, "foo"
b1, b2, b3 = b3, b1, 42
_p0 = assert(a1 == 7)
_p1 = assert(a2 == 3.1415926)
_p2 = assert(a3 == "foo")
_p3 = assert(b1 == 42)
_p4 = assert(b2 == 42)
_p5 = assert(b3 == 42)
)
// iota
const (
iota0 = iota
iota1 = iota
iota2 = iota*2
_a0 = assert(iota0 == 0)
_a1 = assert(iota1 == 1)
_a2 = assert(iota2 == 4)
iota6 = iota*3
iota7
iota8
_a3 = assert(iota7 == 21)
_a4 = assert(iota8 == 24)
)
const (
_b0 = iota
_b1 = assert(iota + iota2 == 5)
)
// special cases
const (
_n0 = nil /* ERROR "invalid constant type" */
_n1 = [ /* ERROR "not constant" */ ]int{}
)

View File

@ -1,18 +0,0 @@
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// conversions
package conversions
// argument count
var (
_v0 = int /* ERROR "one argument" */ ()
_v1 = int /* ERROR "one argument" */ (1, 2)
)
//
var (
_v2 = int8(0)
)

View File

@ -1,177 +0,0 @@
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// type declarations
package decls0
import (
"unsafe"
// we can have multiple blank imports (was bug)
_ "math"
_ "net/rpc"
)
const pi = 3.1415
type (
N undeclared /* ERROR "undeclared" */
B bool
I int32
A [10]P
T struct {
x, y P
}
P *T
R (*R)
F func(A) I
Y interface {
f(A) I
}
S [](((P)))
M map[I]F
C chan<- I
// blank types must be typechecked
_ pi /* ERROR "not a type" */
_ struct{}
_ struct{ pi /* ERROR "not a type" */ }
)
// invalid array types
type (
iA0 [... /* ERROR "invalid use of '...'" */ ]byte
iA1 [1 /* ERROR "invalid array length" */ <<100]int
iA2 [- /* ERROR "invalid array length" */ 1]complex128
iA3 ["foo" /* ERROR "invalid array length" */ ]string
)
type (
p1 pi /* ERROR "no single field or method foo" */ .foo
p2 unsafe.Pointer
)
type (
Pi pi /* ERROR "not a type" */
a /* ERROR "illegal cycle" */ a
a /* ERROR "redeclared" */ int
// where the cycle error appears depends on the
// order in which declarations are processed
// (which depends on the order in which a map
// is iterated through)
b /* ERROR "illegal cycle" */ c
c d
d e
e b
t *t
U V
V *W
W U
P1 *S2
P2 P1
S0 struct {
}
S1 struct {
a, b, c int
u, v, a /* ERROR "redeclared" */ float32
}
S2 struct {
U // anonymous field
// TODO(gri) recognize double-declaration below
// U /* ERROR "redeclared" */ int
}
S3 struct {
x S2
}
S4/* ERROR "illegal cycle" */ struct {
S4
}
S5 /* ERROR "illegal cycle" */ struct {
S6
}
S6 struct {
field S7
}
S7 struct {
S5
}
L1 []L1
L2 []int
A1 [10.0]int
A2 /* ERROR "illegal cycle" */ [10]A2
A3 /* ERROR "illegal cycle" */ [10]struct {
x A4
}
A4 [10]A3
F1 func()
F2 func(x, y, z float32)
F3 func(x, y, x /* ERROR "redeclared" */ float32)
F4 func() (x, y, x /* ERROR "redeclared" */ float32)
F5 func(x int) (x /* ERROR "redeclared" */ float32)
F6 func(x ...int)
I1 interface{}
I2 interface {
m1()
}
I3 interface { /* ERROR "multiple methods named m1" */
m1()
m1 /* ERROR "redeclared" */ ()
}
I4 interface {
m1(x, y, x /* ERROR "redeclared" */ float32)
m2() (x, y, x /* ERROR "redeclared" */ float32)
m3(x int) (x /* ERROR "redeclared" */ float32)
}
I5 interface {
m1(I5)
}
I6 interface {
S0 /* ERROR "not an interface" */
}
I7 interface {
I1
I1
}
I8 /* ERROR "illegal cycle" */ interface {
I8
}
// Use I09 (rather than I9) because it appears lexically before
// I10 so that we get the illegal cycle here rather then in the
// declaration of I10. If the implementation sorts by position
// rather than name, the error message will still be here.
I09 /* ERROR "illegal cycle" */ interface {
I10
}
I10 interface {
I11
}
I11 interface {
I09
}
C1 chan int
C2 <-chan int
C3 chan<- C3
C4 chan C5
C5 chan C6
C6 chan C4
M1 map[Last]string
M2 map[string]M2
Last int
)

View File

@ -1,132 +0,0 @@
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// variable declarations
package decls1
import (
"math"
)
// Global variables without initialization
var (
a, b bool
c byte
d uint8
r rune
i int
j, k, l int
x, y float32
xx, yy float64
u, v complex64
uu, vv complex128
s, t string
array []byte
iface interface{}
blank _ /* ERROR "cannot use _" */
)
// Global variables with initialization
var (
s1 = i + j
s2 = i /* ERROR "mismatched types" */ + x
s3 = c + d
s4 = s + t
s5 = s /* ERROR "invalid operation" */ / t
s6 = array[t1]
s7 = array[x /* ERROR "index" */]
s8 = &a
s10 = &42 /* ERROR "cannot take address" */
s11 = &v
s12 = -(u + *t11) / *&v
s13 = a /* ERROR "shifted operand" */ << d
s14 = i << j /* ERROR "must be unsigned" */
s18 = math.Pi * 10.0
s19 = s1 /* ERROR "cannot call" */ ()
s20 = f0 /* ERROR "no value" */ ()
s21 = f6(1, s1, i)
s22 = f6(1, s1, uu /* ERROR "cannot assign" */ )
t1 int = i + j
t2 int = i /* ERROR "mismatched types" */ + x
t3 int = c /* ERROR "cannot assign" */ + d
t4 string = s + t
t5 string = s /* ERROR "invalid operation" */ / t
t6 byte = array[t1]
t7 byte = array[x /* ERROR "index" */]
t8 *int = & /* ERROR "cannot assign" */ a
t10 *int = &42 /* ERROR "cannot take address" */
t11 *complex64 = &v
t12 complex64 = -(u + *t11) / *&v
t13 int = a /* ERROR "shifted operand" */ << d
t14 int = i << j /* ERROR "must be unsigned" */
t15 math /* ERROR "not in selector" */
t16 math.xxx /* ERROR "unexported" */
t17 math /* ERROR "not a type" */ .Pi
t18 float64 = math.Pi * 10.0
t19 int = t1 /* ERROR "cannot call" */ ()
t20 int = f0 /* ERROR "no value" */ ()
)
// Various more complex expressions
var (
u1 = x /* ERROR "not an interface" */ .(int)
u2 = iface.([]int)
u3 = iface.(a /* ERROR "not a type" */ )
u4, ok = iface.(int)
u5 /* ERROR "assignment count mismatch" */ , ok2, ok3 = iface.(int)
)
// Constant expression initializations
var (
v1 = 1 /* ERROR "cannot convert" */ + "foo"
v2 = c + 255
v3 = c + 256 /* ERROR "overflows" */
v4 = r + 2147483647
v5 = r + 2147483648 /* ERROR "overflows" */
v6 = 42
v7 = v6 + 2147483647
v8 = v6 + 2147483648 /* ERROR "overflows" */
v9 = i + 1 << 10
v10 byte = 1024 /* ERROR "overflows" */
v11 = xx/yy*yy - xx
v12 = true && false
v13 = nil /* ERROR "use of untyped nil" */
)
// Multiple assignment expressions
var (
m1a, m1b = 1, 2
m2a /* ERROR "assignment count mismatch" */ , m2b, m2c = 1, 2
m3a /* ERROR "assignment count mismatch" */ , m3b = 1, 2, 3
)
// Declaration of parameters and results
func f0() {}
func f1(a /* ERROR "not a type" */) {}
func f2(a, b, c d /* ERROR "not a type" */) {}
func f3() int {}
func f4() a /* ERROR "not a type" */ {}
func f5() (a, b, c d /* ERROR "not a type" */) {}
func f6(a, b, c int) complex128 { return 0 }
// Declaration of receivers
type T struct{}
func (T) m0() {}
func (*T) m1() {}
func (x T) m2() {}
func (x *T) m3() {}
// Initialization functions
func init() {}
func /* ERROR "no arguments and no return values" */ init(int) {}
func /* ERROR "no arguments and no return values" */ init() int { return 0 }
func /* ERROR "no arguments and no return values" */ init(int) int {}
func (T) init(int) int { return 0 }

View File

@ -1,67 +0,0 @@
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// method declarations
package decls2
import "time"
// T1 declared before its methods.
type T1 struct{
f int
}
func (T1) m() {}
func (T1) m /* ERROR "redeclared" */ () {}
func (x *T1) f /* ERROR "field and method" */ () {}
// T2's method declared before the type.
func (*T2) f /* ERROR "field and method" */ () {}
type T2 struct {
f int
}
// Methods declared without a declared type.
func (undeclared /* ERROR "undeclared" */) m() {}
func (x *undeclared /* ERROR "undeclared" */) m() {}
// TODO(gri) try to get rid of double error reporting here
func (pi /* ERROR "not a type" */) m1() {}
func (x pi /* ERROR "not a type" */) m2() {}
func (x *pi /* ERROR "not a type" */ ) m3() {} // TODO(gri) not closing the last /* comment crashes the system
// Blank types.
type _ struct { m int }
type _ struct { m int }
// TODO(gri) blank idents not fully checked - disabled for now
// func (_ /* ERROR "cannot use _" */) m() {}
// func (_ /* ERROR "cannot use _" */) m() {}
// Methods with receiver base type declared in another file.
func (T3) m1() {}
func (*T3) m2() {}
func (x T3) m3() {}
func (x *T3) f /* ERROR "field and method" */ () {}
// Methods of non-struct type.
type T4 func()
func (self T4) m() func() { return self }
// Methods associated with an interface.
type T5 interface {
m() int
}
func (T5 /* ERROR "invalid receiver" */) m1() {}
func (T5 /* ERROR "invalid receiver" */) m2() {}
// Methods associated with non-local or unnamed types.
func (int /* ERROR "non-local type" */ ) m() {}
func ([ /* ERROR "expected" */ ]int) m() {}
func (time /* ERROR "expected" */ .Time) m() {}
func (x interface /* ERROR "expected" */ {}) m() {}

View File

@ -1,28 +0,0 @@
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// method declarations
package decls2
const pi = 3.1415
func (T1) m /* ERROR "redeclared" */ () {}
type T3 struct {
f *T3
}
type T6 struct {
x int
}
func (t *T6) m1() int {
return t.x
}
func f() {
var t *T6
t.m1()
}

View File

@ -1,231 +0,0 @@
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// embedded types
package decls3
// fields with the same name at the same level cancel each other out
func _() {
type (
T1 struct { X int }
T2 struct { X int }
T3 struct { T1; T2 } // X is embedded twice at the same level via T1->X, T2->X
)
var t T3
_ = t /* ERROR "no single field or method" */ .X
}
func _() {
type (
T1 struct { X int }
T2 struct { T1 }
T3 struct { T1 }
T4 struct { T2; T3 } // X is embedded twice at the same level via T2->T1->X, T3->T1->X
)
var t T4
_ = t /* ERROR "no single field or method" */ .X
}
func issue4355() {
type (
T1 struct {X int}
T2 struct {T1}
T3 struct {T2}
T4 struct {T2}
T5 struct {T3; T4} // X is embedded twice at the same level via T3->T2->T1->X, T4->T2->T1->X
)
var t T5
_ = t /* ERROR "no single field or method" */ .X
}
// Borrowed from the FieldByName test cases in reflect/all_test.go.
type D1 struct {
d int
}
type D2 struct {
d int
}
type S0 struct {
A, B, C int
D1
D2
}
type S1 struct {
B int
S0
}
type S2 struct {
A int
*S1
}
type S1x struct {
S1
}
type S1y struct {
S1
}
type S3 struct {
S1x
S2
D, E int
*S1y
}
type S4 struct {
*S4
A int
}
// The X in S6 and S7 annihilate, but they also block the X in S8.S9.
type S5 struct {
S6
S7
S8
}
type S6 struct {
X int
}
type S7 S6
type S8 struct {
S9
}
type S9 struct {
X int
Y int
}
// The X in S11.S6 and S12.S6 annihilate, but they also block the X in S13.S8.S9.
type S10 struct {
S11
S12
S13
}
type S11 struct {
S6
}
type S12 struct {
S6
}
type S13 struct {
S8
}
func _() {
_ = struct /* ERROR "no single field or method" */ {}{}.Foo
_ = S0{}.A
_ = S0 /* ERROR "no single field or method" */ {}.D
_ = S1{}.A
_ = S1{}.B
_ = S1{}.S0
_ = S1{}.C
_ = S2{}.A
_ = S2{}.S1
_ = S2{}.B
_ = S2{}.C
_ = S2 /* ERROR "no single field or method" */ {}.D
_ = S3 /* ERROR "no single field or method" */ {}.S1
_ = S3{}.A
_ = S3 /* ERROR "no single field or method" */ {}.B
_ = S3{}.D
_ = S3{}.E
_ = S4{}.A
_ = S4 /* ERROR "no single field or method" */ {}.B
_ = S5 /* ERROR "no single field or method" */ {}.X
_ = S5{}.Y
_ = S10 /* ERROR "no single field or method" */ {}.X
_ = S10{}.Y
}
// Borrowed from the FieldByName benchmark in reflect/all_test.go.
type R0 struct {
*R1
*R2
*R3
*R4
}
type R1 struct {
*R5
*R6
*R7
*R8
}
type R2 R1
type R3 R1
type R4 R1
type R5 struct {
*R9
*R10
*R11
*R12
}
type R6 R5
type R7 R5
type R8 R5
type R9 struct {
*R13
*R14
*R15
*R16
}
type R10 R9
type R11 R9
type R12 R9
type R13 struct {
*R17
*R18
*R19
*R20
}
type R14 R13
type R15 R13
type R16 R13
type R17 struct {
*R21
*R22
*R23
*R24
}
type R18 R17
type R19 R17
type R20 R17
type R21 struct {
X int
}
type R22 R21
type R23 R21
type R24 R21
var _ = R0 /* ERROR "no single field or method" */ {}.X

View File

@ -1,151 +0,0 @@
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// unary expressions
package expr0
var (
// bool
b0 = true
b1 bool = b0
b2 = !true
b3 = !b1
b4 bool = !true
b5 bool = !b4
b6 = +b0 /* ERROR "not defined" */
b7 = -b0 /* ERROR "not defined" */
b8 = ^b0 /* ERROR "not defined" */
b9 = *b0 /* ERROR "cannot indirect" */
b10 = &true /* ERROR "cannot take address" */
b11 = &b0
b12 = <-b0 /* ERROR "cannot receive" */
// int
i0 = 1
i1 int = i0
i2 = +1
i3 = +i0
i4 int = +1
i5 int = +i4
i6 = -1
i7 = -i0
i8 int = -1
i9 int = -i4
i10 = !i0 /* ERROR "not defined" */
i11 = ^1
i12 = ^i0
i13 int = ^1
i14 int = ^i4
i15 = *i0 /* ERROR "cannot indirect" */
i16 = &i0
i17 = *i16
i18 = <-i16 /* ERROR "cannot receive" */
// uint
u0 = uint(1)
u1 uint = u0
u2 = +1
u3 = +u0
u4 uint = +1
u5 uint = +u4
u6 = -1
u7 = -u0
u8 uint = - /* ERROR "overflows" */ 1
u9 uint = -u4
u10 = !u0 /* ERROR "not defined" */
u11 = ^1
u12 = ^i0
u13 uint = ^ /* ERROR "overflows" */ 1
u14 uint = ^u4
u15 = *u0 /* ERROR "cannot indirect" */
u16 = &u0
u17 = *u16
u18 = <-u16 /* ERROR "cannot receive" */
u19 = ^uint(0)
// float64
f0 = float64(1)
f1 float64 = f0
f2 = +1
f3 = +f0
f4 float64 = +1
f5 float64 = +f4 /* ERROR not defined */
f6 = -1
f7 = -f0
f8 float64 = -1
f9 float64 = -f4
f10 = !f0 /* ERROR "not defined" */
f11 = ^1
f12 = ^i0
f13 float64 = ^1
f14 float64 = ^f4 /* ERROR "not defined" */
f15 = *f0 /* ERROR "cannot indirect" */
f16 = &f0
f17 = *u16
f18 = <-u16 /* ERROR "cannot receive" */
// complex128
c0 = complex128(1)
c1 complex128 = c0
c2 = +1
c3 = +c0
c4 complex128 = +1
c5 complex128 = +c4 /* ERROR not defined */
c6 = -1
c7 = -c0
c8 complex128 = -1
c9 complex128 = -c4
c10 = !c0 /* ERROR "not defined" */
c11 = ^1
c12 = ^i0
c13 complex128 = ^1
c14 complex128 = ^c4 /* ERROR "not defined" */
c15 = *c0 /* ERROR "cannot indirect" */
c16 = &c0
c17 = *u16
c18 = <-u16 /* ERROR "cannot receive" */
// string
s0 = "foo"
s1 = +"foo" /* ERROR "not defined" */
s2 = -s0 /* ERROR "not defined" */
s3 = !s0 /* ERROR "not defined" */
s4 = ^s0 /* ERROR "not defined" */
s5 = *s4 /* ERROR "cannot indirect" */
s6 = &s4
s7 = *s6
s8 = <-s7 /* ERROR "cannot receive" */
// channel
ch chan int
rc <-chan float64
sc chan <- string
ch0 = +ch /* ERROR "not defined" */
ch1 = -ch /* ERROR "not defined" */
ch2 = !ch /* ERROR "not defined" */
ch3 = ^ch /* ERROR "not defined" */
ch4 = *ch /* ERROR "cannot indirect" */
ch5 = &ch
ch6 = *ch5
ch7 = <-ch
ch8 = <-rc
ch9 = <-sc /* ERROR "cannot receive" */
)
// address of composite literals
type T struct{x, y int}
func f() T { return T{} }
var (
_ = &T{1, 2}
_ = &[...]int{}
_ = &[]int{}
_ = &[]int{}
_ = &map[string]T{}
_ = &(T{1, 2})
_ = &((((T{1, 2}))))
_ = &f /* ERROR "cannot take address" */ ()
)

View File

@ -1,7 +0,0 @@
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// binary expressions
package expr1

View File

@ -1,23 +0,0 @@
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// comparisons
package expr2
func _bool() {
const t = true == true
const f = true == false
_ = t /* ERROR "cannot compare" */ < f
_ = 0 /* ERROR "cannot convert" */ == t
var b bool
var x, y float32
b = x < y
_ = struct{b bool}{x < y}
}
// corner cases
var (
v0 = nil /* ERROR "cannot compare" */ == nil
)

View File

@ -1,367 +0,0 @@
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// various expressions
package expr3
func shifts1() {
var (
i0 int
u0 uint
)
var (
v0 = 1<<0
v1 = 1<<i0 /* ERROR "must be unsigned" */
v2 = 1<<u0
v3 = 1<<"foo" /* ERROR "must be unsigned" */
v4 = 1<<- /* ERROR "stupid shift" */ 1
v5 = 1<<1025 /* ERROR "stupid shift" */
v6 = 1 /* ERROR "overflows" */ <<100
v10 uint = 1 << 0
v11 uint = 1 << u0
v12 float32 = 1 /* ERROR "must be integer" */ << u0
)
}
func shifts2() {
// TODO(gri) enable commented out tests below.
var (
s uint = 33
i = 1<<s // 1 has type int
j int32 = 1<<s // 1 has type int32; j == 0
k = uint64(1<<s) // 1 has type uint64; k == 1<<33
m int = 1.0<<s // 1.0 has type int
// n = 1.0<<s != 0 // 1.0 has type int; n == false if ints are 32bits in size
o = 1<<s == 2<<s // 1 and 2 have type int; o == true if ints are 32bits in size
// p = 1<<s == 1 /* ERROR "overflows" */ <<33 // illegal if ints are 32bits in size: 1 has type int, but 1<<33 overflows int
u = 1.0 /* ERROR "must be integer" */ <<s // illegal: 1.0 has type float64, cannot shift
v float32 = 1 /* ERROR "must be integer" */ <<s // illegal: 1 has type float32, cannot shift
w int64 = 1.0<<33 // 1.0<<33 is a constant shift expression
)
}
// TODO(gri) The error messages below depond on adjusting the spec
// to reflect what gc is doing at the moment (the spec
// asks for run-time errors at the moment - see issue 4231).
//
func indexes() {
_ = 1 /* ERROR "cannot index" */ [0]
_ = indexes /* ERROR "cannot index" */ [0]
_ = ( /* ERROR "cannot slice" */ 12 + 3)[1:2]
var a [10]int
_ = a[true /* ERROR "must be integer" */ ]
_ = a["foo" /* ERROR "must be integer" */ ]
_ = a[1.1 /* ERROR "must be integer" */ ]
_ = a[1.0]
_ = a[- /* ERROR "index .* negative" */ 1]
_ = a[- /* ERROR "index .* negative" */ 1 :]
_ = a[: - /* ERROR "index .* negative" */ 1]
var a0 int
a0 = a[0]
var a1 int32
a1 = a /* ERROR "cannot assign" */ [1]
_ = a[9]
_ = a[10 /* ERROR "index .* out of bounds" */ ]
_ = a[1 /* ERROR "stupid index" */ <<100]
_ = a[10:]
_ = a[:10]
_ = a[10:10]
_ = a[11 /* ERROR "index .* out of bounds" */ :]
_ = a[: 11 /* ERROR "index .* out of bounds" */ ]
_ = a[: 1 /* ERROR "stupid index" */ <<100]
pa := &a
_ = pa[9]
_ = pa[10 /* ERROR "index .* out of bounds" */ ]
_ = pa[1 /* ERROR "stupid index" */ <<100]
_ = pa[10:]
_ = pa[:10]
_ = pa[10:10]
_ = pa[11 /* ERROR "index .* out of bounds" */ :]
_ = pa[: 11 /* ERROR "index .* out of bounds" */ ]
_ = pa[: 1 /* ERROR "stupid index" */ <<100]
var b [0]int
_ = b[0 /* ERROR "index .* out of bounds" */ ]
_ = b[:]
_ = b[0:]
_ = b[:0]
_ = b[0:0]
var s []int
_ = s[- /* ERROR "index .* negative" */ 1]
_ = s[- /* ERROR "index .* negative" */ 1 :]
_ = s[: - /* ERROR "index .* negative" */ 1]
_ = s[0]
_ = s[1 : 2]
_ = s[2 /* ERROR "inverted slice range" */ : 1]
_ = s[2 :]
_ = s[: 1 /* ERROR "stupid index" */ <<100]
_ = s[1 /* ERROR "stupid index" */ <<100 :]
_ = s[1 /* ERROR "stupid index" */ <<100 : 1 /* ERROR "stupid index" */ <<100]
var t string
_ = t[- /* ERROR "index .* negative" */ 1]
_ = t[- /* ERROR "index .* negative" */ 1 :]
_ = t[: - /* ERROR "index .* negative" */ 1]
var t0 byte
t0 = t[0]
var t1 rune
t1 = t /* ERROR "cannot assign" */ [2]
_ = ("foo" + "bar")[5]
_ = ("foo" + "bar")[6 /* ERROR "index .* out of bounds" */ ]
const c = "foo"
_ = c[- /* ERROR "index .* negative" */ 1]
_ = c[- /* ERROR "index .* negative" */ 1 :]
_ = c[: - /* ERROR "index .* negative" */ 1]
var c0 byte
c0 = c[0]
var c2 float32
c2 = c /* ERROR "cannot assign" */ [2]
_ = c[3 /* ERROR "index .* out of bounds" */ ]
_ = ""[0 /* ERROR "index .* out of bounds" */ ]
_ = s[1<<30] // no compile-time error here
}
type T struct {
x int
}
func (*T) m() {}
func method_expressions() {
_ = T /* ERROR "no single field or method" */ .a
_ = T /* ERROR "has no method" */ .x
_ = T.m
var f func(*T) = (*T).m
var g func(*T) = ( /* ERROR "cannot assign" */ T).m
}
func struct_literals() {
type T0 struct {
a, b, c int
}
type T1 struct {
T0
a, b int
u float64
s string
}
// keyed elements
_ = T1{}
_ = T1{a: 0, 1 /* ERROR "mixture of .* elements" */ }
_ = T1{aa /* ERROR "unknown field" */ : 0}
_ = T1{1 /* ERROR "invalid field name" */ : 0}
_ = T1{a: 0, s: "foo", u: 0, a /* ERROR "duplicate field" */: 10}
_ = T1{a: "foo" /* ERROR "cannot use" */ }
_ = T1{c /* ERROR "unknown field" */ : 0}
_ = T1{T0: { /* ERROR "missing type" */ }}
_ = T1{T0: T0{}}
_ = T1{T0 /* ERROR "invalid field name" */ .a: 0}
// unkeyed elements
_ = T0{1, 2, 3}
_ = T0{1, b /* ERROR "mixture" */ : 2, 3}
_ = T0{1, 2} /* ERROR "too few values" */
_ = T0{1, 2, 3, 4 /* ERROR "too many values" */ }
_ = T0{1, "foo" /* ERROR "cannot use" */, 3.4 /* ERROR "cannot use" */}
}
func array_literals() {
type A0 [0]int
_ = A0{}
_ = A0{0 /* ERROR "index .* out of bounds" */}
_ = A0{0 /* ERROR "index .* out of bounds" */ : 0}
type A1 [10]int
_ = A1{}
_ = A1{0, 1, 2}
_ = A1{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
_ = A1{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 /* ERROR "index .* out of bounds" */ }
_ = A1{- /* ERROR "index .* negative" */ 1: 0}
_ = A1{8: 8, 9}
_ = A1{8: 8, 9, 10 /* ERROR "index .* out of bounds" */ }
_ = A1{0, 1, 2, 0 /* ERROR "duplicate index" */ : 0, 3: 3, 4}
_ = A1{5: 5, 6, 7, 3: 3, 4}
_ = A1{5: 5, 6, 7, 3: 3, 4, 5 /* ERROR "duplicate index" */ }
_ = A1{10 /* ERROR "index .* out of bounds" */ : 10, 10 /* ERROR "index .* out of bounds" */ : 10}
_ = A1{5: 5, 6, 7, 3: 3, 1 /* ERROR "stupid index" */ <<100: 4, 5 /* ERROR "duplicate index" */ }
_ = A1{5: 5, 6, 7, 4: 4, 1 /* ERROR "stupid index" */ <<100: 4}
_ = A1{2.0}
_ = A1{2.1 /* ERROR "cannot use" */ }
_ = A1{"foo" /* ERROR "cannot use" */ }
a0 := [...]int{}
assert(len(a0) == 0)
a1 := [...]int{0, 1, 2}
assert(len(a1) == 3)
var a13 [3]int
var a14 [4]int
a13 = a1
a14 = a1 /* ERROR "cannot assign" */
a2 := [...]int{- /* ERROR "index .* negative" */ 1: 0}
a3 := [...]int{0, 1, 2, 0 /* ERROR "duplicate index" */ : 0, 3: 3, 4}
assert(len(a3) == 5) // somewhat arbitrary
a4 := [...]complex128{0, 1, 2, 1<<10-2: -1i, 1i, 400: 10, 12, 14}
assert(len(a4) == 1024)
// from the spec
type Point struct { x, y float32 }
_ = [...]Point{Point{1.5, -3.5}, Point{0, 0}}
_ = [...]Point{{1.5, -3.5}, {0, 0}}
_ = [][]int{[]int{1, 2, 3}, []int{4, 5}}
_ = [][]int{{1, 2, 3}, {4, 5}}
_ = [...]*Point{&Point{1.5, -3.5}, &Point{0, 0}}
_ = [...]*Point{{1.5, -3.5}, {0, 0}}
}
func slice_literals() {
type S0 []int
_ = S0{}
_ = S0{0, 1, 2}
_ = S0{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
_ = S0{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
_ = S0{- /* ERROR "index .* negative" */ 1: 0}
_ = S0{8: 8, 9}
_ = S0{8: 8, 9, 10}
_ = S0{0, 1, 2, 0 /* ERROR "duplicate index" */ : 0, 3: 3, 4}
_ = S0{5: 5, 6, 7, 3: 3, 4}
_ = S0{5: 5, 6, 7, 3: 3, 4, 5 /* ERROR "duplicate index" */ }
_ = S0{10: 10, 10 /* ERROR "duplicate index" */ : 10}
_ = S0{5: 5, 6, 7, 3: 3, 1 /* ERROR "stupid index" */ <<100: 4, 5 /* ERROR "duplicate index" */ }
_ = S0{5: 5, 6, 7, 4: 4, 1 /* ERROR "stupid index" */ <<100: 4}
_ = S0{2.0}
_ = S0{2.1 /* ERROR "cannot use" */ }
_ = S0{"foo" /* ERROR "cannot use" */ }
// indices must be resolved correctly
// (for details, see comment in go/parser/parser.go, method parseElement)
index1 := 1
_ = S0{index1: 1}
_ = S0{index2: 2}
_ = S0{index3 /* ERROR "undeclared name" */ : 3}
}
var index2 int = 2
func map_literals() {
type M0 map[string]int
_ = M0{}
_ = M0{1 /* ERROR "missing key" */ }
_ = M0{1 /* ERROR "cannot use .* as string key" */ : 2}
_ = M0{"foo": "bar" /* ERROR "cannot use .* as int value" */ }
_ = M0{"foo": 1, "bar": 2, "foo" /* ERROR "duplicate key" */ : 3 }
// map keys must be resolved correctly
// (for detials, see comment in go/parser/parser.go, method parseElement)
key1 := "foo"
_ = M0{key1: 1}
_ = M0{key2: 2}
_ = M0{key3 /* ERROR "undeclared name" */ : 2}
}
var key2 string = "bar"
type I interface {
m()
}
type I2 interface {
m(int)
}
type T1 struct{}
type T2 struct{}
func (T2) m(int) {}
func type_asserts() {
var x int
_ = x /* ERROR "not an interface" */ .(int)
var e interface{}
var ok bool
x, ok = e.(int)
var t I
_ = t /* ERROR "use of .* outside type switch" */ .(type)
_ = t.(T)
_ = t.(T1 /* ERROR "missing method m" */ )
_ = t.(T2 /* ERROR "wrong type for method m" */ )
_ = t.(I2 /* ERROR "wrong type for method m" */ )
}
func f0() {}
func f1(x int) {}
func f2(u float32, s string) {}
func fs(s []byte) {}
func fv(x ...int) {}
func fi(x ... interface{}) {}
func g0() {}
func g1() int { return 0}
func g2() (u float32, s string) { return }
func gs() []byte { return nil }
func _calls() {
var x int
var y float32
var s []int
f0()
_ = f0 /* ERROR "used as value" */ ()
f0(g0 /* ERROR "too many arguments" */ )
f1(0)
f1(x)
f1(10.0)
f1 /* ERROR "too few arguments" */ ()
f1(x, y /* ERROR "too many arguments" */ )
f1(s /* ERROR "cannot assign" */ )
f1(x ... /* ERROR "cannot use ..." */ )
f1(g0 /* ERROR "used as value" */ ())
f1(g1())
// f1(g2()) // TODO(gri) missing position in error message
f2 /* ERROR "too few arguments" */ ()
f2 /* ERROR "too few arguments" */ (3.14)
f2(3.14, "foo")
f2(x /* ERROR "cannot assign" */ , "foo")
f2(g0 /* ERROR "used as value" */ ())
f2 /* ERROR "too few arguments" */ (g1 /* ERROR "cannot assign" */ ())
f2(g2())
fs /* ERROR "too few arguments" */ ()
fs(g0 /* ERROR "used as value" */ ())
fs(g1 /* ERROR "cannot assign" */ ())
// fs(g2()) // TODO(gri) missing position in error message
fs(gs())
fv()
fv(1, 2.0, x)
fv(s /* ERROR "cannot assign" */ )
fv(s...)
fv(1, s /* ERROR "can only use ... with matching parameter" */ ...)
fv(gs /* ERROR "cannot assign" */ ())
fv(gs /* ERROR "cannot assign" */ ()...)
fi()
fi(1, 2.0, x, 3.14, "foo")
fi(g2())
fi(0, g2)
fi(0, g2 /* ERROR "2-valued expression" */ ())
}

View File

@ -1,274 +0,0 @@
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// statements
package stmt0
func _() {
b, i, f, c, s := false, 1, 1.0, 1i, "foo"
b = i /* ERROR "cannot assign" */
i = f /* ERROR "cannot assign" */
f = c /* ERROR "cannot assign" */
c = s /* ERROR "cannot assign" */
s = b /* ERROR "cannot assign" */
v0 /* ERROR "mismatch" */, v1, v2 := 1, 2, 3, 4
b = true
i += 1
i += "foo" /* ERROR "cannot convert.*int" */
f -= 1
f -= "foo" /* ERROR "cannot convert.*float64" */
c *= 1
c /= 0 /* ERROR "division by zero" */
s += "bar"
s += 1 /* ERROR "cannot convert.*string" */
}
func _incdecs() {
const c = 3.14
c /* ERROR "cannot assign" */ ++
s := "foo"
s /* ERROR "cannot convert" */ --
3.14 /* ERROR "cannot assign" */ ++
var (
x int
y float32
z complex128
)
x++
y--
z++
}
func _sends() {
var ch chan int
var rch <-chan int
var x int
x /* ERROR "cannot send" */ <- x
rch /* ERROR "cannot send" */ <- x
ch /* ERROR "cannot send" */ <- "foo"
ch <- x
}
func _selects() {
select {}
var (
ch chan int
sc chan <- bool
x int
)
select {
case <-ch:
ch <- x
case t, ok := <-ch:
x = t
case <-sc /* ERROR "cannot receive from send-only channel" */ :
}
select {
default:
default /* ERROR "multiple defaults" */ :
}
}
func _gos() {
go 1 /* ERROR "expected function/method call" */
go _gos()
var c chan int
go close(c)
go len(c) // TODO(gri) this should not be legal
}
func _defers() {
defer 1 /* ERROR "expected function/method call" */
defer _defers()
var c chan int
defer close(c)
defer len(c) // TODO(gri) this should not be legal
}
func _switches() {
var x int
switch x {
default:
default /* ERROR "multiple defaults" */ :
}
switch {
case 1 /* ERROR "cannot convert" */ :
}
switch int32(x) {
case 1, 2:
case x /* ERROR "cannot compare" */ :
}
switch x {
case 1 /* ERROR "overflows int" */ << 100:
}
switch x {
case 1:
case 1 /* ERROR "duplicate case" */ :
case 2, 3, 4:
case 1 /* ERROR "duplicate case" */ :
}
// TODO(gri) duplicate 64bit values that don't fit into an int64 are not yet detected
switch uint64(x) {
case 1<<64-1:
case 1<<64-1:
}
}
type I interface {
m()
}
type I2 interface {
m(int)
}
type T struct{}
type T1 struct{}
type T2 struct{}
func (T) m() {}
func (T2) m(int) {}
func _typeswitches() {
var i int
var x interface{}
switch x.(type) {}
switch (x /* ERROR "outside type switch" */ .(type)) {}
switch x.(type) {
default:
default /* ERROR "multiple defaults" */ :
}
switch x := x.(type) {}
switch x := x.(type) {
case int:
var y int = x
}
switch x := i /* ERROR "not an interface" */ .(type) {}
switch t := x.(type) {
case nil:
var v bool = t /* ERROR "cannot assign" */
case int:
var v int = t
case float32, complex64:
var v float32 = t /* ERROR "cannot assign" */
default:
var v float32 = t /* ERROR "cannot assign" */
}
var t I
switch t.(type) {
case T:
case T1 /* ERROR "missing method m" */ :
case T2 /* ERROR "wrong type for method m" */ :
case I2 /* ERROR "wrong type for method m" */ :
}
}
func _rangeloops() {
var (
x int
a [10]float32
b []string
p *[10]complex128
pp **[10]complex128
s string
m map[int]bool
c chan int
sc chan<- int
rc <-chan int
)
for _ = range x /* ERROR "cannot range over" */ {}
for i := range x /* ERROR "cannot range over" */ {}
for i := range a {
var ii int
ii = i
}
for i, x := range a {
var ii int
ii = i
var xx float64
xx = x /* ERROR "cannot assign" */
}
var ii int
var xx float32
for ii, xx := range a {}
for i := range b {
var ii int
ii = i
}
for i, x := range b {
var ii int
ii = i
var xx string
xx = x
}
for i := range s {
var ii int
ii = i
}
for i, x := range s {
var ii int
ii = i
var xx rune
xx = x
}
for _, x := range p {
var xx complex128
xx = x
}
for _, x := range pp /* ERROR "cannot range over" */ {}
for k := range m {
var kk int32
kk = k /* ERROR "cannot assign" */
}
for k, v := range m {
var kk int
kk = k
if v {}
}
for _, _ /* ERROR "only one iteration variable" */ = range c {}
for e := range c {
var ee int
ee = e
}
for _ = range sc /* ERROR "cannot range over send-only channel" */ {}
for _ = range rc {}
// constant strings
const cs = "foo"
for i, x := range cs {}
for i, x := range "" {
var ii int
ii = i
var xx rune
xx = x
}
}

View File

@ -887,7 +887,7 @@ func (z *Int) AndNot(x, y *Int) *Int {
}
// x &^ (-y) == x &^ ^(y-1) == x & (y-1)
y1 := nat(nil).add(y.abs, natOne)
y1 := nat(nil).sub(y.abs, natOne)
z.abs = z.abs.and(x.abs, y1)
z.neg = false
return z

View File

@ -1201,6 +1201,7 @@ var bitwiseTests = []struct {
{"-0x01", "-0x01", "-0x01", "-0x01", "0x00", "0x00"},
{"0x07", "0x08", "0x00", "0x0f", "0x0f", "0x07"},
{"0x05", "0x0f", "0x05", "0x0f", "0x0a", "0x00"},
{"0xff", "-0x0a", "0xf6", "-0x01", "-0xf7", "0x09"},
{"0x013ff6", "0x9a4e", "0x1a46", "0x01bffe", "0x01a5b8", "0x0125b0"},
{"-0x013ff6", "0x9a4e", "0x800a", "-0x0125b2", "-0x01a5bc", "-0x01c000"},
{"-0x013ff6", "-0x9a4e", "-0x01bffe", "-0x1a46", "0x01a5b8", "0x8008"},

View File

@ -248,12 +248,12 @@ const (
// with a unique tag like `reflect:"array"` or `reflect:"ptr"`
// so that code cannot convert from, say, *arrayType to *ptrType.
type rtype struct {
kind uint8 // enumeration for C
align int8 // alignment of variable with this type
fieldAlign uint8 // alignment of struct field with this type
_ uint8 // unused/padding
kind uint8 // enumeration for C
align int8 // alignment of variable with this type
fieldAlign uint8 // alignment of struct field with this type
_ uint8 // unused/padding
size uintptr
hash uint32 // hash of type; avoids computation in hash tables
hash uint32 // hash of type; avoids computation in hash tables
hashfn uintptr // hash function code
equalfn uintptr // equality function code
@ -1582,8 +1582,9 @@ func MapOf(key, elem Type) Type {
// gcProg is a helper type for generatation of GC pointer info.
type gcProg struct {
gc []byte
size uintptr // size of type in bytes
gc []byte
size uintptr // size of type in bytes
hasPtr bool
}
func (gc *gcProg) append(v byte) {
@ -1644,11 +1645,14 @@ func (gc *gcProg) appendWord(v byte) {
gc.gc[nptr/2] &= ^(3 << ((nptr%2)*4 + 2))
gc.gc[nptr/2] |= v << ((nptr%2)*4 + 2)
gc.size += ptrsize
if v == bitsPointer {
gc.hasPtr = true
}
}
func (gc *gcProg) finalize() unsafe.Pointer {
func (gc *gcProg) finalize() (unsafe.Pointer, bool) {
if gc.size == 0 {
return nil
return nil, false
}
ptrsize := unsafe.Sizeof(uintptr(0))
gc.align(ptrsize)
@ -1663,7 +1667,7 @@ func (gc *gcProg) finalize() unsafe.Pointer {
gc.appendWord(extractGCWord(gc.gc, i))
}
}
return unsafe.Pointer(&gc.gc[0])
return unsafe.Pointer(&gc.gc[0]), gc.hasPtr
}
func extractGCWord(gc []byte, i uintptr) byte {
@ -1708,10 +1712,6 @@ func bucketOf(ktyp, etyp *rtype) *rtype {
for i := 0; i < int(bucketSize*unsafe.Sizeof(uint8(0))/ptrsize); i++ {
gc.append(bitsScalar)
}
gc.append(bitsPointer) // overflow
if runtime.GOARCH == "amd64p32" {
gc.append(bitsScalar)
}
// keys
for i := 0; i < bucketSize; i++ {
gc.appendProg(ktyp)
@ -1720,10 +1720,15 @@ func bucketOf(ktyp, etyp *rtype) *rtype {
for i := 0; i < bucketSize; i++ {
gc.appendProg(etyp)
}
// overflow
gc.append(bitsPointer)
if runtime.GOARCH == "amd64p32" {
gc.append(bitsScalar)
}
b := new(rtype)
b.size = gc.size
// b.gc[0] = gc.finalize()
// b.gc[0], _ = gc.finalize()
b.kind |= kindGCProg
s := "bucket(" + *ktyp.string + "," + *etyp.string + ")"
b.string = &s

View File

@ -202,6 +202,11 @@ func TestNonblockRecvRace(t *testing.T) {
n := 10000
if testing.Short() {
n = 100
} else {
if runtime.GOARCH == "s390" {
// Test uses too much address space on 31-bit S390.
t.Skip("skipping long test on s390")
}
}
for i := 0; i < n; i++ {
c := make(chan int, 1)

View File

@ -7,6 +7,7 @@
package runtime_test
import (
"os/exec"
"runtime"
"strings"
"testing"
@ -50,6 +51,30 @@ func TestCgoExternalThreadPanic(t *testing.T) {
}
}
func TestCgoExternalThreadSIGPROF(t *testing.T) {
// issue 9456.
switch runtime.GOOS {
case "plan9", "windows":
t.Skipf("no pthreads on %s", runtime.GOOS)
case "darwin":
// static constructor needs external linking, but we don't support
// external linking on OS X 10.6.
out, err := exec.Command("uname", "-r").Output()
if err != nil {
t.Fatalf("uname -r failed: %v", err)
}
// OS X 10.6 == Darwin 10.x
if strings.HasPrefix(string(out), "10.") {
t.Skipf("no external linking on OS X 10.6")
}
}
got := executeTest(t, cgoExternalThreadSIGPROFSource, nil)
want := "OK\n"
if got != want {
t.Fatalf("expected %q, but got %q", want, got)
}
}
const cgoSignalDeadlockSource = `
package main
@ -194,3 +219,46 @@ start(void)
printf("_beginthreadex failed\n");
}
`
const cgoExternalThreadSIGPROFSource = `
package main
/*
#include <stdint.h>
#include <signal.h>
#include <pthread.h>
volatile int32_t spinlock;
static void *thread1(void *p) {
(void)p;
while (spinlock == 0)
;
pthread_kill(pthread_self(), SIGPROF);
spinlock = 0;
return NULL;
}
__attribute__((constructor)) void issue9456() {
pthread_t tid;
pthread_create(&tid, 0, thread1, NULL);
}
*/
import "C"
import (
"runtime"
"sync/atomic"
"unsafe"
)
func main() {
// This test intends to test that sending SIGPROF to foreign threads
// before we make any cgo call will not abort the whole process, so
// we cannot make any cgo call here. See http://golang.org/issue/9456.
atomic.StoreInt32((*int32)(unsafe.Pointer(&C.spinlock)), 1)
for atomic.LoadInt32((*int32)(unsafe.Pointer(&C.spinlock))) == 1 {
runtime.Gosched()
}
println("OK")
}
`

View File

@ -39,6 +39,10 @@ a comma-separated list of name=val pairs. Supported names are:
gcdead: setting gcdead=1 causes the garbage collector to clobber all stack slots
that it thinks are dead.
memprofilerate: setting memprofilerate=X changes the setting for
runtime.MemProfileRate. Refer to the description of this variable for how
it is used and its default value.
scheddetail: setting schedtrace=X and scheddetail=1 causes the scheduler to emit
detailed multiline info every X milliseconds, describing state of the scheduler,
processors, threads and goroutines.

View File

@ -117,12 +117,12 @@ type hmap struct {
// A bucket for a Go map.
type bmap struct {
tophash [bucketCnt]uint8
overflow *bmap
tophash [bucketCnt]uint8
// Followed by bucketCnt keys and then bucketCnt values.
// NOTE: packing all the keys together and then all the values together makes the
// code a bit more complicated than alternating key/value/key/value/... but it allows
// us to eliminate padding which would be needed for, e.g., map[int64]int8.
// Followed by an overflow pointer.
}
// A hash iteration structure.
@ -149,6 +149,13 @@ func evacuated(b *bmap) bool {
return h > empty && h < minTopHash
}
func (b *bmap) overflow(t *maptype) *bmap {
return *(**bmap)(add(unsafe.Pointer(b), uintptr(t.bucketsize)-regSize))
}
func (b *bmap) setoverflow(t *maptype, ovf *bmap) {
*(**bmap)(add(unsafe.Pointer(b), uintptr(t.bucketsize)-regSize)) = ovf
}
func makemap(t *maptype, hint int64) *hmap {
if sz := unsafe.Sizeof(hmap{}); sz > 48 || sz != uintptr(t.hmap.size) {
gothrow("bad hmap size")
@ -275,7 +282,7 @@ func mapaccess1(t *maptype, h *hmap, key unsafe.Pointer) unsafe.Pointer {
return v
}
}
b = b.overflow
b = b.overflow(t)
if b == nil {
return unsafe.Pointer(t.elem.zero)
}
@ -323,7 +330,7 @@ func mapaccess2(t *maptype, h *hmap, key unsafe.Pointer) (unsafe.Pointer, bool)
return v, true
}
}
b = b.overflow
b = b.overflow(t)
if b == nil {
return unsafe.Pointer(t.elem.zero), false
}
@ -366,7 +373,7 @@ func mapaccessK(t *maptype, h *hmap, key unsafe.Pointer) (unsafe.Pointer, unsafe
return k, v
}
}
b = b.overflow
b = b.overflow(t)
if b == nil {
return nil, nil
}
@ -437,10 +444,11 @@ again:
memmove(v2, val, uintptr(t.elem.size))
return
}
if b.overflow == nil {
ovf := b.overflow(t)
if ovf == nil {
break
}
b = b.overflow
b = ovf
}
// did not find mapping for key. Allocate new cell & add entry.
@ -455,7 +463,7 @@ again:
memstats.next_gc = memstats.heap_alloc
}
newb := (*bmap)(newobject(t.bucket))
b.overflow = newb
b.setoverflow(t, newb)
inserti = &newb.tophash[0]
insertk = add(unsafe.Pointer(newb), dataOffset)
insertv = add(insertk, bucketCnt*uintptr(t.keysize))
@ -525,7 +533,7 @@ func mapdelete(t *maptype, h *hmap, key unsafe.Pointer) {
h.count--
return
}
b = b.overflow
b = b.overflow(t)
if b == nil {
return
}
@ -720,7 +728,7 @@ next:
return
}
}
b = b.overflow
b = b.overflow(t)
i = 0
goto next
}
@ -778,7 +786,7 @@ func evacuate(t *maptype, h *hmap, oldbucket uintptr) {
yk := add(unsafe.Pointer(y), dataOffset)
xv := add(xk, bucketCnt*uintptr(t.keysize))
yv := add(yk, bucketCnt*uintptr(t.keysize))
for ; b != nil; b = b.overflow {
for ; b != nil; b = b.overflow(t) {
k := add(unsafe.Pointer(b), dataOffset)
v := add(k, bucketCnt*uintptr(t.keysize))
for i := 0; i < bucketCnt; i, k, v = i+1, add(k, uintptr(t.keysize)), add(v, uintptr(t.valuesize)) {
@ -828,7 +836,7 @@ func evacuate(t *maptype, h *hmap, oldbucket uintptr) {
memstats.next_gc = memstats.heap_alloc
}
newx := (*bmap)(newobject(t.bucket))
x.overflow = newx
x.setoverflow(t, newx)
x = newx
xi = 0
xk = add(unsafe.Pointer(x), dataOffset)
@ -855,7 +863,7 @@ func evacuate(t *maptype, h *hmap, oldbucket uintptr) {
memstats.next_gc = memstats.heap_alloc
}
newy := (*bmap)(newobject(t.bucket))
y.overflow = newy
y.setoverflow(t, newy)
y = newy
yi = 0
yk = add(unsafe.Pointer(y), dataOffset)
@ -881,7 +889,6 @@ func evacuate(t *maptype, h *hmap, oldbucket uintptr) {
// Unlink the overflow buckets & clear key/value to help GC.
if h.flags&oldIterator == 0 {
b = (*bmap)(add(h.oldbuckets, oldbucket*uintptr(t.bucketsize)))
b.overflow = nil
memclr(add(unsafe.Pointer(b), dataOffset), uintptr(t.bucketsize)-dataOffset)
}
}

View File

@ -43,7 +43,7 @@ func mapaccess1_fast32(t *maptype, h *hmap, key uint32) unsafe.Pointer {
}
return add(unsafe.Pointer(b), dataOffset+bucketCnt*4+i*uintptr(t.valuesize))
}
b = b.overflow
b = b.overflow(t)
if b == nil {
return unsafe.Pointer(t.elem.zero)
}
@ -85,7 +85,7 @@ func mapaccess2_fast32(t *maptype, h *hmap, key uint32) (unsafe.Pointer, bool) {
}
return add(unsafe.Pointer(b), dataOffset+bucketCnt*4+i*uintptr(t.valuesize)), true
}
b = b.overflow
b = b.overflow(t)
if b == nil {
return unsafe.Pointer(t.elem.zero), false
}
@ -127,7 +127,7 @@ func mapaccess1_fast64(t *maptype, h *hmap, key uint64) unsafe.Pointer {
}
return add(unsafe.Pointer(b), dataOffset+bucketCnt*8+i*uintptr(t.valuesize))
}
b = b.overflow
b = b.overflow(t)
if b == nil {
return unsafe.Pointer(t.elem.zero)
}
@ -169,7 +169,7 @@ func mapaccess2_fast64(t *maptype, h *hmap, key uint64) (unsafe.Pointer, bool) {
}
return add(unsafe.Pointer(b), dataOffset+bucketCnt*8+i*uintptr(t.valuesize)), true
}
b = b.overflow
b = b.overflow(t)
if b == nil {
return unsafe.Pointer(t.elem.zero), false
}
@ -271,7 +271,7 @@ dohash:
return add(unsafe.Pointer(b), dataOffset+bucketCnt*2*ptrSize+i*uintptr(t.valuesize))
}
}
b = b.overflow
b = b.overflow(t)
if b == nil {
return unsafe.Pointer(t.elem.zero)
}
@ -371,7 +371,7 @@ dohash:
return add(unsafe.Pointer(b), dataOffset+bucketCnt*2*ptrSize+i*uintptr(t.valuesize)), true
}
}
b = b.overflow
b = b.overflow(t)
if b == nil {
return unsafe.Pointer(t.elem.zero), false
}

View File

@ -243,7 +243,12 @@ func TestIterGrowWithGC(t *testing.T) {
func testConcurrentReadsAfterGrowth(t *testing.T, useReflect bool) {
if runtime.GOMAXPROCS(-1) == 1 {
defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(16))
if runtime.GOARCH == "s390" {
// Test uses too much address space on 31-bit S390.
defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(8))
} else {
defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(16))
}
}
numLoop := 10
numGrowStep := 250

View File

@ -24,6 +24,9 @@ func TestFinalizerType(t *testing.T) {
if runtime.GOARCH != "amd64" {
t.Skipf("Skipping on non-amd64 machine")
}
if runtime.Compiler == "gccgo" {
t.Skip("skipping for gccgo")
}
ch := make(chan bool, 10)
finalize := func(x *int) {
@ -81,6 +84,9 @@ func TestFinalizerInterfaceBig(t *testing.T) {
if runtime.GOARCH != "amd64" {
t.Skipf("Skipping on non-amd64 machine")
}
if runtime.Compiler == "gccgo" {
t.Skip("skipping for gccgo")
}
ch := make(chan bool)
done := make(chan bool, 1)
go func() {
@ -175,6 +181,9 @@ func TestEmptySlice(t *testing.T) {
if true { // disable until bug 7564 is fixed.
return
}
if runtime.Compiler == "gccgo" {
t.Skip("skipping for gccgo")
}
x, y := adjChunks()
// the pointer inside xs points to y.

View File

@ -575,20 +575,16 @@ func saveg(pc, sp uintptr, gp *g, r *StackRecord) {
// If all is true, Stack formats stack traces of all other goroutines
// into buf after the trace for the current goroutine.
func Stack(buf []byte, all bool) int {
mp := acquirem()
gp := mp.curg
if all {
semacquire(&worldsema, false)
mp.gcing = 1
releasem(mp)
gp := getg()
gp.m.gcing = 1
onM(stoptheworld)
if mp != acquirem() {
gothrow("Stack: rescheduled")
}
}
n := 0
if len(buf) > 0 {
gp := getg()
sp := getcallersp(unsafe.Pointer(&buf))
pc := getcallerpc(unsafe.Pointer(&buf))
onM(func() {
@ -605,11 +601,11 @@ func Stack(buf []byte, all bool) int {
}
if all {
mp.gcing = 0
gp := getg()
gp.m.gcing = 0
semrelease(&worldsema)
onM(starttheworld)
}
releasem(mp)
return n
}

View File

@ -6,6 +6,8 @@ package runtime
import "unsafe"
const _SIGPROF = 0 // dummy value for badsignal
func pread(fd int32, buf unsafe.Pointer, nbytes int32, offset int64) int32
func pwrite(fd int32, buf unsafe.Pointer, nbytes int32, offset int64) int32
func seek(fd int32, offset int64, whence int32) int64

View File

@ -85,10 +85,12 @@ func TestMemoryProfiler(t *testing.T) {
# 0x[0-9,a-f]+ runtime_pprof_test\.TestMemoryProfiler\+0x[0-9,a-f]+ .*/mprof_test.go:64
`, (1<<10)*memoryProfilerRun, (1<<20)*memoryProfilerRun),
fmt.Sprintf(`0: 0 \[%v: %v\] @ 0x[0-9,a-f x]+
// This should start with "0: 0" but gccgo's imprecise
// GC means that sometimes the value is not collected.
fmt.Sprintf(`(0|%v): (0|%v) \[%v: %v\] @ 0x[0-9,a-f x]+
# 0x[0-9,a-f]+ pprof_test\.allocateTransient2M\+0x[0-9,a-f]+ .*/mprof_test.go:30
# 0x[0-9,a-f]+ runtime_pprof_test\.TestMemoryProfiler\+0x[0-9,a-f]+ .*/mprof_test.go:65
`, memoryProfilerRun, (2<<20)*memoryProfilerRun),
`, memoryProfilerRun, (2<<20)*memoryProfilerRun, memoryProfilerRun, (2<<20)*memoryProfilerRun),
}
for _, test := range tests {

View File

@ -154,6 +154,15 @@ func signal_disable(s uint32) {
// This runs on a foreign stack, without an m or a g. No stack split.
//go:nosplit
func badsignal(sig uintptr) {
// Some external libraries, for example, OpenBLAS, create worker threads in
// a global constructor. If we're doing cpu profiling, and the SIGPROF signal
// comes to one of the foreign threads before we make our first cgo call, the
// call to cgocallback below will bring down the whole process.
// It's better to miss a few SIGPROF signals than to abort in this case.
// See http://golang.org/issue/9456.
if _SIGPROF != 0 && sig == _SIGPROF && needextram != 0 {
return
}
cgocallback(unsafe.Pointer(funcPC(sigsend)), noescape(unsafe.Pointer(&sig)), unsafe.Sizeof(sig))
}

View File

@ -8,6 +8,8 @@ import (
"unsafe"
)
const _SIGPROF = 0 // dummy value for badsignal
type callbacks struct {
lock mutex
ctxt [cb_max]*wincallbackcontext
@ -52,11 +54,13 @@ func compileCallback(fn eface, cleanstack bool) (code uintptr) {
panic("compilecallback: output parameter size is wrong")
}
argsize := uintptr(0)
for _, t := range (*[1024](*_type))(unsafe.Pointer(&ft.in[0]))[:len(ft.in)] {
if (*t).size > uintptrSize {
panic("compilecallback: input parameter size is wrong")
if len(ft.in) > 0 {
for _, t := range (*[1024](*_type))(unsafe.Pointer(&ft.in[0]))[:len(ft.in)] {
if (*t).size > uintptrSize {
panic("compilecallback: input parameter size is wrong")
}
argsize += uintptrSize
}
argsize += uintptrSize
}
lock(&cbs.lock)

View File

@ -226,6 +226,7 @@ func forkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err error)
// Kick off child.
pid, err1 = forkAndExecInChild(argv0p, argvp, envvp, chroot, dir, attr, sys, p[1])
if err1 != 0 {
err = Errno(err1)
goto error
}
ForkLock.Unlock()

View File

@ -12,16 +12,16 @@ func (any *anyMessage) toRoutingMessage(b []byte) RoutingMessage {
switch any.Type {
case RTM_ADD, RTM_DELETE, RTM_CHANGE, RTM_GET, RTM_LOSING, RTM_REDIRECT, RTM_MISS, RTM_LOCK, RTM_RESOLVE:
p := (*RouteMessage)(unsafe.Pointer(any))
return &RouteMessage{Header: p.Header, Data: b[SizeofRtMsghdr:any.Msglen]}
return &RouteMessage{Header: p.Header, Data: b[p.Header.Hdrlen:any.Msglen]}
case RTM_IFINFO:
p := (*InterfaceMessage)(unsafe.Pointer(any))
return &InterfaceMessage{Header: p.Header, Data: b[SizeofIfMsghdr:any.Msglen]}
return &InterfaceMessage{Header: p.Header, Data: b[p.Header.Hdrlen:any.Msglen]}
case RTM_IFANNOUNCE:
p := (*InterfaceAnnounceMessage)(unsafe.Pointer(any))
return &InterfaceAnnounceMessage{Header: p.Header}
case RTM_NEWADDR, RTM_DELADDR:
p := (*InterfaceAddrMessage)(unsafe.Pointer(any))
return &InterfaceAddrMessage{Header: p.Header, Data: b[SizeofIfaMsghdr:any.Msglen]}
return &InterfaceAddrMessage{Header: p.Header, Data: b[p.Header.Hdrlen:any.Msglen]}
}
return nil
}

View File

@ -40,12 +40,14 @@ repository=$1
old_rev=`sed 1q MERGE`
rm -rf ${OLDDIR}
hg clone -r ${old_rev} ${repository} ${OLDDIR}
git clone ${repository} ${OLDDIR}
(cd ${OLDDIR} && git checkout ${old_rev})
rm -rf ${NEWDIR}
hg clone -u ${rev} ${repository} ${NEWDIR}
git clone ${repository} ${NEWDIR}
(cd ${NEWDIR} && git checkout ${rev})
new_rev=`cd ${NEWDIR} && hg log -r ${rev} | sed 1q | sed -e 's/.*://'`
new_rev=`cd ${NEWDIR} && git log | sed 1q | sed -e 's/commit //'`
merge() {
name=$1
@ -69,7 +71,7 @@ merge() {
elif test -f ${old}; then
# The file exists in the old version.
if ! test -f ${libgo}; then
echo "merge.sh: $name: skipping: exists in old and new hg, but not in libgo"
echo "merge.sh: $name: skipping: exists in old and new git, but not in libgo"
continue
fi
if cmp -s ${old} ${libgo}; then
@ -136,6 +138,16 @@ merge_c() {
fi
}
if test -f VERSION; then
if ! cmp -s ${NEWDIR}/VERSION VERSION; then
cp ${NEWDIR}/VERSION .
fi
else
if test -f ${NEWDIR}/VERSION; then
cp ${NEWDIR}/VERSION .
fi
fi
(cd ${NEWDIR}/src && find . -name '*.go' -print) | while read f; do
oldfile=${OLDDIR}/src/$f
newfile=${NEWDIR}/src/$f
@ -150,11 +162,10 @@ done
if ! test -d ${oldtd}; then
continue
fi
(cd ${oldtd} && hg status -A .) | while read f; do
if test "`basename $f`" = ".hgignore"; then
(cd ${oldtd} && git ls-files .) | while read f; do
if test "`basename $f`" = ".gitignore"; then
continue
fi
f=`echo $f | sed -e 's/^..//'`
name=$d/$f
oldfile=${oldtd}/$f
newfile=${newtd}/$f
@ -179,11 +190,10 @@ for c in $cmdlist; do
if ! test -d ${oldtd}; then
continue
fi
(cd ${oldtd} && hg status -A .) | while read f; do
if test "`basename $f`" = ".hgignore"; then
(cd ${oldtd} && git ls-files .) | while read f; do
if test "`basename $f`" = ".gitignore"; then
continue
fi
f=`echo $f | sed -e 's/^..//'`
name=$d/$f
oldfile=${oldtd}/$f
newfile=${newtd}/$f

View File

@ -1240,11 +1240,6 @@ grep '^type _inotify_event ' gen-sysinfo.go | \
grep '^const _CLONE_' gen-sysinfo.go | \
sed -e 's/^\(const \)_\(CLONE_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
# The Solaris 11 Update 1 _zone_net_addr_t struct.
grep '^type _zone_net_addr_t ' gen-sysinfo.go | \
sed -e 's/_in6_addr/[16]byte/' \
>> ${OUT}
# Struct sizes.
set cmsghdr Cmsghdr ip_mreq IPMreq ip_mreqn IPMreqn ipv6_mreq IPv6Mreq \
ifaddrmsg IfAddrmsg ifinfomsg IfInfomsg in_pktinfo Inet4Pktinfo \

View File

@ -37,36 +37,12 @@ callback (void *data, uintptr_t pc __attribute__ ((unused)),
{
struct caller *c = (struct caller *) data;
if (function == NULL)
{
c->fn.str = NULL;
c->fn.len = 0;
}
else
{
byte *s;
c->fn.len = __builtin_strlen (function);
s = runtime_malloc (c->fn.len);
__builtin_memcpy (s, function, c->fn.len);
c->fn.str = s;
}
if (filename == NULL)
{
c->file.str = NULL;
c->file.len = 0;
}
else
{
byte *s;
c->file.len = __builtin_strlen (filename);
s = runtime_malloc (c->file.len);
__builtin_memcpy (s, filename, c->file.len);
c->file.str = s;
}
/* The libbacktrace library says that these strings might disappear,
but with the current implementation they won't. We can't easily
allocate memory here, so for now assume that we can save a
pointer to the strings. */
c->fn = runtime_gostringnocopy ((const byte *) function);
c->file = runtime_gostringnocopy ((const byte *) filename);
c->line = lineno;
return 0;

View File

@ -129,6 +129,11 @@ static void
error_callback (void *data __attribute__ ((unused)),
const char *msg, int errnum)
{
if (errnum == -1)
{
/* No debug info available. Carry on as best we can. */
return;
}
if (errnum != 0)
runtime_printf ("%s errno %d\n", msg, errnum);
runtime_throw (msg);

View File

@ -8,6 +8,7 @@
#include <stdlib.h>
#include "runtime.h"
#include "malloc.h"
#include "go-alloc.h"
#include "go-assert.h"
#include "map.h"
@ -63,7 +64,8 @@ __go_map_rehash (struct __go_map *map)
}
}
__go_free (old_buckets);
if (old_bucket_count * sizeof (void *) >= TinySize)
__go_free (old_buckets);
map->__bucket_count = new_bucket_count;
map->__buckets = new_buckets;

View File

@ -22,6 +22,10 @@ enum {
// gotraceback value.
static uint32 traceback_cache = ~(uint32)0;
extern volatile intgo runtime_MemProfileRate
__asm__ (GOSYM_PREFIX "runtime.MemProfileRate");
// The GOTRACEBACK environment variable controls the
// behavior of a Go program that is crashing and exiting.
// GOTRACEBACK=0 suppress all tracebacks
@ -315,6 +319,11 @@ runtime_signalstack(byte *p, int32 n)
DebugVars runtime_debug;
// Holds variables parsed from GODEBUG env var,
// except for "memprofilerate" since there is an
// existing var for that value which is int
// instead of in32 and might have an
// initial value.
static struct {
const char* name;
int32* value;
@ -349,7 +358,12 @@ runtime_parsedebugvars(void)
for(;;) {
for(i=0; i<(intgo)nelem(dbgvar); i++) {
n = runtime_findnull((const byte*)dbgvar[i].name);
if(runtime_mcmp(p, dbgvar[i].name, n) == 0 && p[n] == '=')
if(runtime_mcmp(p, "memprofilerate", n) == 0 && p[n] == '=')
// Set the MemProfileRate directly since it
// is an int, not int32, and should only lbe
// set here if specified by GODEBUG
runtime_MemProfileRate = runtime_atoi(p+n+1);
else if(runtime_mcmp(p, dbgvar[i].name, n) == 0 && p[n] == '=')
*dbgvar[i].value = runtime_atoi(p+n+1);
}
p = (const byte *)runtime_strstr((const char *)p, ",");

View File

@ -1,7 +1,7 @@
#!/bin/sh -e
gofrontendrepo=https://code.google.com/p/gofrontend
gofrontendrev=07baa07598ea
gofrontendrev=15a24202fa42
gccrepo=svn://gcc.gnu.org/svn/gcc/trunk
gccrev=219477