<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/136594>136594</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Impossible to use `wasm:js-string` functions in webassembly
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          socketpair
      </td>
    </tr>
</table>

<pre>
    Here you can see an example of WASM code how to use `concat` JS builtin:

https://developer.mozilla.org/en-US/docs/WebAssembly/Guides/JavaScript_builtins#wasm_module

```wat
(func $concat (import "wasm:js-string" "concat")
    (param externref externref) (result (ref extern)))
```

So, in C I defined it in the following way:

```C
__externref_t js_concat(__externref_t, __externref_t) 
__attribute__((import_module("wasm:js-string"), import_name("concat")));
```

Next, I'm trying to run the code that uses definition above in the following way:

```js
const { instance } = await WebAssembly.instantiateStreaming(
  fetch('trie_search.wasm'),
  {
 env: {  },
  },
  {
      builtins: ["js-string"],
 importedStringConstants: "Something",
 },
);
instance.exports.my_function();
```

Browser console says:
```
Uncaught (in promise) CompileError: WebAssembly.instantiateStreaming():
Imported builtin function "wasm:js-string" "concat" has incorrect signature
```

I guess, the problem in return value. in WAT language it should look like `(ref extern)`. How to express it in C (Clang)?

https://github.com/WebAssembly/js-string-builtins/blob/main/proposals/js-string-builtins/Overview.md#wasmjs-string-concat
https://github.com/WebAssembly/function-references/blob/master/proposals/function-references/Overview.md#binary-format

```wat
(module
 (global $h (import "string_constants" "hello ") externref)
  (global $w (import "string_constants" "world!") externref)

  (func $concat (import "wasm:js-string" "concat")
    (param externref externref) (result (ref extern)))

  (func $log (import "m" "log") (param externref))
  (func (export "main")
    (call $log (call $concat (global.get $h) (global.get $w))))
)
```

Compiles perfectly well using `binryen`, but how to write an equivalent using C and clang ?

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzMVl-P6rYT_TT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