From b99a74fb343adac02e0003ae170b4050da40e30b Mon Sep 17 00:00:00 2001 From: Djordje Mijovic Date: Fri, 11 Dec 2020 11:06:30 +0100 Subject: [PATCH] Implementing conversion from calldata slices to memory arrays. --- Changelog.md | 1 + libsolidity/codegen/CompilerUtils.cpp | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Changelog.md b/Changelog.md index c9f4d2318..def607f3a 100644 --- a/Changelog.md +++ b/Changelog.md @@ -3,6 +3,7 @@ Language Features: * Code generator: Support copying dynamically encoded structs from calldata to memory. * Code generator: Support copying of nested arrays from calldata to memory. + * Code generator: Support conversion from calldata slices to memory and storage arrays. * The fallback function can now also have a single ``calldata`` argument (equaling ``msg.data``) and return ``bytes memory`` (which will not be ABI-encoded but returned as-is). * Wasm backend: Add ``i32.select`` and ``i64.select`` instructions. diff --git a/libsolidity/codegen/CompilerUtils.cpp b/libsolidity/codegen/CompilerUtils.cpp index ea6a84d1d..407c1037a 100644 --- a/libsolidity/codegen/CompilerUtils.cpp +++ b/libsolidity/codegen/CompilerUtils.cpp @@ -1051,11 +1051,11 @@ void CompilerUtils::convertType( case Type::Category::ArraySlice: { auto& typeOnStack = dynamic_cast(_typeOnStack); - solUnimplementedAssert( - _targetType.dataStoredIn(DataLocation::CallData), - "Conversion from calldata slices to memory not yet implemented." - ); - solAssert(_targetType == typeOnStack.arrayType(), ""); + solAssert(_targetType.category() == Type::Category::Array, ""); + auto const& targetArrayType = dynamic_cast(_targetType); + solAssert(targetArrayType == *typeOnStack.arrayType().copyForLocation(targetArrayType.location(), false), ""); + if (!_targetType.dataStoredIn(DataLocation::CallData)) + return convertType(typeOnStack.arrayType(), _targetType); solUnimplementedAssert( typeOnStack.arrayType().location() == DataLocation::CallData && typeOnStack.arrayType().isDynamicallySized() &&