Skip to content

Commit 51ef6a6

Browse files
chrisethekpyron
authored andcommitted
Fix removal of memory stores in inline assembly blocks.
1 parent 14cdb76 commit 51ef6a6

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

Changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
### 0.8.15 (unreleased)
22

3+
Important Bugfixes:
4+
* Yul Optimizer: Keep all memory side-effects of inline assembly blocks.
5+
6+
37
Language Features:
48
* Add `E.selector` for a non-anonymous event `E` to access the 32-byte selector topic.
59
* Errors and Events allow qualified access from other contracts.

libsolidity/codegen/CompilerContext.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ void CompilerContext::appendInlineAssembly(
485485
obj.code = parserResult;
486486
obj.analysisInfo = make_shared<yul::AsmAnalysisInfo>(analysisInfo);
487487

488+
solAssert(!dialect.providesObjectAccess());
488489
optimizeYul(obj, dialect, _optimiserSettings, externallyUsedIdentifiers);
489490

490491
if (_system)

libyul/optimiser/UnusedStoreEliminator.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#include <libyul/ControlFlowSideEffectsCollector.h>
3232
#include <libyul/AST.h>
3333

34+
#include <libyul/backends/evm/EVMDialect.h>
35+
3436
#include <libsolutil/CommonData.h>
3537

3638
#include <libevmasm/Instruction.h>
@@ -76,7 +78,13 @@ void UnusedStoreEliminator::run(OptimiserStepContext& _context, Block& _ast)
7678
ignoreMemory
7779
};
7880
rse(_ast);
79-
rse.changeUndecidedTo(State::Unused, Location::Memory);
81+
if (
82+
auto evmDialect = dynamic_cast<EVMDialect const*>(&_context.dialect);
83+
evmDialect && evmDialect->providesObjectAccess()
84+
)
85+
rse.changeUndecidedTo(State::Unused, Location::Memory);
86+
else
87+
rse.changeUndecidedTo(State::Used, Location::Memory);
8088
rse.changeUndecidedTo(State::Used, Location::Storage);
8189
rse.scheduleUnusedForDeletion();
8290

test/libsolidity/semanticTests/array/pop/byte_array_pop_long_storage_empty_garbage_ref.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ contract c {
1717
// test() ->
1818
// gas irOptimized: 142639
1919
// gas legacy: 164430
20-
// gas legacyOptimized: 157898
20+
// gas legacyOptimized: 158513
2121
// storageEmpty -> 1

0 commit comments

Comments
 (0)