diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2018-04-03 22:58:11 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-03 22:58:11 +0800 |
commit | 0edce4b570c157927933697b30f0f94cbdf173b2 (patch) | |
tree | a7ec50f920090e529b435e878e4df8cedd1f0eb4 /libsolidity/codegen/ExpressionCompiler.cpp | |
parent | 7753249f646f239819c62ab6847438dc84b6e04b (diff) | |
parent | deadff263fbf4d5da911d7c544821cc77081a6d3 (diff) | |
download | dexon-solidity-0edce4b570c157927933697b30f0f94cbdf173b2.tar dexon-solidity-0edce4b570c157927933697b30f0f94cbdf173b2.tar.gz dexon-solidity-0edce4b570c157927933697b30f0f94cbdf173b2.tar.bz2 dexon-solidity-0edce4b570c157927933697b30f0f94cbdf173b2.tar.lz dexon-solidity-0edce4b570c157927933697b30f0f94cbdf173b2.tar.xz dexon-solidity-0edce4b570c157927933697b30f0f94cbdf173b2.tar.zst dexon-solidity-0edce4b570c157927933697b30f0f94cbdf173b2.zip |
Merge pull request #3693 from ethereum/optimizeMLOAD
Optimize across MLOAD if MSIZE is not used.
Diffstat (limited to 'libsolidity/codegen/ExpressionCompiler.cpp')
-rw-r--r-- | libsolidity/codegen/ExpressionCompiler.cpp | 21 |
1 files changed, 4 insertions, 17 deletions
diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 9e2d30d5..76aa6843 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -850,8 +850,6 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) } case FunctionType::Kind::ObjectCreation: { - // Will allocate at the end of memory (MSIZE) and not write at all unless the base - // type is dynamically sized. ArrayType const& arrayType = dynamic_cast<ArrayType const&>(*_functionCall.annotation().type); _functionCall.expression().accept(*this); solAssert(arguments.size() == 1, ""); @@ -861,15 +859,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) utils().convertType(*arguments[0]->annotation().type, IntegerType(256)); // Stack: requested_length - // Allocate at max(MSIZE, freeMemoryPointer) utils().fetchFreeMemoryPointer(); - m_context << Instruction::DUP1 << Instruction::MSIZE; - m_context << Instruction::LT; - auto initialise = m_context.appendConditionalJump(); - // Free memory pointer does not point to empty memory, use MSIZE. - m_context << Instruction::POP; - m_context << Instruction::MSIZE; - m_context << initialise; // Stack: requested_length memptr m_context << Instruction::SWAP1; @@ -894,13 +884,10 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) // Check if length is zero m_context << Instruction::DUP1 << Instruction::ISZERO; auto skipInit = m_context.appendConditionalJump(); - - // We only have to initialise if the base type is a not a value type. - if (dynamic_cast<ReferenceType const*>(arrayType.baseType().get())) - { - m_context << Instruction::DUP2 << u256(32) << Instruction::ADD; - utils().zeroInitialiseMemoryArray(arrayType); - } + // Always initialize because the free memory pointer might point at + // a dirty memory area. + m_context << Instruction::DUP2 << u256(32) << Instruction::ADD; + utils().zeroInitialiseMemoryArray(arrayType); m_context << skipInit; m_context << Instruction::POP; break; |