mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Tests
This commit is contained in:
parent
91a92a01d5
commit
499fe57d33
14
test/libsolidity/semanticTests/inlineAssembly/leave.sol
Normal file
14
test/libsolidity/semanticTests/inlineAssembly/leave.sol
Normal file
@ -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
|
10
test/libsolidity/syntaxTests/inlineAssembly/leave.sol
Normal file
10
test/libsolidity/syntaxTests/inlineAssembly/leave.sol
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
contract C {
|
||||||
|
function f() public pure {
|
||||||
|
assembly {
|
||||||
|
function f() {
|
||||||
|
leave
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
@ -0,0 +1,9 @@
|
|||||||
|
contract C {
|
||||||
|
function f() public pure {
|
||||||
|
assembly {
|
||||||
|
leave
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// SyntaxError: (63-68): Keyword "leave" can only be used inside a function.
|
20
test/libyul/yulInterpreterTests/leave.yul
Normal file
20
test/libyul/yulInterpreterTests/leave.yul
Normal file
@ -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
|
18
test/libyul/yulInterpreterTests/leave_for_init.yul
Normal file
18
test/libyul/yulInterpreterTests/leave_for_init.yul
Normal file
@ -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
|
@ -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 } }
|
||||||
|
// }
|
@ -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())
|
||||||
|
// }
|
@ -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() }
|
||||||
|
// }
|
@ -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
|
||||||
|
// }
|
||||||
|
// }
|
Loading…
Reference in New Issue
Block a user