diff --git a/test/libsolidity/memoryGuardTests/constructor_safe_deploy_unsafe.sol b/test/libsolidity/memoryGuardTests/comment/constructor_safe_deploy_unsafe.sol similarity index 100% rename from test/libsolidity/memoryGuardTests/constructor_safe_deploy_unsafe.sol rename to test/libsolidity/memoryGuardTests/comment/constructor_safe_deploy_unsafe.sol diff --git a/test/libsolidity/memoryGuardTests/constructor_unsafe_deploy_safe.sol b/test/libsolidity/memoryGuardTests/comment/constructor_unsafe_deploy_safe.sol similarity index 100% rename from test/libsolidity/memoryGuardTests/constructor_unsafe_deploy_safe.sol rename to test/libsolidity/memoryGuardTests/comment/constructor_unsafe_deploy_safe.sol diff --git a/test/libsolidity/memoryGuardTests/free_function.sol b/test/libsolidity/memoryGuardTests/comment/free_function.sol similarity index 100% rename from test/libsolidity/memoryGuardTests/free_function.sol rename to test/libsolidity/memoryGuardTests/comment/free_function.sol diff --git a/test/libsolidity/memoryGuardTests/multi_annotation.sol b/test/libsolidity/memoryGuardTests/comment/multi_annotation.sol similarity index 100% rename from test/libsolidity/memoryGuardTests/multi_annotation.sol rename to test/libsolidity/memoryGuardTests/comment/multi_annotation.sol diff --git a/test/libsolidity/memoryGuardTests/multiple_contracts.sol b/test/libsolidity/memoryGuardTests/comment/multiple_contracts.sol similarity index 100% rename from test/libsolidity/memoryGuardTests/multiple_contracts.sol rename to test/libsolidity/memoryGuardTests/comment/multiple_contracts.sol diff --git a/test/libsolidity/memoryGuardTests/safe_and_unmarked_empty.sol b/test/libsolidity/memoryGuardTests/comment/safe_and_unmarked_empty.sol similarity index 100% rename from test/libsolidity/memoryGuardTests/safe_and_unmarked_empty.sol rename to test/libsolidity/memoryGuardTests/comment/safe_and_unmarked_empty.sol diff --git a/test/libsolidity/memoryGuardTests/safe_and_unmarked_unsafe.sol b/test/libsolidity/memoryGuardTests/comment/safe_and_unmarked_unsafe.sol similarity index 100% rename from test/libsolidity/memoryGuardTests/safe_and_unmarked_unsafe.sol rename to test/libsolidity/memoryGuardTests/comment/safe_and_unmarked_unsafe.sol diff --git a/test/libsolidity/memoryGuardTests/dialectString/constructor_safe_deploy_unsafe.sol b/test/libsolidity/memoryGuardTests/dialectString/constructor_safe_deploy_unsafe.sol new file mode 100644 index 000000000..8c5aa229d --- /dev/null +++ b/test/libsolidity/memoryGuardTests/dialectString/constructor_safe_deploy_unsafe.sol @@ -0,0 +1,17 @@ +contract C { + constructor() { + uint256 x; + assembly { x := 0 } + f(); + } + function f() internal pure { + assembly "evmasm" ("memory-safe") { mstore(0, 0) } + assembly ("memory-safe") { mstore(0, 0) } + } + function g() public pure { + assembly { mstore(0, 0) } + } +} +// ---- +// :C(creation) true +// :C(runtime) false diff --git a/test/libsolidity/memoryGuardTests/dialectString/constructor_unsafe_deploy_safe.sol b/test/libsolidity/memoryGuardTests/dialectString/constructor_unsafe_deploy_safe.sol new file mode 100644 index 000000000..595e25914 --- /dev/null +++ b/test/libsolidity/memoryGuardTests/dialectString/constructor_unsafe_deploy_safe.sol @@ -0,0 +1,16 @@ +contract C { + constructor() { + uint256 x; + assembly { x := 0 } + f(); + } + function f() internal pure { + assembly { mstore(0, 0) } + } + function g() public pure { + assembly "evmasm" ("memory-safe") { mstore(0, 0) } + } +} +// ---- +// :C(creation) false +// :C(runtime) true diff --git a/test/libsolidity/memoryGuardTests/dialectString/free_function.sol b/test/libsolidity/memoryGuardTests/dialectString/free_function.sol new file mode 100644 index 000000000..9e3d2a4b5 --- /dev/null +++ b/test/libsolidity/memoryGuardTests/dialectString/free_function.sol @@ -0,0 +1,28 @@ +function safe() pure returns (uint256 x) { + assembly { x := 42 } + assembly "evmasm" ("memory-safe") { mstore(0, 0) } +} +function unsafe() pure returns (uint256 x) { + assembly { pop(mload(0)) } +} +contract C { + constructor() { + unsafe(); + } + function f() public pure { + safe(); + } +} +contract D { + constructor() { + safe(); + } + function f() public pure { + unsafe(); + } +} +// ---- +// :C(creation) false +// :C(runtime) true +// :D(creation) true +// :D(runtime) false diff --git a/test/libsolidity/memoryGuardTests/dialectString/multiple_contracts.sol b/test/libsolidity/memoryGuardTests/dialectString/multiple_contracts.sol new file mode 100644 index 000000000..2ee227bc6 --- /dev/null +++ b/test/libsolidity/memoryGuardTests/dialectString/multiple_contracts.sol @@ -0,0 +1,23 @@ +contract C { + constructor(uint256 x) { + assembly { x := 4 } + assembly "evmasm" ("memory-safe") { mstore(0, 0) } + } + function f() public pure { + assembly { mstore(0,0) } + } +} +contract D { + constructor() { + assembly { mstore(0,0) } + } + function f(uint256 x) public pure { + assembly { x := 4 } + assembly ("memory-safe") { mstore(0, 0) } + } +} +// ---- +// :C(creation) true +// :C(runtime) false +// :D(creation) false +// :D(runtime) true diff --git a/test/libsolidity/memoryGuardTests/dialectString/safe_and_unmarked_empty.sol b/test/libsolidity/memoryGuardTests/dialectString/safe_and_unmarked_empty.sol new file mode 100644 index 000000000..ab653be97 --- /dev/null +++ b/test/libsolidity/memoryGuardTests/dialectString/safe_and_unmarked_empty.sol @@ -0,0 +1,9 @@ +contract C { + function f() external pure { + assembly "evmasm" ("memory-safe") {} + assembly {} + } +} +// ---- +// :C(creation) true +// :C(runtime) true diff --git a/test/libsolidity/memoryGuardTests/dialectString/safe_and_unmarked_unsafe.sol b/test/libsolidity/memoryGuardTests/dialectString/safe_and_unmarked_unsafe.sol new file mode 100644 index 000000000..8b865d5b8 --- /dev/null +++ b/test/libsolidity/memoryGuardTests/dialectString/safe_and_unmarked_unsafe.sol @@ -0,0 +1,9 @@ +contract C { + function f() external pure { + assembly "evmasm" ("memory-safe") {} + assembly { mstore(0,0) } + } +} +// ---- +// :C(creation) true +// :C(runtime) false diff --git a/test/libsolidity/memoryGuardTests/dialectString/stub.sol b/test/libsolidity/memoryGuardTests/dialectString/stub.sol new file mode 100644 index 000000000..65f6447c1 --- /dev/null +++ b/test/libsolidity/memoryGuardTests/dialectString/stub.sol @@ -0,0 +1,4 @@ +contract C {} +// ---- +// :C(creation) true +// :C(runtime) true diff --git a/test/libsolidity/syntaxTests/inlineAssembly/assembly_dialect_duplicate_option.sol b/test/libsolidity/syntaxTests/inlineAssembly/assembly_dialect_duplicate_option.sol new file mode 100644 index 000000000..7e0672f65 --- /dev/null +++ b/test/libsolidity/syntaxTests/inlineAssembly/assembly_dialect_duplicate_option.sol @@ -0,0 +1,5 @@ +function f() pure { + assembly "evmasm" ("memory-safe", "memory-safe") {} +} +// ---- +// SyntaxError 7026: (24-75): Inline assembly marked memory-safe multiple times. diff --git a/test/libsolidity/syntaxTests/inlineAssembly/assembly_dialect_invalid_options.sol b/test/libsolidity/syntaxTests/inlineAssembly/assembly_dialect_invalid_options.sol new file mode 100644 index 000000000..44206c9ec --- /dev/null +++ b/test/libsolidity/syntaxTests/inlineAssembly/assembly_dialect_invalid_options.sol @@ -0,0 +1,8 @@ +function f() pure { + assembly "evmasm" ("a", "b", "c", "c") {} +} +// ---- +// Warning 4430: (24-65): Unknown inline assembly flag: "a" +// Warning 4430: (24-65): Unknown inline assembly flag: "b" +// Warning 4430: (24-65): Unknown inline assembly flag: "c" +// Warning 4430: (24-65): Unknown inline assembly flag: "c" diff --git a/test/libsolidity/syntaxTests/inlineAssembly/assembly_dialect_leading_space.sol b/test/libsolidity/syntaxTests/inlineAssembly/assembly_dialect_leading_space.sol new file mode 100644 index 000000000..1cf1e7fb9 --- /dev/null +++ b/test/libsolidity/syntaxTests/inlineAssembly/assembly_dialect_leading_space.sol @@ -0,0 +1,5 @@ +function f() pure { + assembly " evmasm" {} +} +// ---- +// ParserError 4531: (33-42): Only "evmasm" supported. diff --git a/test/libsolidity/syntaxTests/inlineAssembly/assembly_duplicate_option.sol b/test/libsolidity/syntaxTests/inlineAssembly/assembly_duplicate_option.sol new file mode 100644 index 000000000..69c503559 --- /dev/null +++ b/test/libsolidity/syntaxTests/inlineAssembly/assembly_duplicate_option.sol @@ -0,0 +1,5 @@ +function f() pure { + assembly ("memory-safe", "memory-safe") {} +} +// ---- +// SyntaxError 7026: (24-66): Inline assembly marked memory-safe multiple times. diff --git a/test/libsolidity/syntaxTests/inlineAssembly/assembly_empty_option_list.sol b/test/libsolidity/syntaxTests/inlineAssembly/assembly_empty_option_list.sol new file mode 100644 index 000000000..cae17320b --- /dev/null +++ b/test/libsolidity/syntaxTests/inlineAssembly/assembly_empty_option_list.sol @@ -0,0 +1,5 @@ +function f() pure { + assembly () {} +} +// ---- +// ParserError 2314: (34-35): Expected 'StringLiteral' but got ')' diff --git a/test/libsolidity/syntaxTests/inlineAssembly/assembly_empty_option_list_dialect.sol b/test/libsolidity/syntaxTests/inlineAssembly/assembly_empty_option_list_dialect.sol new file mode 100644 index 000000000..222e59b93 --- /dev/null +++ b/test/libsolidity/syntaxTests/inlineAssembly/assembly_empty_option_list_dialect.sol @@ -0,0 +1,5 @@ +function f() pure { + assembly "evmasm" () {} +} +// ---- +// ParserError 2314: (43-44): Expected 'StringLiteral' but got ')' diff --git a/test/libsolidity/syntaxTests/inlineAssembly/assembly_flags_delimiter.sol b/test/libsolidity/syntaxTests/inlineAssembly/assembly_flags_delimiter.sol new file mode 100644 index 000000000..cd82f8aaa --- /dev/null +++ b/test/libsolidity/syntaxTests/inlineAssembly/assembly_flags_delimiter.sol @@ -0,0 +1,5 @@ +function f() pure { + assembly ("a" "b") {} +} +// ---- +// ParserError 2314: (35-38): Expected ')' but got 'StringLiteral' diff --git a/test/libsolidity/syntaxTests/inlineAssembly/assembly_invalid_options.sol b/test/libsolidity/syntaxTests/inlineAssembly/assembly_invalid_options.sol new file mode 100644 index 000000000..3364d793e --- /dev/null +++ b/test/libsolidity/syntaxTests/inlineAssembly/assembly_invalid_options.sol @@ -0,0 +1,8 @@ +function f() pure { + assembly ("a", "b", "c", "c") {} +} +// ---- +// Warning 4430: (24-56): Unknown inline assembly flag: "a" +// Warning 4430: (24-56): Unknown inline assembly flag: "b" +// Warning 4430: (24-56): Unknown inline assembly flag: "c" +// Warning 4430: (24-56): Unknown inline assembly flag: "c" diff --git a/test/libsolidity/syntaxTests/inlineAssembly/memory_safe_dialect_string_and_comment.sol b/test/libsolidity/syntaxTests/inlineAssembly/memory_safe_dialect_string_and_comment.sol new file mode 100644 index 000000000..9d0fd3e1c --- /dev/null +++ b/test/libsolidity/syntaxTests/inlineAssembly/memory_safe_dialect_string_and_comment.sol @@ -0,0 +1,7 @@ +function f() pure { + /// @solidity memory-safe-assembly + assembly "evmasm" ("memory-safe") { + } +} +// ---- +// Warning 8544: (63-104): Inline assembly marked as memory safe using both a NatSpec tag and an assembly flag. If you are not concerned with backwards compatibility, only use the assembly flag, otherwise only use the NatSpec tag. diff --git a/test/libsolidity/syntaxTests/inlineAssembly/memory_safe_in_dialect_string.sol b/test/libsolidity/syntaxTests/inlineAssembly/memory_safe_in_dialect_string.sol new file mode 100644 index 000000000..c034f803d --- /dev/null +++ b/test/libsolidity/syntaxTests/inlineAssembly/memory_safe_in_dialect_string.sol @@ -0,0 +1,3 @@ +function f() pure { + assembly "evmasm" ("memory-safe") {} +} \ No newline at end of file