diff --git a/compiler/compiler.go b/compiler/compiler.go index aebea4c6c5..4c252d8dad 100644 --- a/compiler/compiler.go +++ b/compiler/compiler.go @@ -820,6 +820,9 @@ func (c *Compiler) parseFunc(frame *Frame) { if c.DumpSSA { fmt.Printf("\nfunc %s:\n", frame.fn.Function) } + if !frame.fn.LLVMFn.IsDeclaration() { + panic("function is already defined: " + frame.fn.LLVMFn.Name()) + } if !frame.fn.IsExported() { frame.fn.LLVMFn.SetLinkage(llvm.InternalLinkage) frame.fn.LLVMFn.SetUnnamedAddr(true) diff --git a/src/runtime/string.go b/src/runtime/string.go index 7050786176..780c97f4b6 100644 --- a/src/runtime/string.go +++ b/src/runtime/string.go @@ -166,9 +166,10 @@ func decodeUTF8(s string, index uintptr) (rune, uintptr) { } } -// indexByte returns the index of the first instance of c in s, or -1 if c is not present in s. -//go:linkname indexByte strings.IndexByte -func indexByte(s string, c byte) int { +// indexByteString returns the index of the first instance of c in s, or -1 if c +// is not present in s. +//go:linkname indexByteString internal/bytealg.IndexByteString +func indexByteString(s string, c byte) int { for i := 0; i < len(s); i++ { if s[i] == c { return i diff --git a/src/runtime/strings_go111.go b/src/runtime/strings_go111.go new file mode 100644 index 0000000000..b13ae7c088 --- /dev/null +++ b/src/runtime/strings_go111.go @@ -0,0 +1,12 @@ +// +build !go1.12 + +package runtime + +// indexByte provides compatibility with Go 1.11. +// See the following: +// https://github.com/tinygo-org/tinygo/issues/351 +// https://github.com/golang/go/commit/ad4a58e31501bce5de2aad90a620eaecdc1eecb8 +//go:linkname indexByte strings.IndexByte +func indexByte(s string, c byte) int { + return indexByteString(s, c) +} diff --git a/testdata/stdlib.go b/testdata/stdlib.go index 2996cdb296..a06a6cbf2f 100644 --- a/testdata/stdlib.go +++ b/testdata/stdlib.go @@ -4,12 +4,18 @@ import ( "fmt" "math/rand" "os" + "strings" ) func main() { + // package os, fmt fmt.Println("stdin: ", os.Stdin.Fd()) fmt.Println("stdout:", os.Stdout.Fd()) fmt.Println("stderr:", os.Stderr.Fd()) + // package math/rand fmt.Println("pseudorandom number:", rand.Int31()) + + // package strings + fmt.Println("strings.IndexByte:", strings.IndexByte("asdf", 'd')) } diff --git a/testdata/stdlib.txt b/testdata/stdlib.txt index 27f48238b0..aeef0388df 100644 --- a/testdata/stdlib.txt +++ b/testdata/stdlib.txt @@ -2,3 +2,4 @@ stdin: 0 stdout: 1 stderr: 2 pseudorandom number: 1298498081 +strings.IndexByte: 2