Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IR-based Codegen error: too deep inside the stack. #15405

Open
Subway2023 opened this issue Sep 4, 2024 · 1 comment
Open

IR-based Codegen error: too deep inside the stack. #15405

Subway2023 opened this issue Sep 4, 2024 · 1 comment
Labels

Comments

@Subway2023
Copy link

Environment

  • Compiler version: 0.8.27
  • Target EVM version (as per compiler settings): None
  • Framework/IDE (e.g. Truffle or Remix): None
  • EVM execution environment / backend / blockchain client: None
  • Operating system: Linux

Steps to Reproduce

pragma solidity ^0.8.0;
contract C {
    struct S { uint x; }
    uint[] storageArray;
    bytes memoryArray;
    function g(uint x) public {
        for (uint i = 0; i < x; ++i) {
            storageArray.push(i);
        }
    }
    function f(uint a) public returns (uint, uint) {
        if (a > 1) {
            g(a);
            assembly {
                let temp := sload(storageArray.slot)
                sstore(temp, msize())
            }
        }
        memoryArray = abi.encode(storageArray);
        return (storageArray.length, storageArray[0]);
    }
}
solc --via-ir --bin test.sol
Uncaught exception:
/solidity/libyul/backends/evm/EVMObjectCompiler.cpp(125): Throw in function void solidity::yul::EVMObjectCompiler::run(const solidity::yul::Object&, bool)
Dynamic exception type: boost::wrapexcept<solidity::yul::StackTooDeepError>
std::exception::what: Variable var__38 is 11 slot(s) too deep inside the stack. Stack too deep. Try compiling with `--via-ir` (cli) or the equivalent `viaIR: true` (standard JSON) while enabling the optimizer. Otherwise, try removing local variables.
[solidity::util::tag_comment*] = Variable var__38 is 11 slot(s) too deep inside the stack. Stack too deep. Try compiling with `--via-ir` (cli) or the equivalent `viaIR: true` (standard JSON) while enabling the optimizer. Otherwise, try removing local variables.
@frangio
Copy link
Contributor

frangio commented Oct 22, 2024

msize() disables the optimization pass that can fix "stack too deep".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants