From 73cd009b8914bad0a6dfda84339be1d41b429c42 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Thu, 11 Jun 2020 12:10:33 +0200 Subject: [PATCH] Fix struct allocation in Sol->Yul. --- libsolidity/codegen/YulUtilFunctions.cpp | 3 +-- .../viaYul/memory_struct_allow.sol | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 test/libsolidity/semanticTests/viaYul/memory_struct_allow.sol diff --git a/libsolidity/codegen/YulUtilFunctions.cpp b/libsolidity/codegen/YulUtilFunctions.cpp index 87142099e..f7d9711a2 100644 --- a/libsolidity/codegen/YulUtilFunctions.cpp +++ b/libsolidity/codegen/YulUtilFunctions.cpp @@ -1652,8 +1652,7 @@ string YulUtilFunctions::allocateAndInitializeMemoryStructFunction(StructType co return m_functionCollector.createFunction(functionName, [&]() { Whiskers templ(R"( function () -> memPtr { - let allocSize := () - memPtr := (allocSize) + memPtr := () let offset := memPtr <#member> mstore(offset, ()) diff --git a/test/libsolidity/semanticTests/viaYul/memory_struct_allow.sol b/test/libsolidity/semanticTests/viaYul/memory_struct_allow.sol new file mode 100644 index 000000000..b1af4fab8 --- /dev/null +++ b/test/libsolidity/semanticTests/viaYul/memory_struct_allow.sol @@ -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