From 8aa4568b10e6bde427fd5e84dfa21c01e74c78d9 Mon Sep 17 00:00:00 2001 From: Djordje Mijovic Date: Fri, 11 Dec 2020 11:07:22 +0100 Subject: [PATCH] [Sol->Yul] Implementing conversion from calldata slices to memory arrays. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kamil ƚliwak --- libsolidity/ast/Types.cpp | 14 +++++++------- libsolidity/codegen/YulUtilFunctions.cpp | 7 +++++-- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index d32650383..5c7c91126 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -2074,13 +2074,13 @@ std::unique_ptr ArrayType::copyForLocation(DataLocation _location BoolResult ArraySliceType::isImplicitlyConvertibleTo(Type const& _other) const { - if ( - m_arrayType.dataStoredIn(DataLocation::CallData) && - m_arrayType.isDynamicallySized() && - m_arrayType.isImplicitlyConvertibleTo(_other) - ) - return true; - return (*this) == _other; + return + (*this) == _other || + ( + m_arrayType.dataStoredIn(DataLocation::CallData) && + m_arrayType.isDynamicallySized() && + m_arrayType.isImplicitlyConvertibleTo(_other) + ); } string ArraySliceType::richIdentifier() const diff --git a/libsolidity/codegen/YulUtilFunctions.cpp b/libsolidity/codegen/YulUtilFunctions.cpp index db92a7a0a..6c1784551 100644 --- a/libsolidity/codegen/YulUtilFunctions.cpp +++ b/libsolidity/codegen/YulUtilFunctions.cpp @@ -2852,8 +2852,8 @@ string YulUtilFunctions::conversionFunction(Type const& _from, Type const& _to) solAssert(_from.dataStoredIn(DataLocation::CallData), ""); solAssert(_to.category() == Type::Category::Array, ""); - ArraySliceType const& fromType = dynamic_cast(_from); - ArrayType const& targetType = dynamic_cast(_to); + auto const& fromType = dynamic_cast(_from); + auto const& targetType = dynamic_cast(_to); solAssert(!fromType.arrayType().baseType()->isDynamicallyEncoded(), ""); solAssert( @@ -2861,6 +2861,9 @@ string YulUtilFunctions::conversionFunction(Type const& _from, Type const& _to) "Converting arrays of different type is not possible" ); + if (!targetType.dataStoredIn(DataLocation::CallData)) + return arrayConversionFunction(fromType.arrayType(), targetType); + string const functionName = "convert_" + _from.identifier() +