aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/codegen
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2016-09-17 21:25:54 +0800
committerGitHub <noreply@github.com>2016-09-17 21:25:54 +0800
commitaf6afb0415761b53721f89c7f65064807f41cbd3 (patch)
tree006481ce07f5ed6f1690014921f8c559b71dc5b5 /libsolidity/codegen
parent4fc6fc2ca59579fae2472df319c2d8d31fe5bde5 (diff)
parenta78e7794225da95d0f875c908025213d6a47cb59 (diff)
downloaddexon-solidity-af6afb0415761b53721f89c7f65064807f41cbd3.tar
dexon-solidity-af6afb0415761b53721f89c7f65064807f41cbd3.tar.gz
dexon-solidity-af6afb0415761b53721f89c7f65064807f41cbd3.tar.bz2
dexon-solidity-af6afb0415761b53721f89c7f65064807f41cbd3.tar.lz
dexon-solidity-af6afb0415761b53721f89c7f65064807f41cbd3.tar.xz
dexon-solidity-af6afb0415761b53721f89c7f65064807f41cbd3.tar.zst
dexon-solidity-af6afb0415761b53721f89c7f65064807f41cbd3.zip
Merge pull request #1107 from ethereum/develop
Version 0.4.2
Diffstat (limited to 'libsolidity/codegen')
-rw-r--r--libsolidity/codegen/ContractCompiler.cpp4
-rw-r--r--libsolidity/codegen/ExpressionCompiler.cpp17
2 files changed, 16 insertions, 5 deletions
diff --git a/libsolidity/codegen/ContractCompiler.cpp b/libsolidity/codegen/ContractCompiler.cpp
index 33571bc0..18b42fce 100644
--- a/libsolidity/codegen/ContractCompiler.cpp
+++ b/libsolidity/codegen/ContractCompiler.cpp
@@ -263,7 +263,9 @@ void ContractCompiler::appendFunctionSelector(ContractDefinition const& _contrac
CompilerContext::LocationSetter locationSetter(m_context, functionType->declaration());
m_context << callDataUnpackerEntryPoints.at(it.first);
- if (!functionType->isPayable())
+ // We have to allow this for libraries, because value of the previous
+ // call is still visible in the delegatecall.
+ if (!functionType->isPayable() && !_contract.isLibrary())
{
// Throw if function is not payable but call contained ether.
m_context << Instruction::CALLVALUE;
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;