diff --git a/Changelog.md b/Changelog.md index 46be38d41..4fcf6e595 100644 --- a/Changelog.md +++ b/Changelog.md @@ -19,6 +19,7 @@ Bugfixes: * Code Generator: Defensively pad memory for ``type(Contract).name`` to multiples of 32. * Type System: Detect and disallow internal function pointers as parameters for public/external library functions, even when they are nested/wrapped in structs, arrays or other types. * Yul Optimizer: Properly determine whether a variable can be eliminated during stack compression pass. + * Yul / Inline Assembly Parser: Disallow more than one case statement with the same label inside a switch based on the label's integer value. Build System: diff --git a/libyul/AsmAnalysis.cpp b/libyul/AsmAnalysis.cpp index 77c98d616..33132756f 100644 --- a/libyul/AsmAnalysis.cpp +++ b/libyul/AsmAnalysis.cpp @@ -436,7 +436,7 @@ bool AsmAnalyzer::operator()(Switch const& _switch) ); } - set> cases; + set cases; for (auto const& _case: _switch.cases) { if (_case.value) @@ -450,7 +450,7 @@ bool AsmAnalyzer::operator()(Switch const& _switch) m_stackHeight--; /// Note: the parser ensures there is only one default case - if (!cases.insert(_case.value.get()).second) + if (!cases.insert(valueOfLiteral(*_case.value)).second) { m_errorReporter.declarationError( _case.location, diff --git a/test/libyul/Parser.cpp b/test/libyul/Parser.cpp index 9d24ecd91..8dc4bac36 100644 --- a/test/libyul/Parser.cpp +++ b/test/libyul/Parser.cpp @@ -384,6 +384,12 @@ BOOST_AUTO_TEST_CASE(switch_duplicate_case) BOOST_CHECK(successParse("{ switch 0:u256 case 42:u256 {} case 0x42:u256 {} }")); } +BOOST_AUTO_TEST_CASE(switch_duplicate_case_different_literal) +{ + CHECK_ERROR("{ switch 0:u256 case 0:u256 {} case \"\":u256 {} }", DeclarationError, "Duplicate case defined."); + BOOST_CHECK(successParse("{ switch 1:u256 case \"1\":u256 {} case \"2\":u256 {} }")); +} + BOOST_AUTO_TEST_CASE(builtins_parser) { struct SimpleDialect: public Dialect