ViaIR = true & YulException: Cannot swap Slot TMP[eq, 0] ... blah
- Dominant language
- C++
- Stars
- 25.7k
- Forks
- 6.2k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 29
Description
## Description
Yul compiler throws an illegible exception during development:
```
YulException: Cannot swap Slot TMP[eq, 0] with Slot RET[fun_assertEq_459]: too deep in the stack by 1 slots in [ _2 TMP[eq, 0] param_35 param_34 param_37 _mpos_31 param_36 _65 expr_12 offset _65 _69 zero_struct_UPDP_Test_Data_memory_ptr_mpos _72 var_nr _70 _2 memPtr_9 RET[fun_assertEq_459] ]
memoryguard was present.
```
## Environment
- Compiler version: 0.8.19
- Target EVM version (as per compiler settings): default settings but with `via_ir = true`.
- Framework/IDE (e.g. Truffle or Remix): foundry
- EVM execution environment / backend / blockchain client:
- Operating system: NixOS
## Steps to Reproduce
I tried to find a minimum example for you, but I couldn't. You might need to do a full checkout of the branch, I will save the branch for you:
```
$ # have foundry installed:
$ # e.g through nix shell github:shazow/foundry.nix/monthly
$ forge --version
forge 0.2.0 (87bc53f 2023-04-02T00:04:08.631058157Z)
$ git clone https://github.com/superfluid-finance/protocol-monorepo.git
$ cd protocol-monorepo
$ git checkout solc-yul-exception-bug
$ yarn git:submodule:init
$ yarn install
$ cd packages/solidity-semantic-money
$ make test-SemanticMoney
FOUNDRY_PROFILE=test forge test --match-contract SemanticMoney -vv
[⠊] Compiling...
[⠒] Compiling 36 files with 0.8.19
[⠆] Solc 0.8.19 finished in 20.08s
Error:
Compiler run failed
YulException: Cannot swap Slot TMP[eq, 0] with Slot RET[fun_assertEq_459]: too deep in the stack by 1 slots in [ _2 TMP[eq, 0] param_35 param_34 param_37 _mpos_31 param_36 _65 expr_12 offset _65 _69 zero_struct_UPDP_Test_Data_memory_ptr_mpos _72 var_nr _70 _2 memPtr_9 RET[fun_assertEq_459] ]
memoryguard was present.
```
Related test file is [solidity-semantic-money/test/SemanticMoney.t.sol](https://github.com/superfluid-finance/protocol-monorepo/blob/41ed5de296b37d4dd77931f500b15c64dd058ef6/packages/solidity-semantic-money/test/SemanticMoney.t.sol#L43)
Contributor guide
Research direction
Start by checking out the solc-yul-exception-bug branch and running make test-SemanticMoney in packages/solidity-semantic-money with ViaIR enabled. Read solidity-semantic-money/test/SemanticMoney.t.sol around line 43 and investigate the reported YulException from the 0.8.19 compiler. Done should mean the reproduction is understood and the compiler reports a usable result or diagnostic.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, solidity
- Domain
- blockchain, compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100