From 8840e33746c26cc6398b0498b5a3ba0abc992eef Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Mon, 15 Jul 2024 17:15:11 +0200 Subject: [PATCH] Order yul subobjects by order of reference. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kamil ƚliwak --- Changelog.md | 1 + libsolidity/codegen/ir/IRGenerationContext.h | 5 +++-- libsolidity/codegen/ir/IRGenerator.cpp | 4 ++-- libsolidity/codegen/ir/IRGeneratorForStatements.cpp | 4 ++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Changelog.md b/Changelog.md index 7bffd07e1e29..bfdd45575ff7 100644 --- a/Changelog.md +++ b/Changelog.md @@ -19,6 +19,7 @@ Bugfixes: * SMTChecker: Fix formatting of unary minus expressions in invariants. * SMTChecker: Fix internal compiler error when reporting proved targets for BMC engine. * TypeChecker: Fix segfault when assigning nested tuple to tuple. + * Yul IR Code Generation: Deterministic order of Yul subobjects. * Yul Optimizer: Name simplification could lead to forbidden identifiers with a leading and/or trailing dot, e.g., ``x._`` would get simplified into ``x.``. * Yul Parser: Fix segfault when parsing very long location comments. diff --git a/libsolidity/codegen/ir/IRGenerationContext.h b/libsolidity/codegen/ir/IRGenerationContext.h index 8e03a378b302..2bf837697b47 100644 --- a/libsolidity/codegen/ir/IRGenerationContext.h +++ b/libsolidity/codegen/ir/IRGenerationContext.h @@ -143,7 +143,8 @@ class IRGenerationContext RevertStrings revertStrings() const { return m_revertStrings; } - std::set& subObjectsCreated() { return m_subObjects; } + util::UniqueVector const& subObjectsCreated() const { return m_subObjects; } + void addSubObject(ContractDefinition const* _contractDefinition) { m_subObjects.pushBack(_contractDefinition); } bool memoryUnsafeInlineAssemblySeen() const { return m_memoryUnsafeInlineAssemblySeen; } void setMemoryUnsafeInlineAssemblySeen() { m_memoryUnsafeInlineAssemblySeen = true; } @@ -195,7 +196,7 @@ class IRGenerationContext /// It will fail at runtime but the code must still compile. InternalDispatchMap m_internalDispatchMap; - std::set m_subObjects; + util::UniqueVector m_subObjects; langutil::DebugInfoSelection m_debugInfoSelection = {}; langutil::CharStreamProvider const* m_soliditySourceProvider = nullptr; diff --git a/libsolidity/codegen/ir/IRGenerator.cpp b/libsolidity/codegen/ir/IRGenerator.cpp index 93136a1a26cb..bf0f6d5c0f25 100644 --- a/libsolidity/codegen/ir/IRGenerator.cpp +++ b/libsolidity/codegen/ir/IRGenerator.cpp @@ -101,10 +101,10 @@ std::string IRGenerator::generate( std::map const& _otherYulSources ) { - auto subObjectSources = [&_otherYulSources](std::set const& subObjects) -> std::string + auto subObjectSources = [&_otherYulSources](UniqueVector const& _subObjects) -> std::string { std::string subObjectsSources; - for (ContractDefinition const* subObject: subObjects) + for (ContractDefinition const* subObject: _subObjects) subObjectsSources += _otherYulSources.at(subObject); return subObjectsSources; }; diff --git a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp index 1c212cd828c3..0579f50c2d96 100644 --- a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp +++ b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp @@ -1559,7 +1559,7 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall) ContractDefinition const* contract = &dynamic_cast(*functionType->returnParameterTypes().front()).contractDefinition(); - m_context.subObjectsCreated().insert(contract); + m_context.addSubObject(contract); Whiskers t(R"(let := () let := add(, datasize("")) @@ -1947,7 +1947,7 @@ void IRGeneratorForStatements::endVisit(MemberAccess const& _memberAccess) auto const& contractType = dynamic_cast(*arg); solAssert(!contractType.isSuper()); ContractDefinition const& contract = contractType.contractDefinition(); - m_context.subObjectsCreated().insert(&contract); + m_context.addSubObject(&contract); appendCode() << Whiskers(R"( let := datasize("") let := (add(, 32))