-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Yul expression simplifier: Don't substitute out of scope variables #16161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
test/cmdlineTests/yul_optimizer_steps_invalid_substitution_in_expression_simplifier/args
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--optimize --yul-optimizations Md[F]vtDI[jxVpjCDpTnvon]TFSI[v]:Etcns --via-ir --bin |
101 changes: 101 additions & 0 deletions
101
.../cmdlineTests/yul_optimizer_steps_invalid_substitution_in_expression_simplifier/input.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
// reproducing https://github.com/ethereum/solidity/issues/16155 | ||
|
||
pragma solidity ^0.8.19; | ||
|
||
contract PlaceholderContract { | ||
function tZhBDeXU4NnUR6(bool assert_in1) internal virtual returns (int128) { | ||
return (( | ||
(assert_in1 && false) | ||
? (int128(638) - int128(932)) | ||
: (assert_in1 ? int128(923) : int128(392)) | ||
) / ((int128(517) * int128(573)) / (int128(273) % int128(605)))); | ||
} | ||
|
||
function QtdPeAwoi7LD( | ||
bool assert_in1, | ||
bool assert_in2 | ||
) internal pure returns (int128) { | ||
return (( | ||
(assert_in2 || assert_in1) | ||
? (int128(478) % int128(983)) | ||
: (int128(298) + int128(316)) | ||
) + | ||
( | ||
(assert_in1 && assert_in1) | ||
? (int128(71) / int128(885)) | ||
: (-int128(596)) | ||
)); | ||
} | ||
|
||
function fmMG$apfQ14W86hu_3M( | ||
bool assert_out2 | ||
) internal virtual returns (bool) { | ||
return assert_out2; | ||
} | ||
|
||
function check_entrypoint( | ||
bool /*assert_in0*/, | ||
bool assert_in1, | ||
bool assert_in2, | ||
bool /*assert_in3*/ | ||
) public { | ||
unchecked { | ||
bool assert_out1 = (tZhBDeXU4NnUR6(assert_in1) < | ||
QtdPeAwoi7LD(assert_in1, assert_in2)); | ||
bool assert_out2 = (((( | ||
false | ||
? (int128(638) - int128(932)) | ||
: (((( | ||
(!(!assert_in1)) | ||
? int128(923) | ||
: ((int128(392) + (int128(0) & int128(82))) & | ||
((int128(0) + int128(392)) & int128(392))) | ||
) + int128(0)) - (int128(77) & int128(0))) / | ||
(int128(1) | int128(0))) | ||
) / | ||
((int128(573) * int128(517)) / | ||
(-(-(-(int128(0) + (-(int128(273) % int128(605))))))))) < | ||
(( | ||
(true && (assert_in2 || assert_in1)) | ||
? (((int128(478) % int128(983)) - int128(76)) + | ||
int128(76)) | ||
: (int128(298) + int128(316)) | ||
) + | ||
( | ||
assert_in1 | ||
? (int128(73) + | ||
((((int128(71) - int128(94)) + int128(94)) / | ||
int128(885)) - int128(73))) | ||
: (-int128(596)) | ||
))) || | ||
((((int128(0) | | ||
( | ||
false | ||
? (int128(638) - int128(932)) | ||
: (( | ||
(!(!(!(!assert_in1)))) | ||
? int128(923) | ||
: (int128(392) & | ||
((int128(82) & int128(0)) + | ||
int128(392))) | ||
) | int128(0)) | ||
)) / | ||
((int128(573) * int128(517)) / | ||
((-(-(-(int128(0) - (int128(273) % int128(605)))))) + | ||
int128(0)))) | int128(0)) < | ||
(( | ||
(((assert_in2 || assert_in1) && true) && true) | ||
? (int128(478) % int128(983)) | ||
: (int128(298) + int128(316)) | ||
) + | ||
( | ||
((true && assert_in1) && assert_in1) | ||
? (((int128(71) - int128(94)) + int128(94)) / | ||
int128(885)) | ||
: (-int128(596)) | ||
)))); | ||
assert((assert_out1 == fmMG$apfQ14W86hu_3M(assert_out2))); | ||
} | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
test/cmdlineTests/yul_optimizer_steps_invalid_substitution_in_expression_simplifier/output
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
======= input.sol:PlaceholderContract ======= | ||
Binary: | ||
<BYTECODE REMOVED> |
34 changes: 34 additions & 0 deletions
34
test/libyul/yulOptimizerTests/expressionSimplifier/invalid_match.yul
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// regression test for https://github.com/ethereum/solidity/issues/16155 | ||
{ | ||
function identity(value) -> ret { ret := value } | ||
|
||
function f() -> ret | ||
{ | ||
let id1 := identity(0x01) | ||
let x := 0x05 | ||
{ | ||
let const_six := 0x06 | ||
let id2 := identity(0x01) | ||
x := or(0x06, id2) | ||
} | ||
// check that we don't substitute `or(const_six, id2)` for `x` | ||
ret := or(id1, x) | ||
} | ||
|
||
mstore(42, f()) | ||
} | ||
// ---- | ||
// step: expressionSimplifier | ||
// | ||
// { | ||
// { mstore(42, f()) } | ||
// function identity(value) -> ret | ||
// { ret := value } | ||
// function f() -> ret_1 | ||
// { | ||
// let id1 := identity(0x01) | ||
// let x := 0x05 | ||
// { x := or(0x06, id1) } | ||
// ret_1 := or(id1, x) | ||
// } | ||
// } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.