Skip to content

compiler: only support //go:wasmimport on declared functions #3610

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/symbol.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ func (info *functionInfo) parsePragmas(f *ssa.Function) {
case "//go:wasmimport":
// Import a WebAssembly function, for example a WASI function.
// For details, see: https://github.com/golang/go/issues/38248
if len(parts) != 3 {
if len(parts) != 3 || len(f.Blocks) != 0 {
continue
}
info.exported = true
Expand Down
7 changes: 7 additions & 0 deletions compiler/testdata/pragma.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ func functionInSection() {
func exportedFunctionInSection() {
}

//go:wasmimport modulename import1
func declaredImport()

//go:wasmimport modulename import2
func definedImport() {
}

// This function should not: it's only a declaration and not a definition.
//
//go:section .special_function_section
Expand Down
9 changes: 9 additions & 0 deletions compiler/testdata/pragma.ll
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ entry:
ret void
}

declare void @main.declaredImport() #7

; Function Attrs: nounwind
define hidden void @main.definedImport(ptr %context) unnamed_addr #2 {
entry:
ret void
}

declare void @main.undefinedFunctionNotInSection(ptr) #1

attributes #0 = { allockind("alloc,zeroed") allocsize(0) "alloc-family"="runtime.alloc" "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" }
Expand All @@ -69,3 +77,4 @@ attributes #3 = { nounwind "target-features"="+bulk-memory,+nontrapping-fptoint,
attributes #4 = { inlinehint nounwind "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" }
attributes #5 = { noinline nounwind "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" }
attributes #6 = { noinline nounwind "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" "wasm-export-name"="exportedFunctionInSection" "wasm-import-module"="env" "wasm-import-name"="exportedFunctionInSection" }
attributes #7 = { "target-features"="+bulk-memory,+nontrapping-fptoint,+sign-ext" "wasm-import-module"="modulename" "wasm-import-name"="import1" }