30
30
using namespace solidity ::yul;
31
31
using namespace std ;
32
32
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
+
33
57
void EVMObjectCompiler::compile (Object& _object, AbstractAssembly& _assembly, EVMDialect const & _dialect, bool _optimize)
34
58
{
35
59
EVMObjectCompiler compiler (_assembly, _dialect);
@@ -62,6 +86,10 @@ void EVMObjectCompiler::run(Object& _object, bool _optimize)
62
86
63
87
yulAssert (_object.analysisInfo , " No analysis info." );
64
88
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
+
65
93
// We do not catch and re-throw the stack too deep exception here because it is a YulException,
66
94
// which should be native to this part of the code.
67
95
CodeTransform transform{
@@ -72,7 +100,7 @@ void EVMObjectCompiler::run(Object& _object, bool _optimize)
72
100
context,
73
101
_optimize,
74
102
{},
75
- true /* _useNamedLabelsForFunctions */
103
+ useNamedLabelsForFunctions
76
104
};
77
105
transform (*_object.code );
78
106
if (!transform.stackErrors ().empty ())
0 commit comments