Fix: Also replace tags in the list of tags referenced from outside.

This commit is contained in:
chriseth 2019-02-20 12:10:29 +01:00
parent 03b8fcd7eb
commit 7f6f958246
3 changed files with 19 additions and 3 deletions

View File

@ -15,6 +15,7 @@ Bugfixes:
* ABIEncoderV2: Fix internal error related to mappings as library parameters. * ABIEncoderV2: Fix internal error related to mappings as library parameters.
* ABIEncoderV2: Fix invalid signature for events containing structs emitted in libraries. * ABIEncoderV2: Fix invalid signature for events containing structs emitted in libraries.
* Inline Assembly: Proper error message for missing variables. * Inline Assembly: Proper error message for missing variables.
* Optimizer: Fix internal error related to unused tag removal across assemblies. This never generated any invalid code.
* SMTChecker: Fixed crash when used with fixed-sized arrays. * SMTChecker: Fixed crash when used with fixed-sized arrays.
* Yul: Properly detect name clashes with functions before their declaration. * Yul: Properly detect name clashes with functions before their declaration.

View File

@ -390,7 +390,7 @@ Assembly& Assembly::optimise(OptimiserSettings const& _settings)
map<u256, u256> Assembly::optimiseInternal( map<u256, u256> Assembly::optimiseInternal(
OptimiserSettings const& _settings, OptimiserSettings const& _settings,
std::set<size_t> const& _tagsReferencedFromOutside std::set<size_t> _tagsReferencedFromOutside
) )
{ {
// Run optimisation for sub-assemblies. // Run optimisation for sub-assemblies.
@ -436,7 +436,22 @@ map<u256, u256> Assembly::optimiseInternal(
BlockDeduplicator dedup{m_items}; BlockDeduplicator dedup{m_items};
if (dedup.deduplicate()) if (dedup.deduplicate())
{ {
tagReplacements.insert(dedup.replacedTags().begin(), dedup.replacedTags().end()); for (auto const& replacement: dedup.replacedTags())
{
assertThrow(
replacement.first <= size_t(-1) && replacement.second <= size_t(-1),
OptimizerException,
"Invalid tag replacement."
);
assertThrow(
!tagReplacements.count(replacement.first),
OptimizerException,
"Replacement already known."
);
tagReplacements[replacement.first] = replacement.second;
if (_tagsReferencedFromOutside.erase(size_t(replacement.first)))
_tagsReferencedFromOutside.insert(size_t(replacement.second));
}
count++; count++;
} }
} }

View File

@ -154,7 +154,7 @@ protected:
/// Does the same operations as @a optimise, but should only be applied to a sub and /// Does the same operations as @a optimise, but should only be applied to a sub and
/// returns the replaced tags. Also takes an argument containing the tags of this assembly /// returns the replaced tags. Also takes an argument containing the tags of this assembly
/// that are referenced in a super-assembly. /// that are referenced in a super-assembly.
std::map<u256, u256> optimiseInternal(OptimiserSettings const& _settings, std::set<size_t> const& _tagsReferencedFromOutside); std::map<u256, u256> optimiseInternal(OptimiserSettings const& _settings, std::set<size_t> _tagsReferencedFromOutside);
unsigned bytesRequired(unsigned subTagSize) const; unsigned bytesRequired(unsigned subTagSize) const;