diff options
Diffstat (limited to 'libsolidity/codegen/ExpressionCompiler.cpp')
-rw-r--r-- | libsolidity/codegen/ExpressionCompiler.cpp | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 45e58bd0..27440289 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -710,9 +710,9 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) arguments.front()->accept(*this); // Optimization: If type is bytes or string, then do not encode, // but directly compute keccak256 on memory. - if (*argType == ArrayType(DataLocation::Memory) || *argType == ArrayType(DataLocation::Memory, true)) + if (*argType == ArrayType::bytesMemory() || *argType == ArrayType::stringMemory()) { - ArrayUtils(m_context).retrieveLength(ArrayType(DataLocation::Memory)); + ArrayUtils(m_context).retrieveLength(ArrayType::bytesMemory()); m_context << Instruction::SWAP1 << u256(0x20) << Instruction::ADD; } else @@ -1086,7 +1086,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) utils().abiDecode(targetTypes, false); else { - utils().convertType(*firstArgType, ArrayType(DataLocation::Memory)); + utils().convertType(*firstArgType, ArrayType::bytesMemory()); m_context << Instruction::DUP1 << u256(32) << Instruction::ADD; m_context << Instruction::SWAP1 << Instruction::MLOAD; // stack now: <mem_pos> <length> @@ -1098,8 +1098,6 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) case FunctionType::Kind::GasLeft: m_context << Instruction::GAS; break; - default: - solAssert(false, "Invalid function type."); } } return false; @@ -1230,7 +1228,7 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess) else solAssert(false, "Contract member is neither variable nor function."); m_context << identifier; - /// need to store store it as bytes4 + /// need to store it as bytes4 utils().leftShiftNumberOnStack(224); return false; } @@ -1259,7 +1257,7 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess) identifier = FunctionType(*function).externalIdentifier(); else solAssert(false, "Contract member is neither variable nor function."); - utils().convertType(type, AddressType(), true); + utils().convertType(type, type.isPayable() ? AddressType::addressPayable() : AddressType::address(), true); m_context << identifier; } else @@ -1277,15 +1275,24 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess) { utils().convertType( *_memberAccess.expression().annotation().type, - AddressType(), + AddressType::address(), true ); m_context << Instruction::BALANCE; } - else if ((set<string>{"send", "transfer", "call", "callcode", "delegatecall", "staticcall"}).count(member)) + else if ((set<string>{"send", "transfer"}).count(member)) + { + solAssert(dynamic_cast<AddressType const&>(*_memberAccess.expression().annotation().type).stateMutability() == StateMutability::Payable, ""); + utils().convertType( + *_memberAccess.expression().annotation().type, + AddressType(StateMutability::Payable), + true + ); + } + else if ((set<string>{"call", "callcode", "delegatecall", "staticcall"}).count(member)) utils().convertType( *_memberAccess.expression().annotation().type, - AddressType(), + AddressType::address(), true ); else @@ -1296,7 +1303,7 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess) if (member == "selector") { m_context << Instruction::SWAP1 << Instruction::POP; - /// need to store store it as bytes4 + /// need to store it as bytes4 utils().leftShiftNumberOnStack(224); } else @@ -1966,7 +1973,7 @@ void ExpressionCompiler::appendExternalFunctionCall( m_context << dupInstruction(m_context.baseToCurrentStackOffset(contractStackPos)); bool existenceChecked = false; - // Check the the target contract exists (has code) for non-low-level calls. + // Check the target contract exists (has code) for non-low-level calls. if (funKind == FunctionType::Kind::External || funKind == FunctionType::Kind::DelegateCall) { m_context << Instruction::DUP1 << Instruction::EXTCODESIZE << Instruction::ISZERO; |