Skip to content

Commit b99da11

Browse files
committed
Order yul subobjects by order of reference.
1 parent e0ab0f2 commit b99da11

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Compiler Features:
1515

1616

1717
Bugfixes:
18+
* Yul IR Code Generation: Deterministic order of Yul subobjects.
1819
* SMTChecker: Fix error that reports invalid number of verified checks for BMC and CHC engines.
1920
* SMTChecker: Fix formatting of unary minus expressions in invariants.
2021
* SMTChecker: Fix internal compiler error when reporting proved targets for BMC engine.

libsolidity/codegen/ir/IRGenerationContext.h

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

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

146-
std::set<ContractDefinition const*, ASTNode::CompareByID>& subObjectsCreated() { return m_subObjects; }
146+
std::vector<ContractDefinition const*> const& subObjectsCreated() { return m_subObjects; }
147+
void addSubObject(ContractDefinition const* _contractDefinition)
148+
{
149+
if (!util::contains(m_subObjects, _contractDefinition))
150+
m_subObjects.emplace_back(_contractDefinition);
151+
}
147152

148153
bool memoryUnsafeInlineAssemblySeen() const { return m_memoryUnsafeInlineAssemblySeen; }
149154
void setMemoryUnsafeInlineAssemblySeen() { m_memoryUnsafeInlineAssemblySeen = true; }
@@ -195,7 +200,7 @@ class IRGenerationContext
195200
/// It will fail at runtime but the code must still compile.
196201
InternalDispatchMap m_internalDispatchMap;
197202

198-
std::set<ContractDefinition const*, ASTNode::CompareByID> m_subObjects;
203+
std::vector<ContractDefinition const*> m_subObjects;
199204

200205
langutil::DebugInfoSelection m_debugInfoSelection = {};
201206
langutil::CharStreamProvider const* m_soliditySourceProvider = nullptr;

libsolidity/codegen/ir/IRGenerator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ 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](std::vector<ContractDefinition const*> const& subObjects) -> std::string
105105
{
106106
std::string subObjectsSources;
107107
for (ContractDefinition const* subObject: subObjects)

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)