mirror of https://github.com/golang/go.git
cmd/compile: correct wasmexport result type checking
The function resultsToWasmFields was originally for only wasmimport. I adopted it for wasmexport as well, but forgot to update a few places that were wasmimport-specific. This leads to compiler panic if an invalid result type is passed, and also unsafe.Pointer not actually supported. This CL fixes it. Updates #65199. Change-Id: I9bbd7154b70422504994840ff541c39ee596ee8f Reviewed-on: https://go-review.googlesource.com/c/go/+/611315 Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Achille Roussel <achille.roussel@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
69827b5c8d
commit
eb975601a0
|
|
@ -451,8 +451,10 @@ func resultsToWasmFields(f *ir.Func, pragma string, result *abi.ABIParamResultIn
|
||||||
wfs[i].Type = obj.WasmF32
|
wfs[i].Type = obj.WasmF32
|
||||||
case types.TFLOAT64:
|
case types.TFLOAT64:
|
||||||
wfs[i].Type = obj.WasmF64
|
wfs[i].Type = obj.WasmF64
|
||||||
|
case types.TUNSAFEPTR:
|
||||||
|
wfs[i].Type = obj.WasmPtr
|
||||||
default:
|
default:
|
||||||
base.ErrorfAt(f.Pos(), 0, "go:wasmimport %s %s: unsupported result type %s", f.WasmImport.Module, f.WasmImport.Name, t.String())
|
base.ErrorfAt(f.Pos(), 0, "%s: unsupported result type %s", pragma, t.String())
|
||||||
}
|
}
|
||||||
wfs[i].Offset = p.FrameOffset(result)
|
wfs[i].Offset = p.FrameOffset(result)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,9 @@ func good2(MyInt32) {} // named type is ok
|
||||||
//go:wasmexport good3
|
//go:wasmexport good3
|
||||||
func good3() int32 { return 0 } // one result is ok
|
func good3() int32 { return 0 } // one result is ok
|
||||||
|
|
||||||
|
//go:wasmexport good4
|
||||||
|
func good4() unsafe.Pointer { return nil } // one result is ok
|
||||||
|
|
||||||
//go:wasmexport bad1
|
//go:wasmexport bad1
|
||||||
func bad1(string) {} // ERROR "go:wasmexport: unsupported parameter type"
|
func bad1(string) {} // ERROR "go:wasmexport: unsupported parameter type"
|
||||||
|
|
||||||
|
|
@ -54,5 +57,11 @@ func bad7(*S) {} // ERROR "go:wasmexport: unsupported parameter type"
|
||||||
//go:wasmexport bad8
|
//go:wasmexport bad8
|
||||||
func bad8([4]int32) {} // ERROR "go:wasmexport: unsupported parameter type"
|
func bad8([4]int32) {} // ERROR "go:wasmexport: unsupported parameter type"
|
||||||
|
|
||||||
|
//go:wasmexport bad9
|
||||||
|
func bad9() bool { return false } // ERROR "go:wasmexport: unsupported result type"
|
||||||
|
|
||||||
|
//go:wasmexport bad10
|
||||||
|
func bad10() *byte { return nil } // ERROR "go:wasmexport: unsupported result type"
|
||||||
|
|
||||||
//go:wasmexport toomanyresults
|
//go:wasmexport toomanyresults
|
||||||
func toomanyresults() (int32, int32) { return 0, 0 } // ERROR "go:wasmexport: too many return values"
|
func toomanyresults() (int32, int32) { return 0, 0 } // ERROR "go:wasmexport: too many return values"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue