Skip to content

Commit eb97560

Browse files
committed
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 golang#65199. Change-Id: I9bbd7154b70422504994840ff541c39ee596ee8f Reviewed-on: https://go-review.googlesource.com/c/go/+/611315 Reviewed-by: Michael Knyszek <[email protected]> Reviewed-by: Achille Roussel <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 69827b5 commit eb97560

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/cmd/compile/internal/ssagen/abi.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,10 @@ func resultsToWasmFields(f *ir.Func, pragma string, result *abi.ABIParamResultIn
451451
wfs[i].Type = obj.WasmF32
452452
case types.TFLOAT64:
453453
wfs[i].Type = obj.WasmF64
454+
case types.TUNSAFEPTR:
455+
wfs[i].Type = obj.WasmPtr
454456
default:
455-
base.ErrorfAt(f.Pos(), 0, "go:wasmimport %s %s: unsupported result type %s", f.WasmImport.Module, f.WasmImport.Name, t.String())
457+
base.ErrorfAt(f.Pos(), 0, "%s: unsupported result type %s", pragma, t.String())
456458
}
457459
wfs[i].Offset = p.FrameOffset(result)
458460
}

test/wasmexport2.go

+9
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ func good2(MyInt32) {} // named type is ok
2424
//go:wasmexport good3
2525
func good3() int32 { return 0 } // one result is ok
2626

27+
//go:wasmexport good4
28+
func good4() unsafe.Pointer { return nil } // one result is ok
29+
2730
//go:wasmexport bad1
2831
func bad1(string) {} // ERROR "go:wasmexport: unsupported parameter type"
2932

@@ -54,5 +57,11 @@ func bad7(*S) {} // ERROR "go:wasmexport: unsupported parameter type"
5457
//go:wasmexport bad8
5558
func bad8([4]int32) {} // ERROR "go:wasmexport: unsupported parameter type"
5659

60+
//go:wasmexport bad9
61+
func bad9() bool { return false } // ERROR "go:wasmexport: unsupported result type"
62+
63+
//go:wasmexport bad10
64+
func bad10() *byte { return nil } // ERROR "go:wasmexport: unsupported result type"
65+
5766
//go:wasmexport toomanyresults
5867
func toomanyresults() (int32, int32) { return 0, 0 } // ERROR "go:wasmexport: too many return values"

0 commit comments

Comments
 (0)