Skip to content

Commit 6c6a53a

Browse files
committed
Do not create unassigned variables.
1 parent 11209ec commit 6c6a53a

16 files changed

+50
-47
lines changed

libyul/optimiser/FullInliner.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ vector<Statement> InlineModifier::performInline(Statement& _statement, FunctionC
168168

169169
m_driver.tentativelyUpdateCodeSize(function->name, m_currentFunction);
170170

171+
static Expression const zero{Literal{{}, LiteralKind::Number, YulString{"0"}, {}}};
172+
171173
// helper function to create a new variable that is supposed to model
172174
// an existing variable.
173175
auto newVariable = [&](TypedName const& _existingVariable, Expression* _value) {
@@ -176,6 +178,8 @@ vector<Statement> InlineModifier::performInline(Statement& _statement, FunctionC
176178
VariableDeclaration varDecl{_funCall.location, {{_funCall.location, newName, _existingVariable.type}}, {}};
177179
if (_value)
178180
varDecl.value = make_shared<Expression>(std::move(*_value));
181+
else
182+
varDecl.value = make_shared<Expression>(zero);
179183
newStatements.emplace_back(std::move(varDecl));
180184
};
181185

test/libyul/yulOptimizerTests/fullInliner/double_inline.yul

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
// {
1010
// {
1111
// let f_a := calldataload(0)
12-
// let f_b
13-
// let f_c
12+
// let f_b := 0
13+
// let f_c := 0
1414
// f_b := sload(mload(f_a))
1515
// f_c := 3
1616
// let b3 := f_b
1717
// let f_a_2 := f_c
18-
// let f_b_3
19-
// let f_c_4
18+
// let f_b_3 := 0
19+
// let f_c_4 := 0
2020
// f_b_3 := sload(mload(f_a_2))
2121
// f_c_4 := 3
2222
// let b4 := f_b_3

test/libyul/yulOptimizerTests/fullInliner/inside_condition.yul

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// {
1515
// let _2 := mload(0)
1616
// let f_a := mload(1)
17-
// let f_r
17+
// let f_r := 0
1818
// f_a := mload(f_a)
1919
// f_r := add(f_a, calldatasize())
2020
// if gt(f_r, _2)

test/libyul/yulOptimizerTests/fullInliner/large_function_multi_use.yul

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
// let a2 := 2
2424
// let r := f(a_1)
2525
// let f_a := a2
26-
// let f_b
26+
// let f_b := 0
2727
// let f_x := mload(f_a)
2828
// f_b := sload(f_x)
2929
// let f_y := add(f_a, f_x)
3030
// sstore(f_y, 10)
3131
// let t := f_b
3232
// let a3
3333
// let f_a_3 := a3
34-
// let f_b_4
34+
// let f_b_4 := 0
3535
// let f_x_5 := mload(f_a_3)
3636
// f_b_4 := sload(f_x_5)
3737
// let f_y_6 := add(f_a_3, f_x_5)

test/libyul/yulOptimizerTests/fullInliner/large_function_single_use.yul

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// {
1616
// {
1717
// let f_a := mload(1)
18-
// let f_b
18+
// let f_b := 0
1919
// let f_x := mload(f_a)
2020
// f_b := sload(f_x)
2121
// let f_c := 3

test/libyul/yulOptimizerTests/fullInliner/long_names.yul

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// {
1414
// let verylongvariablename2_1 := 3
1515
// let verylongfu_verylongvariablename := verylongvariablename2_1
16-
// let verylongfu_verylongvariablename2
16+
// let verylongfu_verylongvariablename2 := 0
1717
// verylongfu_verylongvariablename2 := add(verylongfu_verylongvariablename, verylongfu_verylongvariablename)
1818
// mstore(0, verylongfu_verylongvariablename2)
1919
// mstore(1, verylongvariablename2_1)

test/libyul/yulOptimizerTests/fullInliner/move_up_rightwards_argument.yul

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// let f_a := mload(2)
1616
// let f_b := _6
1717
// let f_c := _4
18-
// let f_x
18+
// let f_x := 0
1919
// f_x := add(f_a, f_b)
2020
// f_x := mul(f_x, f_c)
2121
// let _10 := add(f_x, _2)

test/libyul/yulOptimizerTests/fullInliner/multi_fun.yul

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
// {
1010
// let _1 := 7
1111
// let f_a := 3
12-
// let f_x
12+
// let f_x := 0
1313
// f_x := add(f_a, f_a)
1414
// let g_b := f_x
1515
// let g_c := _1
16-
// let g_y
16+
// let g_y := 0
1717
// g_y := mul(mload(g_c), f(g_b))
1818
// let y_1 := g_y
1919
// }
@@ -24,7 +24,7 @@
2424
// function g(b, c) -> y
2525
// {
2626
// let f_a_6 := b
27-
// let f_x_7
27+
// let f_x_7 := 0
2828
// f_x_7 := add(f_a_6, f_a_6)
2929
// y := mul(mload(c), f_x_7)
3030
// }

test/libyul/yulOptimizerTests/fullInliner/multi_fun_callback.yul

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
// function f(x)
3838
// {
3939
// mstore(0, x)
40-
// let h_t
40+
// let h_t := 0
4141
// h_t := 2
4242
// mstore(7, h_t)
4343
// let g_x_1 := 10

test/libyul/yulOptimizerTests/fullInliner/multi_return.yul

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
// {
1212
// {
1313
// let f_a := mload(0)
14-
// let f_x
15-
// let f_y
14+
// let f_x := 0
15+
// let f_y := 0
1616
// f_x := mul(f_a, f_a)
1717
// f_y := add(f_a, f_x)
1818
// let r := f_x

0 commit comments

Comments
 (0)