From 2c2269d30024f7859e40ab400863a3829424059f Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 4 Oct 2021 18:09:08 +0200 Subject: [PATCH] Tests --- .../controlFlowSideEffects/eval_order.yul | 19 +++++++ .../controlFlowSideEffects/for_loop.yul | 55 +++++++++++++++++++ test/libyul/controlFlowSideEffects/leave.yul | 13 +++++ .../controlFlowSideEffects/recursion.yul | 37 +++++++++++++ test/libyul/controlFlowSideEffects/switch.yul | 41 ++++++++++++++ 5 files changed, 165 insertions(+) create mode 100644 test/libyul/controlFlowSideEffects/eval_order.yul create mode 100644 test/libyul/controlFlowSideEffects/for_loop.yul create mode 100644 test/libyul/controlFlowSideEffects/leave.yul create mode 100644 test/libyul/controlFlowSideEffects/recursion.yul create mode 100644 test/libyul/controlFlowSideEffects/switch.yul diff --git a/test/libyul/controlFlowSideEffects/eval_order.yul b/test/libyul/controlFlowSideEffects/eval_order.yul new file mode 100644 index 000000000..a207d7a19 --- /dev/null +++ b/test/libyul/controlFlowSideEffects/eval_order.yul @@ -0,0 +1,19 @@ +{ + function a() -> x { + revert(0, 0) + } + function b() -> x { + return(0, 0) + } + function c() { + sstore(a(), b()) + } + function d() { + sstore(b(), a()) + } +} +// ---- +// a: can revert +// b: can terminate +// c: can terminate +// d: can revert diff --git a/test/libyul/controlFlowSideEffects/for_loop.yul b/test/libyul/controlFlowSideEffects/for_loop.yul new file mode 100644 index 000000000..1f3714a48 --- /dev/null +++ b/test/libyul/controlFlowSideEffects/for_loop.yul @@ -0,0 +1,55 @@ +{ + function a() { + for { leave } calldataload(0) { } { + break + revert(0, 0) + } + } + function b() { + for { } calldataload(0) { leave } { + break + revert(0, 0) + } + } + function b2() { + for { } calldataload(0) { leave } { + revert(0, 0) + } + } + function c() { + for { } calldataload(0) { revert(0, 0) } { + break + } + } + function c2() { + for { } calldataload(0) { revert(0, 0) } { + break + revert(0, 0) + } + } + function d() { + for { } calldataload(0) { revert(0, 0) } { + continue + } + } + function e() { + for { } calldataload(0) { revert(0, 0) } { + if calldataload(1) { break } + } + } + function f() { + for { } calldataload(0) { } { + if calldataload(1) { continue } + revert(0, 0) + } + } +} +// ---- +// a: can continue +// b: can continue +// b2: can revert, can continue +// c: can continue +// c2: can continue +// d: can revert, can continue +// e: can revert, can continue +// f: can revert, can continue diff --git a/test/libyul/controlFlowSideEffects/leave.yul b/test/libyul/controlFlowSideEffects/leave.yul new file mode 100644 index 000000000..bbc977820 --- /dev/null +++ b/test/libyul/controlFlowSideEffects/leave.yul @@ -0,0 +1,13 @@ +{ + function a() { + revert(0, 0) + leave + } + function b() { + leave + revert(0, 0) + } +} +// ---- +// a: can revert +// b: can continue diff --git a/test/libyul/controlFlowSideEffects/recursion.yul b/test/libyul/controlFlowSideEffects/recursion.yul new file mode 100644 index 000000000..c4176d502 --- /dev/null +++ b/test/libyul/controlFlowSideEffects/recursion.yul @@ -0,0 +1,37 @@ +{ + function a() { + if calldataload(0) { + revert(0, 0) + } + reg() + b() + } + function b() { + a() + return(0, 0) + } + function c() { + c() + revert(0, 0) + } + function d() { + switch calldataload(0) + case 0 { x() } + case 1 { y() reg() revert(0, 0) } + default { z() } + } + function x() { d() revert(0, 0) } + function y() { reg() x() } + function z() { y() } + + function reg() {} +} +// ---- +// a: can revert +// b: can revert +// c: +// d: +// reg: can continue +// x: +// y: +// z: diff --git a/test/libyul/controlFlowSideEffects/switch.yul b/test/libyul/controlFlowSideEffects/switch.yul new file mode 100644 index 000000000..63b45ce30 --- /dev/null +++ b/test/libyul/controlFlowSideEffects/switch.yul @@ -0,0 +1,41 @@ +{ + function a() { + switch calldataload(0) + case 0 { revert(0, 0) } + } + function b() { + switch calldataload(0) + case 0 { revert(0, 0) } + default { revert(0, 0) } + } + function c() { + return(0, 0) + switch calldataload(0) + case 0 { revert(0, 0) } + default { } + } + function d() { + switch calldataload(0) + case 0 { return(0, 0) } + default { return(0, 0) } + revert(0, 0) + } + function e() { + switch calldataload(0) + case 0 { return(0, 0) } + revert(0, 0) + } + function f() { + switch calldataload(0) + case 0 { leave } + default { leave } + revert(0, 0) + } +} +// ---- +// a: can revert, can continue +// b: can revert +// c: can terminate +// d: can terminate +// e: can terminate, can revert +// f: can continue