emscripten-core / emscripten-core/emscripten

"local count too large" with large generated C++ function in debug mode

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

Description

Please include the following in your bug report:

**Version of emscripten/emsdk:**
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.34 (57b21b8fdcbe3ebb523178b79465254668eab408)
clang version 17.0.0 (https://github.com/llvm/llvm-project a031f72187ce495b9faa4ccf99b1e901a3872f4b)
Target: wasm32-unknown-emscripten
Thread model: posix

Using this python script to generate the code:

```
#!/usr/bin/env python3

import os
import sys

code = ""

for i in range(0, 1200):
code += f"""case {i}:
otherfunc(arg2, "foo", local2, local1, local3, arg1, arg3, arg4, arg5, arg6, arg7, arg8);
break;
"""

with open("generated.cpp", "w") as f:
f.write(
f"""

void otherfunc (...) {{
}}

void somefunc(int arg1, int arg2, char arg3, int arg4, int arg5, int arg6, int arg7, int arg8) {{
char local1 = 0;
char local2 = 0;
char local3 = 0;

switch (arg4) {{
{code}
default:
break;
}}
}}

int main(int, char**)
{{
somefunc(0, 0, 's', 0, 0, 0, 0, 0);
return 0;
}}

""")
```

and this command line:

```
../generate.py && em++ -g -o main.html generated.cpp
```

Chrome fails with something like

> main.js:870 Uncaught (in promise) RuntimeError: Aborted(CompileError: WebAssembly.instantiate(): Compiling function #2 failed: local count too large @+452)

Firefox fails with something like

> Uncaught (in promise) RuntimeError: Aborted(CompileError: wasm validation error: at offset 455: too many locals)

I don't really know what is meant by `locals` here, because there are not many local variables.

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.