Skip to content

transform (gc): GEP not pinned #1245

@lei-april

Description

@lei-april

The following code produces different results between the official Go compiler and Tinygo.

package main

const DataLen = 32

type Foo struct {
	data [DataLen]byte
}

func MakeFoo(from []byte) *Foo {
	foo := new(Foo)
	copy(foo.data[:], from)
	return foo
}

func main() {
	foo := MakeFoo([]byte("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))
	println(string(foo.data[:]))

	bar := MakeFoo([]byte("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"))
	println(string(bar.data[:]))
}

With official Go:

$ go run t.go
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb

With TinyGo:

$ tinygo build -o t t.go && ./t
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

If I change the field type of Foo from array to slice, then TinyGo produces the same result as official Go.

@@ -3,11 +3,12 @@ package main
 const DataLen = 32

 type Foo struct {
-   data [DataLen]byte
+   data []byte
 }

 func MakeFoo(from []byte) *Foo {
    foo := new(Foo)
+   foo.data = make([]byte, DataLen)
    copy(foo.data[:], from)
    return foo
 }

I'm not sure if there's something wrong with the code I posted, or it's a bug in TinyGo. Any idea?

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions