Optimizer failed to remove statement always true
- Dominant language
- C++
- Stars
- 25.7k
- Forks
- 6.2k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 29
Description
## Description
For the following contract
```solidity
pragma solidity ^0.8.0;
contract ComplexProgram {
uint256 public globalVariable;
struct MyStruct {
uint256 value;
bool flag;
}
function complexFunction() public view{
MyStruct memory myStruct;
myStruct.flag = true;
uint256 x = 1;
require(globalVariable != 0, "Global variable cannot be zero");
assert(myStruct.flag == true);//failed to optimize
assert(x == 1);
}
}
```
The IR optimizer failed to remove ``assert(myStruct.flag == true);``.
But if i move the statement to the before of ``require(globalVariable != 0, "Global variable cannot be zero");``.
It can be optimized.
```solidity
pragma solidity ^0.8.0;
contract ComplexProgram {
uint256 public globalVariable;
struct MyStruct {
uint256 value;
bool flag;
}
function complexFunction() public view{
MyStruct memory myStruct;
myStruct.flag = true;
uint256 x = 1;
assert(myStruct.flag == true);//can be optimized
require(globalVariable != 0, "Global variable cannot be zero");
assert(x == 1);
}
}
```
## Environment
- Compiler version: 0.8.19
- Framework/IDE (e.g. Truffle or Remix): Remix
Contributor guide
Research direction
Start by reproducing the issue with the Solidity contract in the description using compiler version 0.8.19 and the IR optimizer. Compare the generated optimized IR when the assert precedes versus follows require; done means the always-true assertion is removed in both cases without changing observable behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, solidity
- Domain
- blockchain, compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100