Skip to content

Commit

Permalink
Order yul subobjects by order of reference.
Browse files Browse the repository at this point in the history
Co-authored-by: Kamil Śliwak <kamil.sliwak@codepoets.it>
  • Loading branch information
ekpyron and cameel committed Jul 16, 2024
1 parent 630f736 commit 8840e33
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
5 changes: 3 additions & 2 deletions libsolidity/codegen/ir/IRGenerationContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ class IRGenerationContext

RevertStrings revertStrings() const { return m_revertStrings; }

std::set<ContractDefinition const*, ASTNode::CompareByID>& subObjectsCreated() { return m_subObjects; }
util::UniqueVector<ContractDefinition const*> 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; }
Expand Down Expand Up @@ -195,7 +196,7 @@ class IRGenerationContext
/// It will fail at runtime but the code must still compile.
InternalDispatchMap m_internalDispatchMap;

std::set<ContractDefinition const*, ASTNode::CompareByID> m_subObjects;
util::UniqueVector<ContractDefinition const*> m_subObjects;

langutil::DebugInfoSelection m_debugInfoSelection = {};
langutil::CharStreamProvider const* m_soliditySourceProvider = nullptr;
Expand Down
4 changes: 2 additions & 2 deletions libsolidity/codegen/ir/IRGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ std::string IRGenerator::generate(
std::map<ContractDefinition const*, std::string_view const> const& _otherYulSources
)
{
auto subObjectSources = [&_otherYulSources](std::set<ContractDefinition const*, ASTNode::CompareByID> const& subObjects) -> std::string
auto subObjectSources = [&_otherYulSources](UniqueVector<ContractDefinition const*> const& _subObjects) -> std::string
{
std::string subObjectsSources;
for (ContractDefinition const* subObject: subObjects)
for (ContractDefinition const* subObject: _subObjects)
subObjectsSources += _otherYulSources.at(subObject);
return subObjectsSources;
};
Expand Down
4 changes: 2 additions & 2 deletions libsolidity/codegen/ir/IRGeneratorForStatements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1559,7 +1559,7 @@ void IRGeneratorForStatements::endVisit(FunctionCall const& _functionCall)

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

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

0 comments on commit 8840e33

Please sign in to comment.