From acb1e8c280b8238cd24c45bdf291c1550e2177fe Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 12 Aug 2020 23:58:21 +0100 Subject: [PATCH 1/3] Add tests showing hex literals are not allowed in Yul --- .../syntaxTests/inlineAssembly/hex_assignment.sol | 9 +++++++++ .../syntaxTests/inlineAssembly/hex_expression.sol | 9 +++++++++ .../syntaxTests/inlineAssembly/hex_switch_case.sol | 11 +++++++++++ test/libyul/yulSyntaxTests/hex_assignment.yul | 5 +++++ test/libyul/yulSyntaxTests/hex_expression.yul | 5 +++++ test/libyul/yulSyntaxTests/hex_switch_case.yul | 7 +++++++ 6 files changed, 46 insertions(+) create mode 100644 test/libsolidity/syntaxTests/inlineAssembly/hex_assignment.sol create mode 100644 test/libsolidity/syntaxTests/inlineAssembly/hex_expression.sol create mode 100644 test/libsolidity/syntaxTests/inlineAssembly/hex_switch_case.sol create mode 100644 test/libyul/yulSyntaxTests/hex_assignment.yul create mode 100644 test/libyul/yulSyntaxTests/hex_expression.yul create mode 100644 test/libyul/yulSyntaxTests/hex_switch_case.yul diff --git a/test/libsolidity/syntaxTests/inlineAssembly/hex_assignment.sol b/test/libsolidity/syntaxTests/inlineAssembly/hex_assignment.sol new file mode 100644 index 000000000..18107e044 --- /dev/null +++ b/test/libsolidity/syntaxTests/inlineAssembly/hex_assignment.sol @@ -0,0 +1,9 @@ +contract C { + function f() public pure { + assembly { + let x := hex"0011" + } + } +} +// ---- +// ParserError 1856: (72-81): Literal or identifier expected. diff --git a/test/libsolidity/syntaxTests/inlineAssembly/hex_expression.sol b/test/libsolidity/syntaxTests/inlineAssembly/hex_expression.sol new file mode 100644 index 000000000..53cd23a29 --- /dev/null +++ b/test/libsolidity/syntaxTests/inlineAssembly/hex_expression.sol @@ -0,0 +1,9 @@ +contract C { + function f() public pure { + assembly { + pop(hex"2233") + } + } +} +// ---- +// ParserError 1856: (67-76): Literal or identifier expected. diff --git a/test/libsolidity/syntaxTests/inlineAssembly/hex_switch_case.sol b/test/libsolidity/syntaxTests/inlineAssembly/hex_switch_case.sol new file mode 100644 index 000000000..bc0ff56fe --- /dev/null +++ b/test/libsolidity/syntaxTests/inlineAssembly/hex_switch_case.sol @@ -0,0 +1,11 @@ +contract C { + function f() public pure { + assembly { + switch codesize() + case hex"00" {} + case hex"1122" {} + } + } +} +// ---- +// ParserError 1856: (92-99): Literal or identifier expected. diff --git a/test/libyul/yulSyntaxTests/hex_assignment.yul b/test/libyul/yulSyntaxTests/hex_assignment.yul new file mode 100644 index 000000000..c9af448c1 --- /dev/null +++ b/test/libyul/yulSyntaxTests/hex_assignment.yul @@ -0,0 +1,5 @@ +{ + let x := hex"0011" +} +// ---- +// ParserError 1856: (15-24): Literal or identifier expected. diff --git a/test/libyul/yulSyntaxTests/hex_expression.yul b/test/libyul/yulSyntaxTests/hex_expression.yul new file mode 100644 index 000000000..f9c1cb52d --- /dev/null +++ b/test/libyul/yulSyntaxTests/hex_expression.yul @@ -0,0 +1,5 @@ +{ + pop(hex"2233") +} +// ---- +// ParserError 1856: (10-19): Literal or identifier expected. diff --git a/test/libyul/yulSyntaxTests/hex_switch_case.yul b/test/libyul/yulSyntaxTests/hex_switch_case.yul new file mode 100644 index 000000000..0f3636b4f --- /dev/null +++ b/test/libyul/yulSyntaxTests/hex_switch_case.yul @@ -0,0 +1,7 @@ +{ + switch codesize() + case hex"00" {} + case hex"1122" {} +} +// ---- +// ParserError 1856: (33-40): Literal or identifier expected. From 18eed4468857f316d5c8dbbbe2d524bc9a1f2045 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 12 Aug 2020 23:59:37 +0100 Subject: [PATCH 2/3] Drop hex literals from the Yul documentation --- docs/yul.rst | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/docs/yul.rst b/docs/yul.rst index 2054f35c7..7d064059b 100644 --- a/docs/yul.rst +++ b/docs/yul.rst @@ -476,9 +476,8 @@ which are explained in their own chapter. TypeName = Identifier TypedIdentifierList = Identifier ( ':' TypeName )? ( ',' Identifier ( ':' TypeName )? )* Literal = - (NumberLiteral | StringLiteral | HexLiteral | TrueLiteral | FalseLiteral) ( ':' TypeName )? + (NumberLiteral | StringLiteral | TrueLiteral | FalseLiteral) ( ':' TypeName )? NumberLiteral = HexNumber | DecimalNumber - HexLiteral = 'hex' ('"' ([0-9a-fA-F]{2})* '"' | '\'' ([0-9a-fA-F]{2})* '\'') StringLiteral = '"' ([^"\r\n\\] | '\\' .)* '"' TrueLiteral = 'true' FalseLiteral = 'false' @@ -688,8 +687,6 @@ We will use a destructuring notation for the AST nodes. L'[$parami] = vi and L'[$reti] = 0 for all i. Let G'', L'', mode = E(Gn, L', block) G'', Ln, L''[$ret1], ..., L''[$retm] - E(G, L, l: HexLiteral) = G, L, hexString(l), - where hexString decodes l from hex and left-aligns it into 32 bytes E(G, L, l: StringLiteral) = G, L, utf8EncodeLeftAligned(l), where utf8EncodeLeftAligned performs a utf8 encoding of l and aligns it left into 32 bytes From b752551ebd63054bc3ba5970f9129dc8914d65c3 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Thu, 13 Aug 2020 00:26:52 +0100 Subject: [PATCH 3/3] Add test case for string literals in switch statements in Yul --- .../inlineAssembly/string_literal_switch_case.yul | 9 +++++++++ .../libyul/yulSyntaxTests/string_literal_switch_case.yul | 5 +++++ 2 files changed, 14 insertions(+) create mode 100644 test/libsolidity/syntaxTests/inlineAssembly/string_literal_switch_case.yul create mode 100644 test/libyul/yulSyntaxTests/string_literal_switch_case.yul diff --git a/test/libsolidity/syntaxTests/inlineAssembly/string_literal_switch_case.yul b/test/libsolidity/syntaxTests/inlineAssembly/string_literal_switch_case.yul new file mode 100644 index 000000000..d068a72e3 --- /dev/null +++ b/test/libsolidity/syntaxTests/inlineAssembly/string_literal_switch_case.yul @@ -0,0 +1,9 @@ +contract C { + function f() public pure { + assembly { + switch codesize() + case "1" {} + case "2" {} + } + } +} diff --git a/test/libyul/yulSyntaxTests/string_literal_switch_case.yul b/test/libyul/yulSyntaxTests/string_literal_switch_case.yul new file mode 100644 index 000000000..02d1045c3 --- /dev/null +++ b/test/libyul/yulSyntaxTests/string_literal_switch_case.yul @@ -0,0 +1,5 @@ +{ + switch codesize() + case "1" {} + case "2" {} +} \ No newline at end of file