Skip to content

Commit

Permalink
Make name clash with a Yul builtin a non-fatal error
Browse files Browse the repository at this point in the history
  • Loading branch information
cameel committed Jan 22, 2025
1 parent 314c27b commit edb6783
Show file tree
Hide file tree
Showing 19 changed files with 34 additions and 4 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Language Features:
Compiler Features:
* Error Reporting: Errors reported during code generation now point at the location of the contract when more fine-grained location is not available.
* SMTChecker: Z3 is now a runtime dependency, not a build dependency (except for emscripten build).
* Yul Parser: Make name clash with a builtin a non-fatal error.


Bugfixes:
Expand Down
8 changes: 7 additions & 1 deletion libyul/AsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,13 @@ YulName Parser::expectAsmIdentifier()
{
YulName name{currentLiteral()};
if (currentToken() == Token::Identifier && m_dialect.findBuiltin(name.str()))
fatalParserError(5568_error, "Cannot use builtin function name \"" + name.str() + "\" as identifier name.");
// Non-fatal. We'll continue and wrongly parse it as an identifier. May lead to some spurious
// errors after this point, but likely also much more useful ones.
m_errorReporter.parserError(
5568_error,
currentLocation(),
"Cannot use builtin function name \"" + name.str() + "\" as identifier name."
);
// NOTE: We keep the expectation here to ensure the correct source location for the error above.
expectToken(Token::Identifier);
return name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ contract C {
// EVMVersion: =london
// ----
// ParserError 5568: (98-105): Cannot use builtin function name "basefee" as identifier name.
// ParserError 7104: (137-144): Builtin function "basefee" must be called.
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ contract C {
// EVMVersion: >=cancun
// ----
// ParserError 5568: (98-109): Cannot use builtin function name "blobbasefee" as identifier name.
// ParserError 7104: (141-152): Builtin function "blobbasefee" must be called.
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ contract C {
}
// ----
// ParserError 5568: (245-248): Cannot use builtin function name "add" as identifier name.
// ParserError 5568: (249-255): Cannot use builtin function name "mstore" as identifier name.
// ParserError 5568: (260-266): Cannot use builtin function name "sstore" as identifier name.
// ParserError 5568: (286-294): Cannot use builtin function name "coinbase" as identifier name.
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ contract C {
// EVMVersion: <paris
// ----
// ParserError 5568: (101-111): Cannot use builtin function name "difficulty" as identifier name.
// ParserError 7104: (143-153): Builtin function "difficulty" must be called.
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ contract C {
// EVMVersion: >=cancun
// ----
// ParserError 5568: (101-106): Cannot use builtin function name "mcopy" as identifier name.
// ParserError 7104: (134-139): Builtin function "mcopy" must be called.
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ contract C {
// EVMVersion: >=paris
// ----
// ParserError 5568: (101-111): Cannot use builtin function name "prevrandao" as identifier name.
// ParserError 7104: (143-153): Builtin function "prevrandao" must be called.
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ contract C {
// EVMVersion: >=cancun
// ----
// ParserError 5568: (98-103): Cannot use builtin function name "tload" as identifier name.
// ParserError 7104: (135-140): Builtin function "tload" must be called.
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ contract C {
// EVMVersion: >=cancun
// ----
// ParserError 5568: (98-104): Cannot use builtin function name "tstore" as identifier name.
// ParserError 7104: (136-142): Builtin function "tstore" must be called.
1 change: 1 addition & 0 deletions test/libyul/yulSyntaxTests/blobhash.yul
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
// EVMVersion: >=cancun
// ----
// ParserError 5568: (20-28): Cannot use builtin function name "blobhash" as identifier name.
// ParserError 5568: (64-72): Cannot use builtin function name "blobhash" as identifier name.
1 change: 0 additions & 1 deletion test/libyul/yulSyntaxTests/eof/extcall_function_in_eof.yul
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ object "a" {
// bytecodeFormat: >=EOFv1
// ----
// ParserError 5568: (41-48): Cannot use builtin function name "extcall" as identifier name.
// ParserError 8143: (41-48): Expected keyword "data" or "object" or "}".
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ object "a" {
// bytecodeFormat: >=EOFv1
// ----
// ParserError 5568: (41-56): Cannot use builtin function name "extdelegatecall" as identifier name.
// ParserError 8143: (41-56): Expected keyword "data" or "object" or "}".
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ object "a" {
// bytecodeFormat: >=EOFv1
// ----
// ParserError 5568: (41-54): Cannot use builtin function name "extstaticcall" as identifier name.
// ParserError 8143: (41-54): Expected keyword "data" or "object" or "}".
5 changes: 5 additions & 0 deletions test/libyul/yulSyntaxTests/invalid/builtin_name_as_type.yul
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@
}
// ----
// ParserError 5568: (13-21): Cannot use builtin function name "datacopy" as identifier name.
// ParserError 5473: (10-21): Types are not supported in untyped Yul.
// ParserError 5568: (37-50): Cannot use builtin function name "loadimmutable" as identifier name.
// ParserError 5473: (31-50): Types are not supported in untyped Yul.
// ParserError 5568: (70-82): Cannot use builtin function name "linkersymbol" as identifier name.
// ParserError 5473: (67-82): Types are not supported in untyped Yul.
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
}
// ----
// ParserError 5568: (17-28): Cannot use builtin function name "memoryguard" as identifier name.
// ParserError 5568: (53-64): Cannot use builtin function name "memoryguard" as identifier name.
// ParserError 5568: (93-104): Cannot use builtin function name "memoryguard" as identifier name.
// ParserError 5568: (120-131): Cannot use builtin function name "memoryguard" as identifier name.
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
}
// ----
// ParserError 5568: (160-163): Cannot use builtin function name "add" as identifier name.
// ParserError 5568: (164-170): Cannot use builtin function name "mstore" as identifier name.
// ParserError 5568: (175-181): Cannot use builtin function name "sstore" as identifier name.
// ParserError 5568: (193-201): Cannot use builtin function name "coinbase" as identifier name.
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
}
// ----
// ParserError 5568: (158-171): Cannot use builtin function name "loadimmutable" as identifier name.
// ParserError 5568: (172-184): Cannot use builtin function name "setimmutable" as identifier name.
// ParserError 5568: (189-197): Cannot use builtin function name "datasize" as identifier name.
// ParserError 5568: (209-219): Cannot use builtin function name "dataoffset" as identifier name.
1 change: 1 addition & 0 deletions test/libyul/yulSyntaxTests/mcopy_as_identifier.yul
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
// EVMVersion: >=cancun
// ----
// ParserError 5568: (20-25): Cannot use builtin function name "mcopy" as identifier name.
// ParserError 5568: (61-66): Cannot use builtin function name "mcopy" as identifier name.

0 comments on commit edb6783

Please sign in to comment.