[Sol->Yul] Fixing nested bytes array push.

This commit is contained in:
Djordje Mijovic
2021-01-14 10:32:31 +01:00
parent fe344ed6e5
commit 7c45509a77
4 changed files with 42 additions and 3 deletions
+24 -1
View File
@@ -2576,7 +2576,30 @@ string YulUtilFunctions::updateStorageValueFunction(
auto const* toReferenceType = dynamic_cast<ReferenceType const*>(&_toType);
auto const* fromReferenceType = dynamic_cast<ReferenceType const*>(&_fromType);
solAssert(fromReferenceType && toReferenceType, "");
solAssert(toReferenceType, "");
if (!fromReferenceType)
{
solAssert(_fromType.category() == Type::Category::StringLiteral, "");
solAssert(toReferenceType->category() == Type::Category::Array, "");
auto const& toArrayType = dynamic_cast<ArrayType const&>(*toReferenceType);
solAssert(toArrayType.isByteArray(), "");
return Whiskers(R"(
function <functionName>(slot<?dynamicOffset>, offset</dynamicOffset>) {
<?dynamicOffset>if offset { <panic>() }</dynamicOffset>
let value := <copyLiteralToMemory>()
<copyToStorage>(slot, value)
}
)")
("functionName", functionName)
("dynamicOffset", !_offset.has_value())
("panic", panicFunction(PanicCode::Generic))
("copyLiteralToMemory", copyLiteralToMemoryFunction(dynamic_cast<StringLiteralType const&>(_fromType).value()))
("copyToStorage", copyArrayToStorageFunction(*TypeProvider::bytesMemory(), toArrayType))
.render();
}
solAssert(*toReferenceType->copyForLocation(
fromReferenceType->location(),
fromReferenceType->isPointer()
@@ -1325,8 +1325,7 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall)
m_utils.storageArrayPushFunction(arrayType, &argument.type()) <<
"(" <<
IRVariable(_functionCall.expression()).commaSeparatedList() <<
", " <<
argument.commaSeparatedList() <<
(argument.stackSlots().empty() ? "" : (", " + argument.commaSeparatedList())) <<
")\n";
}
break;