Merge pull request #9183 from ethereum/yulFixStructAlloc

Fix memory struct allocation in Sol->Yul.
This commit is contained in:
chriseth 2020-06-11 13:08:27 +02:00 committed by GitHub
commit 365a3fcbc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 2 deletions

View File

@ -1652,8 +1652,7 @@ string YulUtilFunctions::allocateAndInitializeMemoryStructFunction(StructType co
return m_functionCollector.createFunction(functionName, [&]() {
Whiskers templ(R"(
function <functionName>() -> memPtr {
let allocSize := <allocSize>()
memPtr := <alloc>(allocSize)
memPtr := <alloc>(<allocSize>)
let offset := memPtr
<#member>
mstore(offset, <zeroValue>())

View File

@ -0,0 +1,21 @@
contract C {
struct S {
uint256 a;
uint256 b;
}
function f() public pure returns (uint256 a, uint256 b){
assembly {
// Make free memory dirty to check that the struct allocation cleans it up again.
let freeMem := mload(0x40)
mstore(freeMem, 42)
mstore(add(freeMem, 32), 42)
}
S memory s;
return (s.a, s.b);
}
}
// ====
// compileViaYul: also
// ----
// f() -> 0, 0