diff options
author | chriseth <chris@ethereum.org> | 2016-09-17 18:30:41 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-17 18:30:41 +0800 |
commit | 212e01609144ebd82bd6a4884b924fc97f31a1b4 (patch) | |
tree | cb2373739001771bd7dbd32fa325285cdcd3b4a0 /libsolidity | |
parent | 60f432e869c3d49a0a68f707b9377335e7427159 (diff) | |
parent | a4f6e5b16c7b9a9ba94c63b6042c20a988219e8e (diff) | |
download | dexon-solidity-212e01609144ebd82bd6a4884b924fc97f31a1b4.tar dexon-solidity-212e01609144ebd82bd6a4884b924fc97f31a1b4.tar.gz dexon-solidity-212e01609144ebd82bd6a4884b924fc97f31a1b4.tar.bz2 dexon-solidity-212e01609144ebd82bd6a4884b924fc97f31a1b4.tar.lz dexon-solidity-212e01609144ebd82bd6a4884b924fc97f31a1b4.tar.xz dexon-solidity-212e01609144ebd82bd6a4884b924fc97f31a1b4.tar.zst dexon-solidity-212e01609144ebd82bd6a4884b924fc97f31a1b4.zip |
Merge pull request #1104 from ethereum/fixmemcosts
Fix memory resize costs during call
Diffstat (limited to 'libsolidity')
-rw-r--r-- | libsolidity/codegen/ExpressionCompiler.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 96ca4296..26acd8a4 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -1476,6 +1476,18 @@ void ExpressionCompiler::appendExternalFunctionCall( utils().storeFreeMemoryPointer(); } + // Touch the end of the output area so that we do not pay for memory resize during the call + // (which we would have to subtract from the gas left) + // We could also just use MLOAD; POP right before the gas calculation, but the optimizer + // would remove that, so we use MSTORE here. + if (!_functionType.gasSet() && retSize > 0) + { + m_context << u256(0); + utils().fetchFreeMemoryPointer(); + // This touches too much, but that way we save some rounding arithmetics + m_context << u256(retSize) << Instruction::ADD << Instruction::MSTORE; + } + // Copy function identifier to memory. utils().fetchFreeMemoryPointer(); if (!_functionType.isBareCall() || manualFunctionId) @@ -1551,10 +1563,7 @@ void ExpressionCompiler::appendExternalFunctionCall( gasNeededByCaller += eth::GasCosts::callValueTransferGas; if (!isCallCode && !isDelegateCall && !existenceChecked) gasNeededByCaller += eth::GasCosts::callNewAccountGas; // we never know - m_context << - gasNeededByCaller << - Instruction::GAS << - Instruction::SUB; + m_context << gasNeededByCaller << Instruction::GAS << Instruction::SUB; } if (isDelegateCall) m_context << Instruction::DELEGATECALL; |