Truncated JSON output from emscripten binary with `viaIR: true` and both `ir` and `*` selected as outputs
- Dominant language
- C++
- Stars
- 25.7k
- Forks
- 6.2k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 29
Description
The snippet from #14361 has one more weird effect that looks unrelated to that issue. When I select `*` output together with `ir`, enable `viaIR` and pass it to the emscripten binary, the produced JSON is truncated.
It only happens when these outputs are both selected at the same time. Changing the snippet to something simple like `contract {}` resolves the problem as well so it's something in the code that triggers it. Unlike in #14361, this happens both with and without optimizer.
It's possible that `solc-js` crashes in the process, but there's nothing in the output that would indicate that (no `Killed` or `core dumped` on the console). The fact that it always cuts off at the same point would also indicate that it's the JSON generation that suddenly decides to stop for whatever reason, but then successfully outputs that unfinished content.
### Environment
Tested with `solc-js` 0.8.20 with the binary included in the release.
### Repro
#### `input.json`
```json
{
"language": "Solidity",
"sources": {
"A": {"content": "
contract C {
function f2() public {
bytes1[2] memory k;
k[0] = bytes1(0);
}
}"
}
},
"settings": {
"viaIR": true,
"outputSelection": {
"*": {"*": ["ir", "*"]}
}
}
}
```
#### Script
```bash
npm install solc
emscripten_output=$(cat input.json | npx --no -- solcjs --standard-json)
echo "$emscripten_output"
echo "$emscripten_output" | jq
```
#### Output
The output from `jq` is:
```
parse error: Unfinished string at EOF at line 2, column 0
```
which means that the produced JSON is malformed. And indeed, this is how it ends:
```json
}\n\n function write_to_memory_t_bytes1(memPtr, value) {\n mstore(memPtr, cleanup_t_bytes1(value))\
```
This is the content of the `ir` field, which is not terminated. The Standard JSON output just ends abruptly in the middle of it.
Contributor guide
Research direction
Start with the input.json reproduction and the shell script invoking solcjs --standard-json, then inspect the output with jq. Compare runs with both ir and * selected against simpler output selections and the provided contract. Done means the emscripten binary emits complete, valid JSON with a terminated ir field.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, javascript, solidity
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100