Skip to content

Commit 6daaff7

Browse files
authored
Merge pull request #15712 from ethereum/make-clash-with-yul-builtin-non-fatal
Make name clash with a builtin non-fatal in Yul parser
2 parents bf6d708 + edb6783 commit 6daaff7

24 files changed

+139
-4
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Language Features:
66
Compiler Features:
77
* Error Reporting: Errors reported during code generation now point at the location of the contract when more fine-grained location is not available.
88
* SMTChecker: Z3 is now a runtime dependency, not a build dependency (except for emscripten build).
9+
* Yul Parser: Make name clash with a builtin a non-fatal error.
910

1011

1112
Bugfixes:

libyul/AsmParser.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,13 @@ YulName Parser::expectAsmIdentifier()
755755
{
756756
YulName name{currentLiteral()};
757757
if (currentToken() == Token::Identifier && m_dialect.findBuiltin(name.str()))
758-
fatalParserError(5568_error, "Cannot use builtin function name \"" + name.str() + "\" as identifier name.");
758+
// Non-fatal. We'll continue and wrongly parse it as an identifier. May lead to some spurious
759+
// errors after this point, but likely also much more useful ones.
760+
m_errorReporter.parserError(
761+
5568_error,
762+
currentLocation(),
763+
"Cannot use builtin function name \"" + name.str() + "\" as identifier name."
764+
);
759765
// NOTE: We keep the expectation here to ensure the correct source location for the error above.
760766
expectToken(Token::Identifier);
761767
return name;

test/libsolidity/syntaxTests/inlineAssembly/basefee_reserved_london.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ contract C {
1010
// EVMVersion: =london
1111
// ----
1212
// ParserError 5568: (98-105): Cannot use builtin function name "basefee" as identifier name.
13+
// ParserError 7104: (137-144): Builtin function "basefee" must be called.

test/libsolidity/syntaxTests/inlineAssembly/blobbasefee_reserved_cancun.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ contract C {
1010
// EVMVersion: >=cancun
1111
// ----
1212
// ParserError 5568: (98-109): Cannot use builtin function name "blobbasefee" as identifier name.
13+
// ParserError 7104: (141-152): Builtin function "blobbasefee" must be called.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
contract C {
2+
function f() public pure {
3+
// NOTE: memoryguard is a builtin but only in pure Yul, not inline assembly.
4+
// NOTE: memoryguard is not a reserved identifier.
5+
assembly { function memoryguard() {} }
6+
assembly { function f(memoryguard) {} }
7+
assembly { function f() -> memoryguard {} }
8+
assembly { let memoryguard }
9+
}
10+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
contract C {
2+
function f() public view {
3+
assembly {
4+
// NOTE: All EVM instruction names are reserved identifiers in Yul.
5+
// NOTE: We do provide builtins corresponding to these instructions.
6+
function add(mstore) -> sstore {}
7+
let coinbase
8+
}
9+
}
10+
}
11+
// ----
12+
// ParserError 5568: (245-248): Cannot use builtin function name "add" as identifier name.
13+
// ParserError 5568: (249-255): Cannot use builtin function name "mstore" as identifier name.
14+
// ParserError 5568: (260-266): Cannot use builtin function name "sstore" as identifier name.
15+
// ParserError 5568: (286-294): Cannot use builtin function name "coinbase" as identifier name.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
contract C {
2+
function f() public pure {
3+
assembly {
4+
// NOTE: All EVM instruction names are reserved identifiers in Yul.
5+
// NOTE: We don't provide builtins corresponding to these instructions.
6+
function dup1(dup2) -> dup3 {}
7+
let dup4
8+
}
9+
}
10+
}
11+
// ----
12+
// DeclarationError 5017: (239-269): The identifier "dup1" is reserved and can not be used.
13+
// DeclarationError 5017: (253-257): The identifier "dup2" is reserved and can not be used.
14+
// DeclarationError 5017: (262-266): The identifier "dup3" is reserved and can not be used.
15+
// DeclarationError 5017: (286-290): The identifier "dup4" is reserved and can not be used.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
contract C {
2+
function f() public view {
3+
assembly {
4+
// NOTE: These are builtins but only in pure Yul, not inline assembly.
5+
// NOTE: Names of these builtins are also reserved identifiers.
6+
function loadimmutable(setimmutable) -> datasize {}
7+
let dataoffset
8+
}
9+
}
10+
}
11+
// ----
12+
// DeclarationError 5017: (234-285): The identifier "loadimmutable" is reserved and can not be used.
13+
// DeclarationError 5017: (257-269): The identifier "setimmutable" is reserved and can not be used.
14+
// DeclarationError 5017: (274-282): The identifier "datasize" is reserved and can not be used.
15+
// DeclarationError 5017: (302-312): The identifier "dataoffset" is reserved and can not be used.

test/libsolidity/syntaxTests/inlineAssembly/difficulty_disallowed_function_pre_paris.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ contract C {
1919
// EVMVersion: <paris
2020
// ----
2121
// ParserError 5568: (101-111): Cannot use builtin function name "difficulty" as identifier name.
22+
// ParserError 7104: (143-153): Builtin function "difficulty" must be called.

test/libsolidity/syntaxTests/inlineAssembly/mcopy_reserved_cancun.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ contract C {
1919
// EVMVersion: >=cancun
2020
// ----
2121
// ParserError 5568: (101-106): Cannot use builtin function name "mcopy" as identifier name.
22+
// ParserError 7104: (134-139): Builtin function "mcopy" must be called.

0 commit comments

Comments
 (0)