diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index 84d7665c4..a844ab8be 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -698,42 +698,28 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) evmasm::AssemblyItem returnLabel = m_context.pushNewTag(); - if (!_functionCall.isSuffixCall()) + if (!_functionCall.isSuffixCall() || parameterTypes.size() == 1) { for (unsigned i = 0; i < arguments.size(); ++i) acceptAndConvert(*arguments[i], *parameterTypes[i]); } else { - solAssert(arguments.size() == 1); - solAssert(arguments[0]); + solAssert(parameterTypes.size() == 2); + solAssert(arguments.size() == 1 && arguments[0]); auto const* literal = dynamic_cast(arguments[0].get()); - Type const& literalType = *literal->annotation().type; solAssert(literal); solAssert(literal->annotation().type); - if (parameterTypes.size() == 1) - { - if (literalType.category() != Type::Category::StringLiteral) - // NOTE: For string literals we do not need to define the variable. The variable - // value will be embedded inside the conversion function. - m_context << literalType.literalValue(literal); - utils().convertType(literalType, *parameterTypes.at(0)); - } - else - { - solAssert(parameterTypes.size() == 2); + auto const* rationalNumberType = dynamic_cast(literal->annotation().type); + solAssert(rationalNumberType); - auto const* rationalNumberType = dynamic_cast(&literalType); - solAssert(rationalNumberType); - - auto&& [mantissa, exponent] = rationalNumberType->fractionalDecomposition(); - solAssert(mantissa && exponent); - m_context << mantissa->literalValue(nullptr); - utils().convertType(*mantissa, *parameterTypes.at(0)); - m_context << exponent->literalValue(nullptr); - utils().convertType(*exponent, *parameterTypes.at(1)); - } + auto&& [mantissa, exponent] = rationalNumberType->fractionalDecomposition(); + solAssert(mantissa && exponent); + m_context << mantissa->literalValue(nullptr); + utils().convertType(*mantissa, *parameterTypes.at(0)); + m_context << exponent->literalValue(nullptr); + utils().convertType(*exponent, *parameterTypes.at(1)); } _functionCall.expression().accept(*this); diff --git a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp index 59a063b9d..89d044d9c 100644 --- a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp +++ b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp @@ -1003,7 +1003,7 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall) vector args; FunctionDefinition const* functionDef = nullptr; - if (!_functionCall.isSuffixCall()) + if (!_functionCall.isSuffixCall() || parameterTypes.size() == 1) { functionDef = ASTNode::resolveFunctionCall(_functionCall, &m_context.mostDerivedContract()); @@ -1020,40 +1020,25 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall) solAssert(!functionDef->virtualSemantics()); solAssert(!functionType->hasBoundFirstArgument()); - solAssert(arguments.size() == 1); - solAssert(arguments[0]); + solAssert(parameterTypes.size() == 2); + solAssert(arguments.size() == 1 && arguments[0]); auto const* literal = dynamic_cast(arguments[0].get()); - Type const& literalType = *literal->annotation().type; solAssert(literal); solAssert(literal->annotation().type); - if (parameterTypes.size() == 2) - { - auto const* literalRationalType = dynamic_cast(&literalType); - solAssert(literalRationalType); + auto const* literalRationalType = dynamic_cast(literal->annotation().type); + solAssert(literalRationalType); - auto&& [mantissa, exponent] = literalRationalType->fractionalDecomposition(); - solAssert(mantissa && exponent); + auto&& [mantissa, exponent] = literalRationalType->fractionalDecomposition(); + solAssert(mantissa && exponent); - IRVariable mantissaVar(m_context.newYulVariable(), *mantissa); - define(mantissaVar) << toCompactHexWithPrefix(mantissa->literalValue(literal)) << "\n"; - args += convert(mantissaVar, *parameterTypes[0]).stackSlots(); + IRVariable mantissaVar(m_context.newYulVariable(), *mantissa); + define(mantissaVar) << toCompactHexWithPrefix(mantissa->literalValue(literal)) << "\n"; + args += convert(mantissaVar, *parameterTypes[0]).stackSlots(); - IRVariable exponentVar(m_context.newYulVariable(), *exponent); - define(exponentVar) << toCompactHexWithPrefix(exponent->literalValue(literal)) << "\n"; - args += convert(exponentVar, *parameterTypes[1]).stackSlots(); - } - else - { - solAssert(parameterTypes.size() == 1); - - IRVariable value(m_context.newYulVariable(), literalType); - if (literalType.category() != Type::Category::StringLiteral) - // NOTE: For string literals we do not need to define the variable. The variable - // value will be embedded inside the conversion function. - define(value) << toCompactHexWithPrefix(literalType.literalValue(literal)) << "\n"; - args += convert(value, *parameterTypes[0]).stackSlots(); - } + IRVariable exponentVar(m_context.newYulVariable(), *exponent); + define(exponentVar) << toCompactHexWithPrefix(exponent->literalValue(literal)) << "\n"; + args += convert(exponentVar, *parameterTypes[1]).stackSlots(); } if (functionDef)