From bda76a14f0e9f4b0698372115611f39e3b33d1df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Wed, 28 Jun 2023 13:52:24 +0200 Subject: [PATCH] IRGeneratorForStatements: Fix undefined order of functions when generating code for index expressions --- Changelog.md | 1 + .../codegen/ir/IRGeneratorForStatements.cpp | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Changelog.md b/Changelog.md index 2ddf6647e06b..d5062b4eb6c0 100644 --- a/Changelog.md +++ b/Changelog.md @@ -4,6 +4,7 @@ Language Features: * Allow qualified access to events from other contracts. Compiler Features: + * Code Generator: Fix not entirely deterministic order of functions in unoptimized Yul output. The choice of C++ compiler in some cases would result in different (but equivalent) bytecode (especially from native binaries vs emscripten binaries) * Commandline Interface: Add ``--ast-compact-json`` output in assembler mode. * Commandline Interface: Add ``--ir-ast-json`` and ``--ir-optimized-ast-json`` outputs for Solidity input, providing AST in compact JSON format for IR and optimized IR. * Commandline Interface: Respect ``--optimize-yul`` and ``--no-optimize-yul`` in compiler mode and accept them in assembler mode as well. ``--optimize --no-optimize-yul`` combination now allows enabling EVM assembly optimizer without enabling Yul optimizer. diff --git a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp index 509cc28c7aa7..bc8ce35d5da6 100644 --- a/libsolidity/codegen/ir/IRGeneratorForStatements.cpp +++ b/libsolidity/codegen/ir/IRGeneratorForStatements.cpp @@ -2295,13 +2295,13 @@ void IRGeneratorForStatements::endVisit(IndexAccess const& _indexAccess) } case DataLocation::Memory: { - string const memAddress = - m_utils.memoryArrayIndexAccessFunction(arrayType) + - "(" + - IRVariable(_indexAccess.baseExpression()).part("mpos").name() + - ", " + - expressionAsType(*_indexAccess.indexExpression(), *TypeProvider::uint256()) + - ")"; + string const indexAccessFunction = m_utils.memoryArrayIndexAccessFunction(arrayType); + string const baseRef = IRVariable(_indexAccess.baseExpression()).part("mpos").name(); + string const indexExpression = expressionAsType( + *_indexAccess.indexExpression(), + *TypeProvider::uint256() + ); + string const memAddress = indexAccessFunction + "(" + baseRef + ", " + indexExpression + ")"; setLValue(_indexAccess, IRLValue{ *arrayType.baseType(),