From 2d0f6278bbe9a740e715ee9acbc83eec0bca68e9 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Mon, 17 Jan 2022 18:39:18 +0100 Subject: [PATCH 1/2] Allow builtins as yul identifier paths in antlr grammar. --- Changelog.md | 1 + docs/grammar/SolidityParser.g4 | 2 +- .../inlineAssembly/assignment_to_function_pointer.sol | 9 +++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 test/libsolidity/syntaxTests/inlineAssembly/assignment_to_function_pointer.sol diff --git a/Changelog.md b/Changelog.md index bd492e4bfdcd..39e844387b87 100644 --- a/Changelog.md +++ b/Changelog.md @@ -10,6 +10,7 @@ Compiler Features: Bugfixes: + * Antlr Grammar: Allow builtin names in ``yulPath`` to support ``.address`` in function pointers. * Control Flow Graph: Perform proper virtual lookup for modifiers for uninitialized variable and unreachable code analysis. * Immutables: Fix wrong error when the constructor of a base contract uses ``return`` and the parent contract contains immutable variables. diff --git a/docs/grammar/SolidityParser.g4 b/docs/grammar/SolidityParser.g4 index f7630c59ee32..110773fede7c 100644 --- a/docs/grammar/SolidityParser.g4 +++ b/docs/grammar/SolidityParser.g4 @@ -564,7 +564,7 @@ yulFunctionDefinition: * While only identifiers without dots can be declared within inline assembly, * paths containing dots can refer to declarations outside the inline assembly block. */ -yulPath: YulIdentifier (YulPeriod YulIdentifier)*; +yulPath: YulIdentifier (YulPeriod (YulIdentifier | YulEVMBuiltin))*; /** * A call to a function with return values can only occur as right-hand side of an assignment or * a variable declaration. diff --git a/test/libsolidity/syntaxTests/inlineAssembly/assignment_to_function_pointer.sol b/test/libsolidity/syntaxTests/inlineAssembly/assignment_to_function_pointer.sol new file mode 100644 index 000000000000..d29a74890536 --- /dev/null +++ b/test/libsolidity/syntaxTests/inlineAssembly/assignment_to_function_pointer.sol @@ -0,0 +1,9 @@ +contract C { + function f() public pure { + function() external g; + assembly { + g.address := 0x42 + g.selector := 0x23 + } + } +} From c91f995ec9aa389fb3c0b0b98bbb836deb8cc353 Mon Sep 17 00:00:00 2001 From: Daniel Kirchner Date: Mon, 17 Jan 2022 20:12:11 +0100 Subject: [PATCH 2/2] Update test/libsolidity/syntaxTests/inlineAssembly/assignment_to_function_pointer.sol MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Kamil ƚliwak --- .../assignment_to_function_pointer.sol | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/libsolidity/syntaxTests/inlineAssembly/assignment_to_function_pointer.sol b/test/libsolidity/syntaxTests/inlineAssembly/assignment_to_function_pointer.sol index d29a74890536..38e88eeeb6a4 100644 --- a/test/libsolidity/syntaxTests/inlineAssembly/assignment_to_function_pointer.sol +++ b/test/libsolidity/syntaxTests/inlineAssembly/assignment_to_function_pointer.sol @@ -1,9 +1,9 @@ contract C { - function f() public pure { - function() external g; - assembly { - g.address := 0x42 - g.selector := 0x23 + function f() public pure { + function() external g; + assembly { + g.address := 0x42 + g.selector := 0x23 + } } - } }