Skip to content

Commit 085ca40

Browse files
authored
Merge pull request #11621 from ethereum/fixSourceLocationOfBuiltins
Fix source location of builtin function calls.
2 parents 09578e7 + 8d5e82b commit 085ca40

File tree

28 files changed

+81
-60
lines changed

28 files changed

+81
-60
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Bugfixes:
1616
* Code Generator: Fix internal compiler error when passing a 32-byte hex literal or a zero literal to ``bytes.concat()`` by disallowing such literals.
1717
* Type Checker: Fix internal error and prevent static calls to unimplemented modifiers.
1818
* Yul Code Generator: Fix internal compiler error when using a long literal with bitwise negation.
19+
* Yul Code Generator: Fix source location references for calls to builtin functions.
1920

2021

2122
### 0.8.6 (2021-06-22)

libyul/backends/evm/EVMCodeTransform.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,16 +237,14 @@ void CodeTransform::operator()(FunctionCall const& _call)
237237
{
238238
yulAssert(m_scope, "");
239239

240+
m_assembly.setSourceLocation(extractSourceLocationFromDebugData(_call.debugData));
240241
if (BuiltinFunctionForEVM const* builtin = m_dialect.builtin(_call.functionName.name))
241242
builtin->generateCode(_call, m_assembly, m_builtinContext, [&](Expression const& _expression) {
242243
visitExpression(_expression);
243244
});
244245
else
245246
{
246-
m_assembly.setSourceLocation(extractSourceLocationFromDebugData(_call.debugData));
247-
AbstractAssembly::LabelID returnLabel(numeric_limits<AbstractAssembly::LabelID>::max()); // only used for evm 1.0
248-
249-
returnLabel = m_assembly.newLabelId();
247+
AbstractAssembly::LabelID returnLabel = m_assembly.newLabelId();
250248
m_assembly.appendLabelReference(returnLabel);
251249

252250
Scope::Function* function = nullptr;
@@ -320,8 +318,6 @@ void CodeTransform::operator()(If const& _if)
320318

321319
void CodeTransform::operator()(Switch const& _switch)
322320
{
323-
//@TODO use JUMPV in EVM1.5?
324-
325321
visitExpression(*_switch.expression);
326322
int expressionHeight = m_assembly.stackHeight();
327323
map<Case const*, AbstractAssembly::LabelID> caseBodies;
@@ -416,6 +412,8 @@ void CodeTransform::operator()(FunctionDefinition const& _function)
416412
subTransform.setupReturnVariablesAndFunctionExit();
417413

418414
subTransform(_function.body);
415+
416+
m_assembly.setSourceLocation(extractSourceLocationFromDebugData(_function.debugData));
419417
if (!subTransform.m_stackErrors.empty())
420418
{
421419
m_assembly.markAsInvalid();

libyul/backends/evm/EVMDialect.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ map<YulString, BuiltinFunctionForEVM> createBuiltins(langutil::EVMVersion _evmVe
163163
) {
164164
yulAssert(_call.arguments.size() == 1, "");
165165
Expression const& arg = _call.arguments.front();
166+
_assembly.setSourceLocation(_call.debugData->location);
166167
_assembly.appendLinkerSymbol(std::get<Literal>(arg).value.str());
167168
}));
168169

@@ -192,6 +193,7 @@ map<YulString, BuiltinFunctionForEVM> createBuiltins(langutil::EVMVersion _evmVe
192193
yulAssert(_call.arguments.size() == 1, "");
193194
Expression const& arg = _call.arguments.front();
194195
YulString dataName = std::get<Literal>(arg).value;
196+
_assembly.setSourceLocation(_call.debugData->location);
195197
if (_context.currentObject->name == dataName)
196198
_assembly.appendAssemblySize();
197199
else
@@ -214,6 +216,7 @@ map<YulString, BuiltinFunctionForEVM> createBuiltins(langutil::EVMVersion _evmVe
214216
yulAssert(_call.arguments.size() == 1, "");
215217
Expression const& arg = _call.arguments.front();
216218
YulString dataName = std::get<Literal>(arg).value;
219+
_assembly.setSourceLocation(_call.debugData->location);
217220
if (_context.currentObject->name == dataName)
218221
_assembly.appendConstant(0);
219222
else
@@ -276,6 +279,7 @@ map<YulString, BuiltinFunctionForEVM> createBuiltins(langutil::EVMVersion _evmVe
276279
std::function<void(Expression const&)>
277280
) {
278281
yulAssert(_call.arguments.size() == 1, "");
282+
_assembly.setSourceLocation(_call.debugData->location);
279283
_assembly.appendImmutable(std::get<Literal>(_call.arguments.front()).value.str());
280284
}
281285
));
@@ -382,6 +386,8 @@ BuiltinFunctionForEVM const* EVMDialect::verbatimFunction(size_t _arguments, siz
382386
for (Expression const& arg: _call.arguments | ranges::views::tail | ranges::views::reverse)
383387
_visitExpression(arg);
384388
Expression const& bytecode = _call.arguments.front();
389+
390+
_assembly.setSourceLocation(_call.debugData->location);
385391
_assembly.appendVerbatim(
386392
asBytes(std::get<Literal>(bytecode).value.str()),
387393
_arguments,

test/cmdlineTests/linking_strict_assembly/output

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Binary representation:
1414
7312345678901234567890123456789012345678908060005550
1515

1616
Text representation:
17+
/* "linking_strict_assembly/input.yul":44:79 */
1718
linkerSymbol("f919ba91ac99f96129544b80b9516b27a80e376b9dc693819d0b18b7e0395612")
1819
/* "linking_strict_assembly/input.yul":98:102 */
1920
dup1

test/cmdlineTests/linking_strict_assembly_no_file_name_in_link_reference/output

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Binary representation:
1414
7312345678901234567890123456789012345678908060005550
1515

1616
Text representation:
17+
/* "linking_strict_assembly_no_file_name_in_link_reference/input.yul":44:61 */
1718
linkerSymbol("8aa64f937099b65a4febc243a5ae0f2d6416bb9e473c30dd29c1ee498fb7c5a8")
1819
/* "linking_strict_assembly_no_file_name_in_link_reference/input.yul":80:84 */
1920
dup1

test/cmdlineTests/linking_strict_assembly_same_library_name_different_files/output

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ Binary representation:
1616
73111111111111111111111111111111111111111173222222222222222222222222222222222222222281600055806001555050
1717

1818
Text representation:
19+
/* "linking_strict_assembly_same_library_name_different_files/input.yul":45:75 */
1920
linkerSymbol("f3ffc10c396a7cc41ae954b050792839d20947bf73497d30c49a9fda1ea477ec")
20-
/* "linking_strict_assembly_same_library_name_different_files/input.yul":32:75 */
21+
/* "linking_strict_assembly_same_library_name_different_files/input.yul":97:127 */
2122
linkerSymbol("c3523432985587641d17c68161d2f700c57aaf4ed21cda4f25d76193c831f97f")
2223
/* "linking_strict_assembly_same_library_name_different_files/input.yul":146:151 */
2324
dup2

test/cmdlineTests/linking_strict_assembly_same_library_name_different_files_in_link_references/output

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ Binary representation:
1616
73123456789012345678901234567890123456789073__$c3523432985587641d17c68161d2f700c5$__81600055806001555050
1717

1818
Text representation:
19+
/* "linking_strict_assembly_same_library_name_different_files_in_link_references/input.yul":45:75 */
1920
linkerSymbol("f3ffc10c396a7cc41ae954b050792839d20947bf73497d30c49a9fda1ea477ec")
20-
/* "linking_strict_assembly_same_library_name_different_files_in_link_references/input.yul":32:75 */
21+
/* "linking_strict_assembly_same_library_name_different_files_in_link_references/input.yul":97:127 */
2122
linkerSymbol("c3523432985587641d17c68161d2f700c57aaf4ed21cda4f25d76193c831f97f")
2223
/* "linking_strict_assembly_same_library_name_different_files_in_link_references/input.yul":146:151 */
2324
dup2

test/cmdlineTests/linking_strict_assembly_unresolved_references/output

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ Binary representation:
1616
73123456789012345678901234567890123456789073__$fb58009a6b1ecea3b9d99bedd645df4ec3$__81600055806001555050
1717

1818
Text representation:
19+
/* "linking_strict_assembly_unresolved_references/input.yul":45:81 */
1920
linkerSymbol("05b0326038374a21e0895480a58bda0768cdcc04c8d18f154362d1ca5223d245")
20-
/* "linking_strict_assembly_unresolved_references/input.yul":32:81 */
21+
/* "linking_strict_assembly_unresolved_references/input.yul":103:139 */
2122
linkerSymbol("fb58009a6b1ecea3b9d99bedd645df4ec308f17bc0087e5f39d078f77f809177")
2223
/* "linking_strict_assembly_unresolved_references/input.yul":158:163 */
2324
dup2

test/cmdlineTests/object_compiler/output

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ Text representation:
3232
0x00
3333
/* "object_compiler/input.yul":118:137 */
3434
sstore
35-
dataSize(sub_0)
3635
/* "object_compiler/input.yul":240:259 */
36+
dataSize(sub_0)
3737
dup1
38+
/* "object_compiler/input.yul":217:238 */
3839
dataOffset(sub_0)
3940
/* "object_compiler/input.yul":125:126 */
4041
0x00

test/cmdlineTests/optimizer_inliner_dynamic_reference/output

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ sub_0: assembly {
194194
/* "#utility.yul":406:415 */
195195
add
196196
swap1
197-
/* "#utility.yul":244:421 */
197+
/* "#utility.yul":196:421 */
198198
jump // out
199199
/* "#utility.yul":426:553 */
200200
tag_26:

0 commit comments

Comments
 (0)