ethereum / solidity

Solidity, the Smart Contract Programming Language
https://soliditylang.org
GNU General Public License v3.0
23.37k stars 5.78k forks source link

"Variable dataEnd is 4 slot(s) too deep inside the stack" in an external function returning triple-nested dynamic array #9979

Open cameel opened 4 years ago

cameel commented 4 years ago

Steps to Reproduce

pragma experimental ABIEncoderV2;

contract A {
    function get() public view returns (uint[][][] memory) {}

    function foo() public view {
        A(0x00).get();
    }
}

It happens only when using the optimizer

solc --optimize test.sol
Compiler error: Stack too deep when compiling inline assembly: Variable dataEnd is 4 slot(s) too deep inside the stack.

Without the optimizer it compiles just fine.

Running it as a soltest test case gives a bit more info about where the exception is raised:

Running 1 test case...
/solidity/test/boostTest.cpp(123): error: in "syntaxTests/test": Exception during extracted test: /solidity/libyul/backends/evm/AsmCodeGen.cpp(248): Throw in function static void solidity::yul::CodeGenerator::assemble(const solidity::yul::Block&, solidity::yul::AsmAnalysisInfo&, solidity::evmasm::Assembly&, solidity::langutil::EVMVersion, const solidity::yul::ExternalIdentifierAccess&, bool, bool)
Dynamic exception type: boost::wrapexcept<solidity::langutil::StackTooDeepError>
std::exception::what: Stack too deep when compiling inline assembly: Variable dataEnd is 4 slot(s) too deep inside the stack.
[solidity::util::tag_comment*] = Stack too deep when compiling inline assembly: Variable dataEnd is 4 slot(s) too deep inside the stack.

*** 1 failure is detected in the test module "SolidityTests"

Environment

cameel commented 4 years ago

Managed to reproduce it with solc by enabling the optimizer. So it's not just a soltest thing. Description and title updated.

Also, this error happens only on 0.7.2 and in develop. It does not happen on 0.7.1.

hrkrshnn commented 4 years ago

We generally ignore stack too deep errors. But this one might be a bit interesting. If it's not happening in 0.7.1, then it's likely that this is because of the change in order of inlining that was introduced in 0.7.2. If this is true, then there isn't much that we can do here.

Amxx commented 3 years ago

I'm seeing that error in 0.8.3. Any clue what is causing that ?

chriseth commented 3 years ago

@Amxx try to reduce the number of parameters for your function.

Amxx commented 3 years ago

@Amxx try to reduce the number of parameters for your function.

Yes that was it. To many calldata arrays in parameter. Replacing them with an array of structures (or a structures with arrays) seems to fix it.

The error message is really unclear (and doesn't point out the function causing the issue). You may want to clarify things

chriseth commented 3 years ago

We can hopefully fix this altogether soon.