From a9fa9429d51098c73e769b2b504798d8560dde54 Mon Sep 17 00:00:00 2001 From: Harikrishnan Mulackal Date: Fri, 15 May 2020 20:46:50 +0530 Subject: [PATCH 1/2] Fixed bug in BlockDeDuplicator --- libevmasm/BlockDeduplicator.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libevmasm/BlockDeduplicator.cpp b/libevmasm/BlockDeduplicator.cpp index 9a26db8ca..decfee650 100644 --- a/libevmasm/BlockDeduplicator.cpp +++ b/libevmasm/BlockDeduplicator.cpp @@ -113,6 +113,10 @@ bool BlockDeduplicator::applyTagReplacement( if (subId != _subId) continue; auto it = _replacements.find(tagId); + // Recursively look for the element replaced by tagId + for (auto _it = it; _it != _replacements.end(); _it = _replacements.find(_it->second)) + it = _it; + if (it != _replacements.end()) { changed = true; From 4a291f85512f534096f9e017202999d016f24fc1 Mon Sep 17 00:00:00 2001 From: Harikrishnan Mulackal Date: Mon, 18 May 2020 11:57:07 +0530 Subject: [PATCH 2/2] Changelog and test --- Changelog.md | 2 +- .../optimizer_BlockDeDuplicator/args | 1 + .../optimizer_BlockDeDuplicator/err | 11 ++ .../optimizer_BlockDeDuplicator/input.sol | 9 ++ .../optimizer_BlockDeDuplicator/output | 107 ++++++++++++++++++ 5 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 test/cmdlineTests/optimizer_BlockDeDuplicator/args create mode 100644 test/cmdlineTests/optimizer_BlockDeDuplicator/err create mode 100644 test/cmdlineTests/optimizer_BlockDeDuplicator/input.sol create mode 100644 test/cmdlineTests/optimizer_BlockDeDuplicator/output diff --git a/Changelog.md b/Changelog.md index cf1565913..cfd281893 100644 --- a/Changelog.md +++ b/Changelog.md @@ -9,7 +9,7 @@ Compiler Features: Bugfixes: - + * Optimizer: Fixed a bug in BlockDeDuplicator. ### 0.6.8 (2020-05-14) diff --git a/test/cmdlineTests/optimizer_BlockDeDuplicator/args b/test/cmdlineTests/optimizer_BlockDeDuplicator/args new file mode 100644 index 000000000..8942fcc35 --- /dev/null +++ b/test/cmdlineTests/optimizer_BlockDeDuplicator/args @@ -0,0 +1 @@ +--optimize --asm --metadata-hash none diff --git a/test/cmdlineTests/optimizer_BlockDeDuplicator/err b/test/cmdlineTests/optimizer_BlockDeDuplicator/err new file mode 100644 index 000000000..e29fc4fc3 --- /dev/null +++ b/test/cmdlineTests/optimizer_BlockDeDuplicator/err @@ -0,0 +1,11 @@ +Warning: Statement has no effect. + --> optimizer_BlockDeDuplicator/input.sol:7:27: + | +7 | function f() public { true ? 1 : 3;} + | ^^^^^^^^^^^^ + +Warning: Function state mutability can be restricted to pure + --> optimizer_BlockDeDuplicator/input.sol:7:5: + | +7 | function f() public { true ? 1 : 3;} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/test/cmdlineTests/optimizer_BlockDeDuplicator/input.sol b/test/cmdlineTests/optimizer_BlockDeDuplicator/input.sol new file mode 100644 index 000000000..3f75fa240 --- /dev/null +++ b/test/cmdlineTests/optimizer_BlockDeDuplicator/input.sol @@ -0,0 +1,9 @@ +// SPDX-License-Identifier: GPL-3.0 +pragma solidity >=0.0; + +contract C { + function fun_x() public {} + function fun_() public {} + function f() public { true ? 1 : 3;} + function() r = true ? fun_x : f; +} diff --git a/test/cmdlineTests/optimizer_BlockDeDuplicator/output b/test/cmdlineTests/optimizer_BlockDeDuplicator/output new file mode 100644 index 000000000..6f11f97a4 --- /dev/null +++ b/test/cmdlineTests/optimizer_BlockDeDuplicator/output @@ -0,0 +1,107 @@ + +======= optimizer_BlockDeDuplicator/input.sol:C ======= +EVM assembly: + /* "optimizer_BlockDeDuplicator/input.sol":60:213 contract C {... */ + mstore(0x40, 0x80) + /* "optimizer_BlockDeDuplicator/input.sol":179:210 function() r = true ? fun_x : f */ + 0x00 + dup1 + sload + not(sub(shl(0x40, 0x01), 0x01)) + and + /* "optimizer_BlockDeDuplicator/input.sol":201:206 fun_x */ + or(tag_0_7, shl(0x20, tag_4)) + sub(shl(0x40, 0x01), 0x01) + /* "optimizer_BlockDeDuplicator/input.sol":179:210 function() r = true ? fun_x : f */ + and + or + swap1 + sstore + /* "optimizer_BlockDeDuplicator/input.sol":60:213 contract C {... */ + callvalue + /* "--CODEGEN--":2:4 */ + dup1 + iszero + tag_5 + jumpi + /* "--CODEGEN--":27:28 */ + 0x00 + /* "--CODEGEN--":24:25 */ + dup1 + /* "--CODEGEN--":17:29 */ + revert + /* "--CODEGEN--":2:4 */ +tag_5: + /* "optimizer_BlockDeDuplicator/input.sol":60:213 contract C {... */ + pop + jump(tag_6) + /* "optimizer_BlockDeDuplicator/input.sol":77:103 function fun_x() public {} */ +tag_4: + jump // out + /* "optimizer_BlockDeDuplicator/input.sol":60:213 contract C {... */ +tag_6: + dataSize(sub_0) + dup1 + dataOffset(sub_0) + 0x00 + codecopy + 0x00 + return +stop + +sub_0: assembly { + /* "optimizer_BlockDeDuplicator/input.sol":60:213 contract C {... */ + mstore(0x40, 0x80) + callvalue + /* "--CODEGEN--":5:14 */ + dup1 + /* "--CODEGEN--":2:4 */ + iszero + tag_1 + jumpi + /* "--CODEGEN--":27:28 */ + 0x00 + /* "--CODEGEN--":24:25 */ + dup1 + /* "--CODEGEN--":17:29 */ + revert + /* "--CODEGEN--":2:4 */ + tag_1: + /* "optimizer_BlockDeDuplicator/input.sol":60:213 contract C {... */ + pop + jumpi(tag_2, lt(calldatasize, 0x04)) + shr(0xe0, calldataload(0x00)) + dup1 + 0x26121ff0 + eq + tag_3 + jumpi + dup1 + 0x2e1fb2bc + eq + tag_3 + jumpi + dup1 + 0x4753a67d + eq + tag_3 + jumpi + tag_2: + /* "--CODEGEN--":12:13 */ + 0x00 + /* "--CODEGEN--":9:10 */ + dup1 + /* "--CODEGEN--":2:14 */ + revert + /* "optimizer_BlockDeDuplicator/input.sol":138:174 function f() public { true ? 1 : 3;} */ + tag_3: + tag_6 + tag_7 + jump // in + tag_6: + stop + tag_7: + jump // out + + auxdata: AUXDATA REMOVED +}