aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2015-06-06 07:04:55 +0800
committerchriseth <c@ethdev.com>2015-06-07 18:51:15 +0800
commitc2a9419e495e931a825e8146aec49ffc34e44954 (patch)
treea6674b16ad95fe108794e305abddc7981c1bed79
parentb51ef4a357b4b60fc01038b0e97280fb9ecca01e (diff)
downloaddexon-solidity-c2a9419e495e931a825e8146aec49ffc34e44954.tar
dexon-solidity-c2a9419e495e931a825e8146aec49ffc34e44954.tar.gz
dexon-solidity-c2a9419e495e931a825e8146aec49ffc34e44954.tar.bz2
dexon-solidity-c2a9419e495e931a825e8146aec49ffc34e44954.tar.lz
dexon-solidity-c2a9419e495e931a825e8146aec49ffc34e44954.tar.xz
dexon-solidity-c2a9419e495e931a825e8146aec49ffc34e44954.tar.zst
dexon-solidity-c2a9419e495e931a825e8146aec49ffc34e44954.zip
Improved "Stack too deep" error message.
Closes #2080.
-rw-r--r--ArrayUtils.cpp5
-rw-r--r--Compiler.cpp2
-rw-r--r--CompilerUtils.cpp11
-rw-r--r--ExpressionCompiler.cpp2
-rw-r--r--LValue.cpp26
5 files changed, 32 insertions, 14 deletions
diff --git a/ArrayUtils.cpp b/ArrayUtils.cpp
index 531ab8af..b770b815 100644
--- a/ArrayUtils.cpp
+++ b/ArrayUtils.cpp
@@ -168,7 +168,10 @@ void ArrayUtils::copyArrayToStorage(ArrayType const& _targetType, ArrayType cons
else
solAssert(false, "Copying of unknown type requested: " + sourceBaseType->toString());
// stack: target_ref target_data_end source_data_pos target_data_pos source_data_end [target_byte_offset] [source_byte_offset] <source_value>...
- solAssert(2 + byteOffsetSize + sourceBaseType->getSizeOnStack() <= 16, "Stack too deep.");
+ solAssert(
+ 2 + byteOffsetSize + sourceBaseType->getSizeOnStack() <= 16,
+ "Stack too deep, try removing local variables."
+ );
// fetch target storage reference
m_context << eth::dupInstruction(2 + byteOffsetSize + sourceBaseType->getSizeOnStack());
if (haveByteOffsetTarget)
diff --git a/Compiler.cpp b/Compiler.cpp
index 40ed1fd8..0a75e55a 100644
--- a/Compiler.cpp
+++ b/Compiler.cpp
@@ -367,7 +367,7 @@ bool Compiler::visit(FunctionDefinition const& _function)
stackLayout.push_back(i);
stackLayout += vector<int>(c_localVariablesSize, -1);
- solAssert(stackLayout.size() <= 17, "Stack too deep.");
+ solAssert(stackLayout.size() <= 17, "Stack too deep, try removing local variables.");
while (stackLayout.back() != int(stackLayout.size() - 1))
if (stackLayout.back() < 0)
{
diff --git a/CompilerUtils.cpp b/CompilerUtils.cpp
index e3d8f7f9..3549ef98 100644
--- a/CompilerUtils.cpp
+++ b/CompilerUtils.cpp
@@ -142,22 +142,25 @@ void CompilerUtils::moveToStackVariable(VariableDeclaration const& _variable)
solAssert(stackPosition >= size, "Variable size and position mismatch.");
// move variable starting from its top end in the stack
if (stackPosition - size + 1 > 16)
- BOOST_THROW_EXCEPTION(CompilerError() << errinfo_sourceLocation(_variable.getLocation())
- << errinfo_comment("Stack too deep."));
+ BOOST_THROW_EXCEPTION(
+ CompilerError() <<
+ errinfo_sourceLocation(_variable.getLocation()) <<
+ errinfo_comment("Stack too deep, try removing local variables.")
+ );
for (unsigned i = 0; i < size; ++i)
m_context << eth::swapInstruction(stackPosition - size + 1) << eth::Instruction::POP;
}
void CompilerUtils::copyToStackTop(unsigned _stackDepth, unsigned _itemSize)
{
- solAssert(_stackDepth <= 16, "Stack too deep.");
+ solAssert(_stackDepth <= 16, "Stack too deep, try removing local variables.");
for (unsigned i = 0; i < _itemSize; ++i)
m_context << eth::dupInstruction(_stackDepth);
}
void CompilerUtils::moveToStackTop(unsigned _stackDepth)
{
- solAssert(_stackDepth <= 15, "Stack too deep.");
+ solAssert(_stackDepth <= 15, "Stack too deep, try removing local variables.");
for (unsigned i = 0; i < _stackDepth; ++i)
m_context << eth::swapInstruction(1 + i);
}
diff --git a/ExpressionCompiler.cpp b/ExpressionCompiler.cpp
index bac967d8..ba80a8ea 100644
--- a/ExpressionCompiler.cpp
+++ b/ExpressionCompiler.cpp
@@ -263,7 +263,7 @@ bool ExpressionCompiler::visit(Assignment const& _assignment)
appendOrdinaryBinaryOperatorCode(Token::AssignmentToBinaryOp(op), *_assignment.getType());
if (lvalueSize > 0)
{
- solAssert(itemSize + lvalueSize <= 16, "Stack too deep.");
+ solAssert(itemSize + lvalueSize <= 16, "Stack too deep, try removing local variables.");
// value [lvalue_ref] updated_value
for (unsigned i = 0; i < itemSize; ++i)
m_context << eth::swapInstruction(itemSize + lvalueSize) << eth::Instruction::POP;
diff --git a/LValue.cpp b/LValue.cpp
index 38efb2a7..b684e55a 100644
--- a/LValue.cpp
+++ b/LValue.cpp
@@ -42,8 +42,11 @@ void StackVariable::retrieveValue(SourceLocation const& _location, bool) const
{
unsigned stackPos = m_context.baseToCurrentStackOffset(m_baseStackOffset);
if (stackPos >= 15) //@todo correct this by fetching earlier or moving to memory
- BOOST_THROW_EXCEPTION(CompilerError()
- << errinfo_sourceLocation(_location) << errinfo_comment("Stack too deep."));
+ BOOST_THROW_EXCEPTION(
+ CompilerError() <<
+ errinfo_sourceLocation(_location) <<
+ errinfo_comment("Stack too deep, try removing local variables.")
+ );
for (unsigned i = 0; i < m_size; ++i)
m_context << eth::dupInstruction(stackPos + 1);
}
@@ -52,8 +55,11 @@ void StackVariable::storeValue(Type const&, SourceLocation const& _location, boo
{
unsigned stackDiff = m_context.baseToCurrentStackOffset(m_baseStackOffset) - m_size + 1;
if (stackDiff > 16)
- BOOST_THROW_EXCEPTION(CompilerError()
- << errinfo_sourceLocation(_location) << errinfo_comment("Stack too deep."));
+ BOOST_THROW_EXCEPTION(
+ CompilerError() <<
+ errinfo_sourceLocation(_location) <<
+ errinfo_comment("Stack too deep, try removing local variables.")
+ );
else if (stackDiff > 0)
for (unsigned i = 0; i < m_size; ++i)
m_context << eth::swapInstruction(stackDiff) << eth::Instruction::POP;
@@ -65,8 +71,11 @@ void StackVariable::setToZero(SourceLocation const& _location, bool) const
{
unsigned stackDiff = m_context.baseToCurrentStackOffset(m_baseStackOffset);
if (stackDiff > 16)
- BOOST_THROW_EXCEPTION(CompilerError()
- << errinfo_sourceLocation(_location) << errinfo_comment("Stack too deep."));
+ BOOST_THROW_EXCEPTION(
+ CompilerError() <<
+ errinfo_sourceLocation(_location) <<
+ errinfo_comment("Stack too deep, try removing local variables.")
+ );
solAssert(stackDiff >= m_size - 1, "");
for (unsigned i = 0; i < m_size; ++i)
m_context << u256(0) << eth::swapInstruction(stackDiff + 1 - i)
@@ -204,7 +213,10 @@ void StorageItem::storeValue(Type const& _sourceType, SourceLocation const& _loc
// stack: source_ref source_off target_ref target_off member_slot_offset member_byte_offset source_member_ref source_member_off
StorageItem(m_context, *memberType).retrieveValue(_location, true);
// stack: source_ref source_off target_ref target_off member_offset source_value...
- solAssert(4 + memberType->getSizeOnStack() <= 16, "Stack too deep.");
+ solAssert(
+ 4 + memberType->getSizeOnStack() <= 16,
+ "Stack too deep, try removing local varibales."
+ );
m_context
<< eth::dupInstruction(4 + memberType->getSizeOnStack())
<< eth::dupInstruction(3 + memberType->getSizeOnStack()) << eth::Instruction::ADD