Skip to content

Commit 4e281a7

Browse files
authored
Escape object/data names in Yul serializer (#16517)
1 parent 2aad0a7 commit 4e281a7

File tree

6 files changed

+30
-2
lines changed

6 files changed

+30
-2
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Compiler Features:
1313
* Yul Optimizer: Improve performance of control flow side effects collector and function references resolver.
1414

1515
Bugfixes:
16+
* Yul: Fix incorrect serialization of Yul object names containing double quotes and escape sequences, producing output that could not be parsed as valid Yul.
1617
* Yul EVM Code Transform: Improve stack shuffler performance by fixing a BFS deduplication issue.
1718

1819

libyul/Object.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ using namespace solidity::yul;
4040

4141
std::string Data::toString(DebugInfoSelection const&, CharStreamProvider const*) const
4242
{
43-
return "data \"" + name + "\" hex\"" + util::toHex(data) + "\"";
43+
return "data " + util::escapeAndQuoteString(name) + " hex\"" + util::toHex(data) + "\"";
4444
}
4545

4646
std::string Object::toString(
@@ -64,7 +64,7 @@ std::string Object::toString(
6464

6565
return
6666
debugData->formatUseSrcComment() +
67-
"object \"" + name + "\" {\n" +
67+
"object " + util::escapeAndQuoteString(name) + " {\n" +
6868
indent(inner) + "\n" +
6969
"}";
7070
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
object "A" {
2+
code {
3+
sstore(0, datasize("B\nC"))
4+
}
5+
data "B
6+
C" hex"1234"
7+
}
8+
// ----
9+
// ParserError 2314: (65-67): Expected 'StringLiteral' but got 'ILLEGAL'
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
object "a" {
2+
code {
3+
pop(datasize("my\"data"))
4+
}
5+
data "my\"data" hex"deadbeef"
6+
}
7+
// ----
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
object "outer" {
2+
code {
3+
pop(datasize("a\\b\"c\nd\re\tf\x01g"))
4+
}
5+
data "a\\b\"c\nd\re\tf\x01g" hex"deadbeef"
6+
}
7+
// ----
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
object "3\"{code{}}e0003" {
2+
code { {} }
3+
}
4+
// ----

0 commit comments

Comments
 (0)