mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Access output memory area so that we do not pay for resize during call.
This commit is contained in:
parent
dd2f878e59
commit
5a45990458
@ -1476,6 +1476,18 @@ void ExpressionCompiler::appendExternalFunctionCall(
|
|||||||
utils().storeFreeMemoryPointer();
|
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.
|
// Copy function identifier to memory.
|
||||||
utils().fetchFreeMemoryPointer();
|
utils().fetchFreeMemoryPointer();
|
||||||
if (!_functionType.isBareCall() || manualFunctionId)
|
if (!_functionType.isBareCall() || manualFunctionId)
|
||||||
@ -1551,10 +1563,7 @@ void ExpressionCompiler::appendExternalFunctionCall(
|
|||||||
gasNeededByCaller += eth::GasCosts::callValueTransferGas;
|
gasNeededByCaller += eth::GasCosts::callValueTransferGas;
|
||||||
if (!isCallCode && !isDelegateCall && !existenceChecked)
|
if (!isCallCode && !isDelegateCall && !existenceChecked)
|
||||||
gasNeededByCaller += eth::GasCosts::callNewAccountGas; // we never know
|
gasNeededByCaller += eth::GasCosts::callNewAccountGas; // we never know
|
||||||
m_context <<
|
m_context << gasNeededByCaller << Instruction::GAS << Instruction::SUB;
|
||||||
gasNeededByCaller <<
|
|
||||||
Instruction::GAS <<
|
|
||||||
Instruction::SUB;
|
|
||||||
}
|
}
|
||||||
if (isDelegateCall)
|
if (isDelegateCall)
|
||||||
m_context << Instruction::DELEGATECALL;
|
m_context << Instruction::DELEGATECALL;
|
||||||
|
@ -7191,7 +7191,7 @@ BOOST_AUTO_TEST_CASE(mem_resize_is_not_paid_at_call)
|
|||||||
// This tests that memory resize for return values is not paid during the call, which would
|
// This tests that memory resize for return values is not paid during the call, which would
|
||||||
// make the gas calculation overly complex. We access the end of the output area before
|
// make the gas calculation overly complex. We access the end of the output area before
|
||||||
// the call is made.
|
// the call is made.
|
||||||
// Tests that this also survivecs the optimizer.
|
// Tests that this also survives the optimizer.
|
||||||
char const* sourceCode = R"(
|
char const* sourceCode = R"(
|
||||||
contract C {
|
contract C {
|
||||||
function f() returns (uint[200]) {}
|
function f() returns (uint[200]) {}
|
||||||
|
Loading…
Reference in New Issue
Block a user