aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-12-13 22:38:14 +0800
committerchriseth <chris@ethereum.org>2018-12-13 23:51:10 +0800
commit6c6a53a439de11ebae0b09d8a18c30018b3d89b4 (patch)
tree5abf3f2a9d4f5a8778af1afb8f2fcdbd005434b4
parent11209ec48a3581419ebfa4764669c2a128f1b997 (diff)
downloaddexon-solidity-6c6a53a439de11ebae0b09d8a18c30018b3d89b4.tar
dexon-solidity-6c6a53a439de11ebae0b09d8a18c30018b3d89b4.tar.gz
dexon-solidity-6c6a53a439de11ebae0b09d8a18c30018b3d89b4.tar.bz2
dexon-solidity-6c6a53a439de11ebae0b09d8a18c30018b3d89b4.tar.lz
dexon-solidity-6c6a53a439de11ebae0b09d8a18c30018b3d89b4.tar.xz
dexon-solidity-6c6a53a439de11ebae0b09d8a18c30018b3d89b4.tar.zst
dexon-solidity-6c6a53a439de11ebae0b09d8a18c30018b3d89b4.zip
Do not create unassigned variables.
-rw-r--r--libyul/optimiser/FullInliner.cpp4
-rw-r--r--test/libyul/yulOptimizerTests/fullInliner/double_inline.yul8
-rw-r--r--test/libyul/yulOptimizerTests/fullInliner/inside_condition.yul2
-rw-r--r--test/libyul/yulOptimizerTests/fullInliner/large_function_multi_use.yul4
-rw-r--r--test/libyul/yulOptimizerTests/fullInliner/large_function_single_use.yul2
-rw-r--r--test/libyul/yulOptimizerTests/fullInliner/long_names.yul2
-rw-r--r--test/libyul/yulOptimizerTests/fullInliner/move_up_rightwards_argument.yul2
-rw-r--r--test/libyul/yulOptimizerTests/fullInliner/multi_fun.yul6
-rw-r--r--test/libyul/yulOptimizerTests/fullInliner/multi_fun_callback.yul2
-rw-r--r--test/libyul/yulOptimizerTests/fullInliner/multi_return.yul4
-rw-r--r--test/libyul/yulOptimizerTests/fullInliner/no_inline_into_big_function.yul14
-rw-r--r--test/libyul/yulOptimizerTests/fullInliner/no_inline_into_big_global_context.yul14
-rw-r--r--test/libyul/yulOptimizerTests/fullInliner/not_inside_for.yul6
-rw-r--r--test/libyul/yulOptimizerTests/fullInliner/pop_result.yul2
-rw-r--r--test/libyul/yulOptimizerTests/fullInliner/simple.yul2
-rw-r--r--test/libyul/yulOptimizerTests/fullSuite/abi_example1.yul23
16 files changed, 50 insertions, 47 deletions
diff --git a/libyul/optimiser/FullInliner.cpp b/libyul/optimiser/FullInliner.cpp
index 04005847..95360dc3 100644
--- a/libyul/optimiser/FullInliner.cpp
+++ b/libyul/optimiser/FullInliner.cpp
@@ -168,6 +168,8 @@ vector<Statement> InlineModifier::performInline(Statement& _statement, FunctionC
m_driver.tentativelyUpdateCodeSize(function->name, m_currentFunction);
+ static Expression const zero{Literal{{}, LiteralKind::Number, YulString{"0"}, {}}};
+
// helper function to create a new variable that is supposed to model
// an existing variable.
auto newVariable = [&](TypedName const& _existingVariable, Expression* _value) {
@@ -176,6 +178,8 @@ vector<Statement> InlineModifier::performInline(Statement& _statement, FunctionC
VariableDeclaration varDecl{_funCall.location, {{_funCall.location, newName, _existingVariable.type}}, {}};
if (_value)
varDecl.value = make_shared<Expression>(std::move(*_value));
+ else
+ varDecl.value = make_shared<Expression>(zero);
newStatements.emplace_back(std::move(varDecl));
};
diff --git a/test/libyul/yulOptimizerTests/fullInliner/double_inline.yul b/test/libyul/yulOptimizerTests/fullInliner/double_inline.yul
index ee7f5bf5..b3f51593 100644
--- a/test/libyul/yulOptimizerTests/fullInliner/double_inline.yul
+++ b/test/libyul/yulOptimizerTests/fullInliner/double_inline.yul
@@ -9,14 +9,14 @@
// {
// {
// let f_a := calldataload(0)
-// let f_b
-// let f_c
+// let f_b := 0
+// let f_c := 0
// f_b := sload(mload(f_a))
// f_c := 3
// let b3 := f_b
// let f_a_2 := f_c
-// let f_b_3
-// let f_c_4
+// let f_b_3 := 0
+// let f_c_4 := 0
// f_b_3 := sload(mload(f_a_2))
// f_c_4 := 3
// let b4 := f_b_3
diff --git a/test/libyul/yulOptimizerTests/fullInliner/inside_condition.yul b/test/libyul/yulOptimizerTests/fullInliner/inside_condition.yul
index 00bb6577..9e6c4e76 100644
--- a/test/libyul/yulOptimizerTests/fullInliner/inside_condition.yul
+++ b/test/libyul/yulOptimizerTests/fullInliner/inside_condition.yul
@@ -14,7 +14,7 @@
// {
// let _2 := mload(0)
// let f_a := mload(1)
-// let f_r
+// let f_r := 0
// f_a := mload(f_a)
// f_r := add(f_a, calldatasize())
// if gt(f_r, _2)
diff --git a/test/libyul/yulOptimizerTests/fullInliner/large_function_multi_use.yul b/test/libyul/yulOptimizerTests/fullInliner/large_function_multi_use.yul
index e0dad8b8..c00b1163 100644
--- a/test/libyul/yulOptimizerTests/fullInliner/large_function_multi_use.yul
+++ b/test/libyul/yulOptimizerTests/fullInliner/large_function_multi_use.yul
@@ -23,7 +23,7 @@
// let a2 := 2
// let r := f(a_1)
// let f_a := a2
-// let f_b
+// let f_b := 0
// let f_x := mload(f_a)
// f_b := sload(f_x)
// let f_y := add(f_a, f_x)
@@ -31,7 +31,7 @@
// let t := f_b
// let a3
// let f_a_3 := a3
-// let f_b_4
+// let f_b_4 := 0
// let f_x_5 := mload(f_a_3)
// f_b_4 := sload(f_x_5)
// let f_y_6 := add(f_a_3, f_x_5)
diff --git a/test/libyul/yulOptimizerTests/fullInliner/large_function_single_use.yul b/test/libyul/yulOptimizerTests/fullInliner/large_function_single_use.yul
index 3302a35c..72beb8b1 100644
--- a/test/libyul/yulOptimizerTests/fullInliner/large_function_single_use.yul
+++ b/test/libyul/yulOptimizerTests/fullInliner/large_function_single_use.yul
@@ -15,7 +15,7 @@
// {
// {
// let f_a := mload(1)
-// let f_b
+// let f_b := 0
// let f_x := mload(f_a)
// f_b := sload(f_x)
// let f_c := 3
diff --git a/test/libyul/yulOptimizerTests/fullInliner/long_names.yul b/test/libyul/yulOptimizerTests/fullInliner/long_names.yul
index 644e9126..869abbc9 100644
--- a/test/libyul/yulOptimizerTests/fullInliner/long_names.yul
+++ b/test/libyul/yulOptimizerTests/fullInliner/long_names.yul
@@ -13,7 +13,7 @@
// {
// let verylongvariablename2_1 := 3
// let verylongfu_verylongvariablename := verylongvariablename2_1
-// let verylongfu_verylongvariablename2
+// let verylongfu_verylongvariablename2 := 0
// verylongfu_verylongvariablename2 := add(verylongfu_verylongvariablename, verylongfu_verylongvariablename)
// mstore(0, verylongfu_verylongvariablename2)
// mstore(1, verylongvariablename2_1)
diff --git a/test/libyul/yulOptimizerTests/fullInliner/move_up_rightwards_argument.yul b/test/libyul/yulOptimizerTests/fullInliner/move_up_rightwards_argument.yul
index f3d0b286..0b46a3c6 100644
--- a/test/libyul/yulOptimizerTests/fullInliner/move_up_rightwards_argument.yul
+++ b/test/libyul/yulOptimizerTests/fullInliner/move_up_rightwards_argument.yul
@@ -15,7 +15,7 @@
// let f_a := mload(2)
// let f_b := _6
// let f_c := _4
-// let f_x
+// let f_x := 0
// f_x := add(f_a, f_b)
// f_x := mul(f_x, f_c)
// let _10 := add(f_x, _2)
diff --git a/test/libyul/yulOptimizerTests/fullInliner/multi_fun.yul b/test/libyul/yulOptimizerTests/fullInliner/multi_fun.yul
index 8bc6ec58..5d658e96 100644
--- a/test/libyul/yulOptimizerTests/fullInliner/multi_fun.yul
+++ b/test/libyul/yulOptimizerTests/fullInliner/multi_fun.yul
@@ -9,11 +9,11 @@
// {
// let _1 := 7
// let f_a := 3
-// let f_x
+// let f_x := 0
// f_x := add(f_a, f_a)
// let g_b := f_x
// let g_c := _1
-// let g_y
+// let g_y := 0
// g_y := mul(mload(g_c), f(g_b))
// let y_1 := g_y
// }
@@ -24,7 +24,7 @@
// function g(b, c) -> y
// {
// let f_a_6 := b
-// let f_x_7
+// let f_x_7 := 0
// f_x_7 := add(f_a_6, f_a_6)
// y := mul(mload(c), f_x_7)
// }
diff --git a/test/libyul/yulOptimizerTests/fullInliner/multi_fun_callback.yul b/test/libyul/yulOptimizerTests/fullInliner/multi_fun_callback.yul
index 19ac945e..6e4acb97 100644
--- a/test/libyul/yulOptimizerTests/fullInliner/multi_fun_callback.yul
+++ b/test/libyul/yulOptimizerTests/fullInliner/multi_fun_callback.yul
@@ -37,7 +37,7 @@
// function f(x)
// {
// mstore(0, x)
-// let h_t
+// let h_t := 0
// h_t := 2
// mstore(7, h_t)
// let g_x_1 := 10
diff --git a/test/libyul/yulOptimizerTests/fullInliner/multi_return.yul b/test/libyul/yulOptimizerTests/fullInliner/multi_return.yul
index eebdec38..a4cbbef0 100644
--- a/test/libyul/yulOptimizerTests/fullInliner/multi_return.yul
+++ b/test/libyul/yulOptimizerTests/fullInliner/multi_return.yul
@@ -11,8 +11,8 @@
// {
// {
// let f_a := mload(0)
-// let f_x
-// let f_y
+// let f_x := 0
+// let f_y := 0
// f_x := mul(f_a, f_a)
// f_y := add(f_a, f_x)
// let r := f_x
diff --git a/test/libyul/yulOptimizerTests/fullInliner/no_inline_into_big_function.yul b/test/libyul/yulOptimizerTests/fullInliner/no_inline_into_big_function.yul
index 7b1558c0..f59e2c11 100644
--- a/test/libyul/yulOptimizerTests/fullInliner/no_inline_into_big_function.yul
+++ b/test/libyul/yulOptimizerTests/fullInliner/no_inline_into_big_function.yul
@@ -19,25 +19,25 @@
// function g() -> x_1
// {
// let f_a := 2
-// let f_b
+// let f_b := 0
// f_b := sload(mload(f_a))
// let f_a_20 := f_b
-// let f_b_21
+// let f_b_21 := 0
// f_b_21 := sload(mload(f_a_20))
// let f_a_23 := f_b_21
-// let f_b_24
+// let f_b_24 := 0
// f_b_24 := sload(mload(f_a_23))
// let f_a_26 := f_b_24
-// let f_b_27
+// let f_b_27 := 0
// f_b_27 := sload(mload(f_a_26))
// let f_a_29 := f_b_27
-// let f_b_30
+// let f_b_30 := 0
// f_b_30 := sload(mload(f_a_29))
// let f_a_32 := f_b_30
-// let f_b_33
+// let f_b_33 := 0
// f_b_33 := sload(mload(f_a_32))
// let f_a_35 := f_b_33
-// let f_b_36
+// let f_b_36 := 0
// f_b_36 := sload(mload(f_a_35))
// x_1 := f(f(f(f(f(f(f(f(f(f(f(f(f_b_36))))))))))))
// }
diff --git a/test/libyul/yulOptimizerTests/fullInliner/no_inline_into_big_global_context.yul b/test/libyul/yulOptimizerTests/fullInliner/no_inline_into_big_global_context.yul
index c8c49d39..f20b7221 100644
--- a/test/libyul/yulOptimizerTests/fullInliner/no_inline_into_big_global_context.yul
+++ b/test/libyul/yulOptimizerTests/fullInliner/no_inline_into_big_global_context.yul
@@ -12,25 +12,25 @@
// {
// {
// let f_a := 2
-// let f_b
+// let f_b := 0
// f_b := sload(mload(f_a))
// let f_a_20 := f_b
-// let f_b_21
+// let f_b_21 := 0
// f_b_21 := sload(mload(f_a_20))
// let f_a_23 := f_b_21
-// let f_b_24
+// let f_b_24 := 0
// f_b_24 := sload(mload(f_a_23))
// let f_a_26 := f_b_24
-// let f_b_27
+// let f_b_27 := 0
// f_b_27 := sload(mload(f_a_26))
// let f_a_29 := f_b_27
-// let f_b_30
+// let f_b_30 := 0
// f_b_30 := sload(mload(f_a_29))
// let f_a_32 := f_b_30
-// let f_b_33
+// let f_b_33 := 0
// f_b_33 := sload(mload(f_a_32))
// let f_a_35 := f_b_33
-// let f_b_36
+// let f_b_36 := 0
// f_b_36 := sload(mload(f_a_35))
// let x_1 := f(f(f(f(f(f(f(f(f(f(f(f(f_b_36))))))))))))
// }
diff --git a/test/libyul/yulOptimizerTests/fullInliner/not_inside_for.yul b/test/libyul/yulOptimizerTests/fullInliner/not_inside_for.yul
index 9644e6c1..96d806bd 100644
--- a/test/libyul/yulOptimizerTests/fullInliner/not_inside_for.yul
+++ b/test/libyul/yulOptimizerTests/fullInliner/not_inside_for.yul
@@ -14,7 +14,7 @@
// {
// for {
// let f_a := 0
-// let f_r
+// let f_r := 0
// sstore(f_a, 0)
// f_r := f_a
// let x := f_r
@@ -22,14 +22,14 @@
// f(x)
// {
// let f_a_3 := x
-// let f_r_4
+// let f_r_4 := 0
// sstore(f_a_3, 0)
// f_r_4 := f_a_3
// x := f_r_4
// }
// {
// let f_a_6 := x
-// let f_r_7
+// let f_r_7 := 0
// sstore(f_a_6, 0)
// f_r_7 := f_a_6
// let t := f_r_7
diff --git a/test/libyul/yulOptimizerTests/fullInliner/pop_result.yul b/test/libyul/yulOptimizerTests/fullInliner/pop_result.yul
index cd9e2746..c1bed208 100644
--- a/test/libyul/yulOptimizerTests/fullInliner/pop_result.yul
+++ b/test/libyul/yulOptimizerTests/fullInliner/pop_result.yul
@@ -14,7 +14,7 @@
// {
// let _1 := 2
// let f_a := 7
-// let f_x
+// let f_x := 0
// let f_r := mul(f_a, f_a)
// f_x := add(f_r, f_r)
// pop(add(f_x, _1))
diff --git a/test/libyul/yulOptimizerTests/fullInliner/simple.yul b/test/libyul/yulOptimizerTests/fullInliner/simple.yul
index fcdf453b..1ada8f53 100644
--- a/test/libyul/yulOptimizerTests/fullInliner/simple.yul
+++ b/test/libyul/yulOptimizerTests/fullInliner/simple.yul
@@ -11,7 +11,7 @@
// {
// let _2 := mload(7)
// let f_a := sload(mload(2))
-// let f_x
+// let f_x := 0
// let f_r := mul(f_a, f_a)
// f_x := add(f_r, f_r)
// let y := add(f_x, _2)
diff --git a/test/libyul/yulOptimizerTests/fullSuite/abi_example1.yul b/test/libyul/yulOptimizerTests/fullSuite/abi_example1.yul
index a3d59ff4..efb846f2 100644
--- a/test/libyul/yulOptimizerTests/fullSuite/abi_example1.yul
+++ b/test/libyul/yulOptimizerTests/fullSuite/abi_example1.yul
@@ -463,12 +463,11 @@
// let _2 := 0
// let _485 := mload(_2)
// let abi_encode_pos := _1
-// let abi_encode_end_67_610
// let abi_encode_length_68 := mload(_485)
// mstore(_1, abi_encode_length_68)
// abi_encode_pos := 64
// let abi_encode_srcPtr := add(_485, _1)
-// let abi_encode_i_69 := abi_encode_end_67_610
+// let abi_encode_i_69 := _2
// for {
// }
// lt(abi_encode_i_69, abi_encode_length_68)
@@ -476,21 +475,21 @@
// abi_encode_i_69 := add(abi_encode_i_69, 1)
// }
// {
-// let _857 := mload(abi_encode_srcPtr)
-// let abi_encode_pos_71_965 := abi_encode_pos
-// let abi_encode_length_72_966 := 0x3
-// let abi_encode_srcPtr_73_967 := _857
-// let abi_encode_i_74_968 := _2
+// let _863 := mload(abi_encode_srcPtr)
+// let abi_encode_pos_71_971 := abi_encode_pos
+// let abi_encode_length_72_972 := 0x3
+// let abi_encode_srcPtr_73_973 := _863
+// let abi_encode_i_74_974 := _2
// for {
// }
-// lt(abi_encode_i_74_968, abi_encode_length_72_966)
+// lt(abi_encode_i_74_974, abi_encode_length_72_972)
// {
-// abi_encode_i_74_968 := add(abi_encode_i_74_968, 1)
+// abi_encode_i_74_974 := add(abi_encode_i_74_974, 1)
// }
// {
-// mstore(abi_encode_pos_71_965, and(mload(abi_encode_srcPtr_73_967), 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))
-// abi_encode_srcPtr_73_967 := add(abi_encode_srcPtr_73_967, _1)
-// abi_encode_pos_71_965 := add(abi_encode_pos_71_965, _1)
+// mstore(abi_encode_pos_71_971, and(mload(abi_encode_srcPtr_73_973), 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))
+// abi_encode_srcPtr_73_973 := add(abi_encode_srcPtr_73_973, _1)
+// abi_encode_pos_71_971 := add(abi_encode_pos_71_971, _1)
// }
// abi_encode_srcPtr := add(abi_encode_srcPtr, _1)
// abi_encode_pos := add(abi_encode_pos, 0x60)