Merge pull request #10315 from ethereum/fixToStorageCopy

[SolYul] Fix bug in array to storage copy routine.
This commit is contained in:
chriseth 2020-11-17 15:56:21 +01:00 committed by GitHub
commit df53b53aa5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 4 deletions

View File

@ -1542,7 +1542,7 @@ string YulUtilFunctions::copyArrayToStorageFunction(ArrayType const& _fromType,
<updateStorageValue>(elementSlot<?isValueType>, elementOffset</isValueType>, <elementValues>) <updateStorageValue>(elementSlot<?isValueType>, elementOffset</isValueType>, <elementValues>)
srcPtr := add(srcPtr, <stride>) srcPtr := add(srcPtr, <srcStride>)
<?multipleItemsPerSlot> <?multipleItemsPerSlot>
elementOffset := add(elementOffset, <storageStride>) elementOffset := add(elementOffset, <storageStride>)
@ -1552,7 +1552,6 @@ string YulUtilFunctions::copyArrayToStorageFunction(ArrayType const& _fromType,
} }
<!multipleItemsPerSlot> <!multipleItemsPerSlot>
elementSlot := add(elementSlot, <storageSize>) elementSlot := add(elementSlot, <storageSize>)
elementOffset := 0
</multipleItemsPerSlot> </multipleItemsPerSlot>
} }
} }
@ -1568,7 +1567,6 @@ string YulUtilFunctions::copyArrayToStorageFunction(ArrayType const& _fromType,
templ("fromCalldata", fromCalldata); templ("fromCalldata", fromCalldata);
templ("isToDynamic", _toType.isDynamicallySized()); templ("isToDynamic", _toType.isDynamicallySized());
templ("srcDataLocation", arrayDataAreaFunction(_fromType)); templ("srcDataLocation", arrayDataAreaFunction(_fromType));
templ("isFromMemoryDynamic", _fromType.isDynamicallySized() && _fromType.dataStoredIn(DataLocation::Memory));
if (fromCalldata) if (fromCalldata)
{ {
templ("dynamicallySizedBase", _fromType.baseType()->isDynamicallySized()); templ("dynamicallySizedBase", _fromType.baseType()->isDynamicallySized());
@ -1589,7 +1587,13 @@ string YulUtilFunctions::copyArrayToStorageFunction(ArrayType const& _fromType,
_fromType.baseType()->stackItems().size() _fromType.baseType()->stackItems().size()
)); ));
templ("updateStorageValue", updateStorageValueFunction(*_fromType.baseType(), *_toType.baseType())); templ("updateStorageValue", updateStorageValueFunction(*_fromType.baseType(), *_toType.baseType()));
templ("stride", to_string(fromCalldata ? _fromType.calldataStride() : _fromType.memoryStride())); templ("srcStride",
fromCalldata ?
to_string(_fromType.calldataStride()) :
fromMemory ?
to_string(_fromType.memoryStride()) :
formatNumber(_fromType.baseType()->storageSize())
);
templ("multipleItemsPerSlot", _toType.storageStride() <= 16); templ("multipleItemsPerSlot", _toType.storageStride() <= 16);
templ("storageStride", to_string(_toType.storageStride())); templ("storageStride", to_string(_toType.storageStride()));
templ("storageSize", _toType.baseType()->storageSize().str()); templ("storageSize", _toType.baseType()->storageSize().str());

View File

@ -11,5 +11,7 @@ contract c {
} }
} }
// ====
// compileViaYul: also
// ---- // ----
// test(uint256[2][]): 32, 3, 7, 8, 9, 10, 11, 12 -> 10 // test(uint256[2][]): 32, 3, 7, 8, 9, 10, 11, 12 -> 10

View File

@ -15,6 +15,8 @@ contract c {
data2 = data1; data2 = data1;
} }
} }
// ====
// compileViaYul: also
// ---- // ----
// test() -> 4, 5 // test() -> 4, 5
// storage: empty // storage: empty