emscripten-core / emscripten-core/emscripten

Wasm table is not optimized away if not used

Open
#12,779 2 comments 0 reactions 0 assignees View on GitHub
wontfix
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

STR:

```
emcc tests\minimal_hello.c -o a.html -s MINIMAL_RUNTIME=1 -s ENVIRONMENT=web -s SUPPORT_ERRNO=0 -s MINIFY_HTML=0 -s TEXTDECODER=2 -O3 -g1 --closure 1 --profiling-funcs
```
generates
```wast
(module
(type $none_=>_none (func))
(type $i32_=>_none (func (param i32)))
(type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))
(import "a" "a" (memory $1 256 256))
(data (i32.const 1024) "(char* str)<::>{ console.log(UTF8ToString(str)); }\00minimal hello!")
(import "a" "b" (func $console_log (param i32)))
(table $0 1 1 funcref)
(export "c" (table $0))
(export "d" (func $__wasm_call_ctors))
(export "e" (func $main))
(func $main (; 1 ;) (param $0 i32) (param $1 i32) (result i32)
(call $console_log
(i32.const 1075)
)
(i32.const 0)
)
(func $__wasm_call_ctors (; 2 ;)
(nop)
)
)
```
```js
var c;
c || (c = Module);
var d = new TextDecoder("utf8");
function e(a) {
if (!a) {
return "";
}
for (var k = a + NaN, b = a; !(b >= k) && f[b];) {
++b;
}
return d.decode(f.subarray(a, b));
}
var g = new WebAssembly.Memory({initial:256, maximum:256}), f = new Uint8Array(g.buffer), h;
WebAssembly.instantiate(c.wasm, {a:{b:function(a) {
console.log(e(a));
}, a:g}}).then(function(a) {
a = a.instance.exports;
h = a.e;
a.d();
h();
});
```
In the Wasm module there are
```
(table $0 1 1 funcref)
(export "c" (table $0))
```
but those are not used for anything in the generated program, and the export `c` goes unused in the output, so they could both have been optimized out from the wasm module.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.