From 499fe57d33fe5be36c1f3ef54d882aad6b9411f1 Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 28 Oct 2019 15:46:58 +0100 Subject: [PATCH] Tests --- .../semanticTests/inlineAssembly/leave.sol | 14 +++++++ .../syntaxTests/inlineAssembly/leave.sol | 10 +++++ .../inlineAssembly/leave_invalid.sol | 9 +++++ test/libyul/yulInterpreterTests/leave.yul | 20 ++++++++++ .../yulInterpreterTests/leave_for_init.yul | 18 +++++++++ .../controlFlowSimplifier/remove_leave.yul | 19 +++++++++ .../deadCodeEliminator/early_leave.yul | 36 +++++++++++++++++ .../fullInliner/no_inline_leave.yul | 22 ++++++++++ .../redundantAssignEliminator/leave.yul | 40 +++++++++++++++++++ 9 files changed, 188 insertions(+) create mode 100644 test/libsolidity/semanticTests/inlineAssembly/leave.sol create mode 100644 test/libsolidity/syntaxTests/inlineAssembly/leave.sol create mode 100644 test/libsolidity/syntaxTests/inlineAssembly/leave_invalid.sol create mode 100644 test/libyul/yulInterpreterTests/leave.yul create mode 100644 test/libyul/yulInterpreterTests/leave_for_init.yul create mode 100644 test/libyul/yulOptimizerTests/controlFlowSimplifier/remove_leave.yul create mode 100644 test/libyul/yulOptimizerTests/deadCodeEliminator/early_leave.yul create mode 100644 test/libyul/yulOptimizerTests/fullInliner/no_inline_leave.yul create mode 100644 test/libyul/yulOptimizerTests/redundantAssignEliminator/leave.yul diff --git a/test/libsolidity/semanticTests/inlineAssembly/leave.sol b/test/libsolidity/semanticTests/inlineAssembly/leave.sol new file mode 100644 index 000000000..40add273e --- /dev/null +++ b/test/libsolidity/semanticTests/inlineAssembly/leave.sol @@ -0,0 +1,14 @@ +contract C { + function f() public pure returns (uint w) { + assembly { + function f() -> t { + t := 2 + leave + t := 9 + } + w := f() + } + } +} +// ---- +// f() -> 2 diff --git a/test/libsolidity/syntaxTests/inlineAssembly/leave.sol b/test/libsolidity/syntaxTests/inlineAssembly/leave.sol new file mode 100644 index 000000000..27edba47e --- /dev/null +++ b/test/libsolidity/syntaxTests/inlineAssembly/leave.sol @@ -0,0 +1,10 @@ +contract C { + function f() public pure { + assembly { + function f() { + leave + } + } + } +} +// ---- diff --git a/test/libsolidity/syntaxTests/inlineAssembly/leave_invalid.sol b/test/libsolidity/syntaxTests/inlineAssembly/leave_invalid.sol new file mode 100644 index 000000000..f2da48e1c --- /dev/null +++ b/test/libsolidity/syntaxTests/inlineAssembly/leave_invalid.sol @@ -0,0 +1,9 @@ +contract C { + function f() public pure { + assembly { + leave + } + } +} +// ---- +// SyntaxError: (63-68): Keyword "leave" can only be used inside a function. diff --git a/test/libyul/yulInterpreterTests/leave.yul b/test/libyul/yulInterpreterTests/leave.yul new file mode 100644 index 000000000..6f082ee33 --- /dev/null +++ b/test/libyul/yulInterpreterTests/leave.yul @@ -0,0 +1,20 @@ +{ + function f() -> x, y + { + for { x := 0 } lt(x, 10) { x := add(x, 1) } { + if eq(x, 5) { y := 1 leave } + } + x := 9 + } + { + let a, b := f() + sstore(a, b) + } +} +// ==== +// EVMVersion: >=constantinople +// ---- +// Trace: +// Memory dump: +// Storage dump: +// 0000000000000000000000000000000000000000000000000000000000000005: 0000000000000000000000000000000000000000000000000000000000000001 diff --git a/test/libyul/yulInterpreterTests/leave_for_init.yul b/test/libyul/yulInterpreterTests/leave_for_init.yul new file mode 100644 index 000000000..cd0557e71 --- /dev/null +++ b/test/libyul/yulInterpreterTests/leave_for_init.yul @@ -0,0 +1,18 @@ +{ + function f() -> x + { + for { leave x := 2 } eq(x, 0) { } { + } + } + { + let a := f() + sstore(a, 7) + } +} +// ==== +// EVMVersion: >=constantinople +// ---- +// Trace: +// Memory dump: +// Storage dump: +// 0000000000000000000000000000000000000000000000000000000000000000: 0000000000000000000000000000000000000000000000000000000000000007 diff --git a/test/libyul/yulOptimizerTests/controlFlowSimplifier/remove_leave.yul b/test/libyul/yulOptimizerTests/controlFlowSimplifier/remove_leave.yul new file mode 100644 index 000000000..af7726df9 --- /dev/null +++ b/test/libyul/yulOptimizerTests/controlFlowSimplifier/remove_leave.yul @@ -0,0 +1,19 @@ +{ + function f() -> x { x := 7 leave } + function g() -> x { leave x := 7 } + function h() -> x { if x { leave } } +} +// ==== +// step: controlFlowSimplifier +// ---- +// { +// function f() -> x +// { x := 7 } +// function g() -> x_1 +// { +// leave +// x_1 := 7 +// } +// function h() -> x_2 +// { if x_2 { leave } } +// } diff --git a/test/libyul/yulOptimizerTests/deadCodeEliminator/early_leave.yul b/test/libyul/yulOptimizerTests/deadCodeEliminator/early_leave.yul new file mode 100644 index 000000000..90dae56f0 --- /dev/null +++ b/test/libyul/yulOptimizerTests/deadCodeEliminator/early_leave.yul @@ -0,0 +1,36 @@ +{ + function f() -> x { + for { + let a := 20 + } + lt(a, 40) + { + a := add(a, 2) + } + { + a := a + leave + mstore(0, a) + a := add(a, 10) + } + x := 9 + } + pop(f()) +} + +// ==== +// step: deadCodeEliminator +// ---- +// { +// function f() -> x +// { +// let a := 20 +// for { } lt(a, 40) { a := add(a, 2) } +// { +// a := a +// leave +// } +// x := 9 +// } +// pop(f()) +// } diff --git a/test/libyul/yulOptimizerTests/fullInliner/no_inline_leave.yul b/test/libyul/yulOptimizerTests/fullInliner/no_inline_leave.yul new file mode 100644 index 000000000..552ce9a82 --- /dev/null +++ b/test/libyul/yulOptimizerTests/fullInliner/no_inline_leave.yul @@ -0,0 +1,22 @@ +{ + function g() -> x { x := 8 leave } + function f(a) { a := g() } + let a1 := calldataload(0) + f(a1) +} +// ==== +// step: fullInliner +// ---- +// { +// { +// let a_2 := calldataload(0) +// a_2 := g() +// } +// function g() -> x +// { +// x := 8 +// leave +// } +// function f(a) +// { a := g() } +// } diff --git a/test/libyul/yulOptimizerTests/redundantAssignEliminator/leave.yul b/test/libyul/yulOptimizerTests/redundantAssignEliminator/leave.yul new file mode 100644 index 000000000..ef68155ad --- /dev/null +++ b/test/libyul/yulOptimizerTests/redundantAssignEliminator/leave.yul @@ -0,0 +1,40 @@ +{ + function f(a, b) -> x { + let t + a := 2 + x := 2 + t := 2 + if b { leave } + a := 8 + x := 8 + t := 8 + } + function g(a, b) -> x { + let t + a := 2 + x := 2 + t := 2 + if b { } + a := 8 + x := 8 + t := 8 + } +} +// ==== +// step: redundantAssignEliminator +// ---- +// { +// function f(a, b) -> x +// { +// let t +// x := 2 +// if b { leave } +// x := 8 +// } +// function g(a_1, b_2) -> x_3 +// { +// let t_4 +// if b_2 { } +// x_3 := 8 +// } +// }