3030using namespace solidity ::yul;
3131using namespace std ;
3232
33+ namespace
34+ {
35+ class AreFunctionNamesUnique : ASTWalker
36+ {
37+ public:
38+ static bool check (Block& _block)
39+ {
40+ AreFunctionNamesUnique instance;
41+ instance (_block);
42+ return instance.m_unique ;
43+ }
44+ private:
45+ using ASTWalker::operator ();
46+ void operator ()(FunctionDefinition const & _functionDefinition) override
47+ {
48+ ASTWalker::operator ()(_functionDefinition);
49+ if (!m_functionNames.insert (_functionDefinition.name ).second )
50+ m_unique = false ;
51+ }
52+ bool m_unique = true ;
53+ std::set<YulString> m_functionNames;
54+ };
55+ }
56+
3357void EVMObjectCompiler::compile (Object& _object, AbstractAssembly& _assembly, EVMDialect const & _dialect, bool _optimize)
3458{
3559 EVMObjectCompiler compiler (_assembly, _dialect);
@@ -62,6 +86,10 @@ void EVMObjectCompiler::run(Object& _object, bool _optimize)
6286
6387 yulAssert (_object.analysisInfo , " No analysis info." );
6488 yulAssert (_object.code , " No code." );
89+
90+ // We cannot use named labels if the function names are not unique.
91+ bool useNamedLabelsForFunctions = AreFunctionNamesUnique::check (*_object.code );
92+
6593 // We do not catch and re-throw the stack too deep exception here because it is a YulException,
6694 // which should be native to this part of the code.
6795 CodeTransform transform{
@@ -72,7 +100,7 @@ void EVMObjectCompiler::run(Object& _object, bool _optimize)
72100 context,
73101 _optimize,
74102 {},
75- true /* _useNamedLabelsForFunctions */
103+ useNamedLabelsForFunctions
76104 };
77105 transform (*_object.code );
78106 if (!transform.stackErrors ().empty ())
0 commit comments