Do not use named function labels if function names are not unique.

This commit is contained in:
chriseth
2021-10-19 18:33:00 +02:00
parent 863a0d3b9c
commit 9f48b7419c
18 changed files with 429 additions and 7 deletions
+14 -2
View File
@@ -52,7 +52,7 @@ CodeTransform::CodeTransform(
EVMDialect const& _dialect,
BuiltinContext& _builtinContext,
ExternalIdentifierAccess::CodeGenerator _identifierAccessCodeGen,
bool _useNamedLabelsForFunctions,
UseNamedLabels _useNamedLabelsForFunctions,
shared_ptr<Context> _context,
vector<TypedName> _delayedReturnVariables,
optional<AbstractAssembly::LabelID> _functionExitLabel
@@ -405,8 +405,12 @@ void CodeTransform::operator()(FunctionDefinition const& _function)
if (!m_allowStackOpt)
subTransform.setupReturnVariablesAndFunctionExit();
subTransform.m_assignedNamedLabels = move(m_assignedNamedLabels);
subTransform(_function.body);
m_assignedNamedLabels = move(subTransform.m_assignedNamedLabels);
m_assembly.setSourceLocation(originLocationOf(_function));
if (!subTransform.m_stackErrors.empty())
{
@@ -585,8 +589,16 @@ void CodeTransform::createFunctionEntryID(FunctionDefinition const& _function)
if (_function.debugData)
astID = _function.debugData->astID;
bool nameAlreadySeen = !m_assignedNamedLabels.insert(_function.name).second;
if (m_useNamedLabelsForFunctions == UseNamedLabels::YesAndForceUnique)
yulAssert(!nameAlreadySeen);
m_context->functionEntryIDs[&scopeFunction] =
m_useNamedLabelsForFunctions ?
(
m_useNamedLabelsForFunctions != UseNamedLabels::Never &&
!nameAlreadySeen
) ?
m_assembly.namedLabel(
_function.name.str(),
_function.parameters.size(),