Skip to content

Commit 9d7e5ae

Browse files
ekpyronnikola-matic
authored andcommitted
Do not duplicate subassemblies.
1 parent e48d495 commit 9d7e5ae

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

libevmasm/Assembly.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -679,13 +679,22 @@ LinkerObject const& Assembly::assemble() const
679679
// Append an INVALID here to help tests find miscompilation.
680680
ret.bytecode.push_back(static_cast<uint8_t>(Instruction::INVALID));
681681

682-
for (auto const& [subIdPath, bytecodeOffset]: subRef)
683682
{
684-
bytesRef r(ret.bytecode.data() + bytecodeOffset, bytesPerDataRef);
685-
toBigEndian(ret.bytecode.size(), r);
686-
ret.append(subAssemblyById(subIdPath)->assemble());
683+
std::map<Assembly const*, size_t> subAssemblyOffsets;
684+
for (auto const& [subIdPath, bytecodeOffset]: subRef)
685+
{
686+
Assembly const* subAssembly = subAssemblyById(subIdPath);
687+
bytesRef r(ret.bytecode.data() + bytecodeOffset, bytesPerDataRef);
688+
if (size_t* subAssemblyOffset = util::valueOrNullptr(subAssemblyOffsets, subAssembly))
689+
toBigEndian(*subAssemblyOffset, r);
690+
else
691+
{
692+
toBigEndian(ret.bytecode.size(), r);
693+
subAssemblyOffsets[subAssembly] = ret.bytecode.size();
694+
ret.append(subAssembly->assemble());
695+
}
696+
}
687697
}
688-
689698
for (auto const& i: tagRef)
690699
{
691700
size_t subId;

test/libsolidity/semanticTests/functionCall/failed_create.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ contract C {
1717
// EVMVersion: >=byzantium
1818
// ----
1919
// constructor(), 20 wei
20-
// gas irOptimized: 184005
20+
// gas irOptimized: 179697
2121
// gas legacy: 294335
2222
// gas legacyOptimized: 173427
2323
// f(uint256): 20 -> 0x137aa4dfc0911524504fcd4d98501f179bc13b4a

0 commit comments

Comments
 (0)