Skip to content

Wasm table is not optimized away if not used #12779

@juj

Description

@juj

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

(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)
 )
)
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions