ExpressionSimplifier references variables declared in loop body when simplifying the post block
- Dominant language
- C++
- Stars
- 25.7k
- Forks
- 6.2k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 29
Description
## Description
Hi! I tried to compile the following Solidity code using `solc-latest --optimize --yul-optimizations 'xajs' --bin out.sol`, enabling the custom optimization sequence `xajs`. solc threw an `Invalid assembly/yul code` exception.
```solidity
contract Test {
function g() private returns(bool) {
assembly {
for {
let x := 1
let y := 1
}
iszero(eq(x, 10))
{
x := add(x, y)
}
{ x := add(x, 1) }
}
return true;
}
function f() public returns(bool) {
return g();
}
}
```
Output:
```
Uncaught exception:
/solidity/libyul/AsmAnalysis.cpp(111): Throw in function static solidity::yul::AsmAnalysisInfo solidity::yul::AsmAnalyzer::analyzeStrictAssertCorrect(const solidity::yul::Dialect&, const solidity::yul::Block&, solidity::yul::Object::Structure)
Dynamic exception type: boost::wrapexcept
std::exception::what: Invalid assembly/yul code.
[solidity::util::tag_comment*] = Invalid assembly/yul code.
```
## Environment
- Compiler version: `solc-0.8.25+`
Contributor guide
Research direction
Reproduce the failure with the supplied Solidity contract and the `solc-latest --optimize --yul-optimizations 'xajs'` command. Inspect the ExpressionSimplifier behavior around loop-body variables and the failure reported at `libyul/AsmAnalysis.cpp:111`; done means the example no longer produces invalid assembly/Yul code.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, solidity
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100