compiler: fix passing weirdly-padded structs to new goroutines

The values were stored in the passed object as the values itself (not
expanded like is common in the calling convention), and read back after
assuming they were expanded. This often works for simple parameters
(int, pointer, etc), but not for more complex parameters. Especially
when there's padding.

Found this while working on `//go:wasmexport`.
This commit is contained in:
Ayke van Laethem
2024-08-31 13:25:42 +02:00
committed by Ron Evans
parent ee5bc65c97
commit d4cb92f27c
5 changed files with 28 additions and 15 deletions
+16
View File
@@ -86,6 +86,10 @@ func main() {
testCond()
testIssue1790()
done := make(chan int)
go testPaddedParameters(paddedStruct{x: 5, y: 7}, done)
<-done
}
func acquire(m *sync.Mutex) {
@@ -243,3 +247,15 @@ func (f Foo) Wait() {
time.Sleep(time.Microsecond)
println(" ...waited")
}
type paddedStruct struct {
x uint8
_ [0]int64
y uint8
}
// Structs with interesting padding used to crash.
func testPaddedParameters(s paddedStruct, done chan int) {
println("paddedStruct:", s.x, s.y)
close(done)
}
+1
View File
@@ -26,3 +26,4 @@ called: Foo.Nowait
called: Foo.Wait
...waited
done with 'go on interface'
paddedStruct: 5 7