Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8840e33

Browse files
ekpyroncameel
andcommitted
Order yul subobjects by order of reference.
Co-authored-by: Kamil Śliwak <[email protected]>
1 parent 630f736 commit 8840e33

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Bugfixes:
1919
* SMTChecker: Fix formatting of unary minus expressions in invariants.
2020
* SMTChecker: Fix internal compiler error when reporting proved targets for BMC engine.
2121
* TypeChecker: Fix segfault when assigning nested tuple to tuple.
22+
* Yul IR Code Generation: Deterministic order of Yul subobjects.
2223
* Yul Optimizer: Name simplification could lead to forbidden identifiers with a leading and/or trailing dot, e.g., ``x._`` would get simplified into ``x.``.
2324
* Yul Parser: Fix segfault when parsing very long location comments.
2425

libsolidity/codegen/ir/IRGenerationContext.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ class IRGenerationContext
143143

144144
RevertStrings revertStrings() const { return m_revertStrings; }
145145

146-
std::set<ContractDefinition const*, ASTNode::CompareByID>& subObjectsCreated() { return m_subObjects; }
146+
util::UniqueVector<ContractDefinition const*> const& subObjectsCreated() const { return m_subObjects; }
147+
void addSubObject(ContractDefinition const* _contractDefinition) { m_subObjects.pushBack(_contractDefinition); }
147148

148149
bool memoryUnsafeInlineAssemblySeen() const { return m_memoryUnsafeInlineAssemblySeen; }
149150
void setMemoryUnsafeInlineAssemblySeen() { m_memoryUnsafeInlineAssemblySeen = true; }
@@ -195,7 +196,7 @@ class IRGenerationContext
195196
/// It will fail at runtime but the code must still compile.
196197
InternalDispatchMap m_internalDispatchMap;
197198

198-
std::set<ContractDefinition const*, ASTNode::CompareByID> m_subObjects;
199+
util::UniqueVector<ContractDefinition const*> m_subObjects;
199200

200201
langutil::DebugInfoSelection m_debugInfoSelection = {};
201202
langutil::CharStreamProvider const* m_soliditySourceProvider = nullptr;

libsolidity/codegen/ir/IRGenerator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ std::string IRGenerator::generate(
101101
std::map<ContractDefinition const*, std::string_view const> const& _otherYulSources
102102
)
103103
{
104-
auto subObjectSources = [&_otherYulSources](std::set<ContractDefinition const*, ASTNode::CompareByID> const& subObjects) -> std::string
104+
auto subObjectSources = [&_otherYulSources](UniqueVector<ContractDefinition const*> const& _subObjects) -> std::string
105105
{
106106
std::string subObjectsSources;
107-
for (ContractDefinition const* subObject: subObjects)
107+
for (ContractDefinition const* subObject: _subObjects)
108108
subObjectsSources += _otherYulSources.at(subObject);
109109
return subObjectsSources;
110110
};

libsolidity/codegen/ir/IRGeneratorForStatements.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,7 +1559,7 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall)
15591559

15601560
ContractDefinition const* contract =
15611561
&dynamic_cast<ContractType const&>(*functionType->returnParameterTypes().front()).contractDefinition();
1562-
m_context.subObjectsCreated().insert(contract);
1562+
m_context.addSubObject(contract);
15631563

15641564
Whiskers t(R"(let <memPos> := <allocateUnbounded>()
15651565
let <memEnd> := add(<memPos>, datasize("<object>"))
@@ -1947,7 +1947,7 @@ void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess)
19471947
auto const& contractType = dynamic_cast<ContractType const&>(*arg);
19481948
solAssert(!contractType.isSuper());
19491949
ContractDefinition const& contract = contractType.contractDefinition();
1950-
m_context.subObjectsCreated().insert(&contract);
1950+
m_context.addSubObject(&contract);
19511951
appendCode() << Whiskers(R"(
19521952
let <size> := datasize("<objectName>")
19531953
let <result> := <allocationFunction>(add(<size>, 32))

0 commit comments

Comments
 (0)