Skip to content

Commit 8455f15

Browse files
committed
IRGeneratorForStatements does not check for builtin when mangling user identifiers
1 parent a652292 commit 8455f15

File tree

2 files changed

+11
-21
lines changed

2 files changed

+11
-21
lines changed

Diff for: libsolidity/codegen/ir/IRGeneratorForStatements.cpp

+8-13
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ struct CopyTranslate: public yul::ASTCopier
6363
{
6464
using ExternalRefsMap = std::map<yul::Identifier const*, InlineAssemblyAnnotation::ExternalIdentifierInfo>;
6565

66-
CopyTranslate(yul::Dialect const& _dialect, IRGenerationContext& _context, ExternalRefsMap const& _references):
67-
m_dialect(_dialect), m_context(_context), m_references(_references) {}
66+
CopyTranslate(IRGenerationContext& _context, ExternalRefsMap const& _references):
67+
m_context(_context), m_references(_references) {}
6868

6969
using ASTCopier::operator();
7070

@@ -80,14 +80,11 @@ struct CopyTranslate: public yul::ASTCopier
8080

8181
yul::YulName translateIdentifier(yul::YulName _name) override
8282
{
83-
// Strictly, the dialect used by inline assembly (m_dialect) could be different
84-
// from the Yul dialect we are compiling to. So we are assuming here that the builtin
85-
// functions are identical. This should not be a problem for now since everything
86-
// is EVM anyway.
87-
if (m_dialect.findBuiltin(_name.str()))
88-
return _name;
89-
else
90-
return yul::YulName{"usr$" + _name.str()};
83+
// Strictly, the dialect used by inline assembly could be different
84+
// from the Yul dialect we are compiling to. By only translating `YulName`s which correspond to Identifiers,
85+
// we are implicitly excluding builtins together with the assumption, that numerical builtin handles
86+
// stay identical. Special care has to be taken, that these numerical handles stay consistent.
87+
return yul::YulName{"usr$" + _name.str()};
9188
}
9289

9390
yul::Identifier translate(yul::Identifier const& _identifier) override
@@ -209,8 +206,6 @@ struct CopyTranslate: public yul::ASTCopier
209206
return yul::Identifier{_identifier.debugData, yul::YulName{value}};
210207
}
211208

212-
213-
yul::Dialect const& m_dialect;
214209
IRGenerationContext& m_context;
215210
ExternalRefsMap const& m_references;
216211
};
@@ -2294,7 +2289,7 @@ bool IRGeneratorForStatements::visit(InlineAssembly const& _inlineAsm)
22942289
setLocation(_inlineAsm);
22952290
if (*_inlineAsm.annotation().hasMemoryEffects && !_inlineAsm.annotation().markedMemorySafe)
22962291
m_context.setMemoryUnsafeInlineAssemblySeen();
2297-
CopyTranslate bodyCopier{_inlineAsm.dialect(), m_context, _inlineAsm.annotation().externalReferences};
2292+
CopyTranslate bodyCopier{m_context, _inlineAsm.annotation().externalReferences};
22982293

22992294
yul::Statement modified = bodyCopier(_inlineAsm.operations().root());
23002295

Diff for: libsolidity/experimental/codegen/IRGeneratorForStatements.cpp

+3-8
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,8 @@ struct CopyTranslate: public yul::ASTCopier
5454
{
5555
CopyTranslate(
5656
IRGenerationContext const& _context,
57-
yul::Dialect const& _dialect,
5857
std::map<yul::Identifier const*, InlineAssemblyAnnotation::ExternalIdentifierInfo> _references
59-
): m_context(_context), m_dialect(_dialect), m_references(std::move(_references)) {}
58+
): m_context(_context), m_references(std::move(_references)) {}
6059

6160
using ASTCopier::operator();
6261

@@ -72,10 +71,7 @@ struct CopyTranslate: public yul::ASTCopier
7271

7372
yul::YulName translateIdentifier(yul::YulName _name) override
7473
{
75-
if (m_dialect.findBuiltin(_name.str()))
76-
return _name;
77-
else
78-
return yul::YulName{"usr$" + _name.str()};
74+
return yul::YulName{"usr$" + _name.str()};
7975
}
8076

8177
yul::Identifier translate(yul::Identifier const& _identifier) override
@@ -106,7 +102,6 @@ struct CopyTranslate: public yul::ASTCopier
106102
}
107103

108104
IRGenerationContext const& m_context;
109-
yul::Dialect const& m_dialect;
110105
std::map<yul::Identifier const*, InlineAssemblyAnnotation::ExternalIdentifierInfo> m_references;
111106
};
112107

@@ -129,7 +124,7 @@ bool IRGeneratorForStatements::visit(TupleExpression const& _tupleExpression)
129124

130125
bool IRGeneratorForStatements::visit(InlineAssembly const& _assembly)
131126
{
132-
CopyTranslate bodyCopier{m_context, _assembly.dialect(), _assembly.annotation().externalReferences};
127+
CopyTranslate bodyCopier{m_context, _assembly.annotation().externalReferences};
133128
yul::Statement modified = bodyCopier(_assembly.operations().root());
134129
solAssert(std::holds_alternative<yul::Block>(modified));
135130
m_code << yul::AsmPrinter(_assembly.dialect())(std::get<yul::Block>(modified)) << "\n";

0 commit comments

Comments
 (0)