diff --git a/libyul/optimiser/Suite.cpp b/libyul/optimiser/Suite.cpp index 4a175eb02..1a0628b00 100644 --- a/libyul/optimiser/Suite.cpp +++ b/libyul/optimiser/Suite.cpp @@ -67,6 +67,7 @@ #include +#include #include using namespace std; @@ -235,6 +236,12 @@ map const& OptimiserSuite::stepNameToAbbreviationMap() {VarDeclInitializer::name, 'd'}, }; yulAssert(lookupTable.size() == allSteps().size(), ""); + yulAssert(( + util::convertContainer>(string(NonStepAbbreviations)) - + util::convertContainer>(lookupTable | boost::adaptors::map_values) + ).size() == string(NonStepAbbreviations).size(), + "Step abbreviation conflicts with a character reserved for another syntactic element" + ); return lookupTable; } @@ -265,6 +272,10 @@ void OptimiserSuite::runSequence(string const& _stepAbbreviations, Block& _ast) insideLoop = false; break; default: + yulAssert( + string(NonStepAbbreviations).find(abbreviation) == string::npos, + "Unhandled syntactic element in the abbreviation sequence" + ); assertThrow( stepAbbreviationToNameMap().find(abbreviation) != stepAbbreviationToNameMap().end(), OptimizerException, diff --git a/libyul/optimiser/Suite.h b/libyul/optimiser/Suite.h index 3b0ed0163..e8a6c7a56 100644 --- a/libyul/optimiser/Suite.h +++ b/libyul/optimiser/Suite.h @@ -47,6 +47,10 @@ class OptimiserSuite public: static constexpr size_t MaxRounds = 12; + /// Special characters that do not represent optimiser steps but are allowed in abbreviation sequences. + /// Some of them (like whitespace) are ignored, others (like brackets) are a part of the syntax. + static constexpr char NonStepAbbreviations[] = " \n[]"; + enum class Debug { None,