mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #9183 from ethereum/yulFixStructAlloc
Fix memory struct allocation in Sol->Yul.
This commit is contained in:
commit
365a3fcbc2
@ -1652,8 +1652,7 @@ string YulUtilFunctions::allocateAndInitializeMemoryStructFunction(StructType co
|
|||||||
return m_functionCollector.createFunction(functionName, [&]() {
|
return m_functionCollector.createFunction(functionName, [&]() {
|
||||||
Whiskers templ(R"(
|
Whiskers templ(R"(
|
||||||
function <functionName>() -> memPtr {
|
function <functionName>() -> memPtr {
|
||||||
let allocSize := <allocSize>()
|
memPtr := <alloc>(<allocSize>)
|
||||||
memPtr := <alloc>(allocSize)
|
|
||||||
let offset := memPtr
|
let offset := memPtr
|
||||||
<#member>
|
<#member>
|
||||||
mstore(offset, <zeroValue>())
|
mstore(offset, <zeroValue>())
|
||||||
|
@ -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
|
Loading…
Reference in New Issue
Block a user