Out of Memory crash when optimizing code containing shifts, ternary and bitwise operators on storage variables via IR
- Dominant language
- C++
- Stars
- 25.7k
- Forks
- 6.2k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 29
Description
## Description
Given the following contract:
```
contract Test {
int8 b;
int8 c;
int8 o;
int8 d;
int8 e;
int8 f;
bool g;
int8 h;
int8 i;
uint112 j;
int8 k;
int8 l;
int8 m;
int8 n;
constructor() {
c = k <<= 0 <= j ? j : 0;
o <<= j;
f = m >> j;
g = (e >>= 0) >= (g ? int40(0) : int56(0));
l = h &= d <<= j;
n = (o = b) | (h >>= 0) << (0 <= i ? 0 : j);
}
}
```
I get an out of memory error when running `solc --bin --optimize --via-ir Test.sol`. I can't reproduce the issue with either the `--optimize` or `--via-ir` flags set separately, or with both omitted. I have run this on two machines both with 32GB RAM and both OOM. Here is the dmesg output from one machine:
```
oom-kill:constraint=CONSTRAINT_NONE,nodemask=(null),cpuset=/,mems_allowed=0,global_oom,task_memcg=/user.slice/user-1000.slice/user@1000.service,task=solc-0.8.18,pid=301840,uid=1000
Out of memory: Killed process 301840 (solc-0.8.18) total-vm:22943372kB, anon-rss:22925304kB, file-rss:0kB, shmem-rss:0kB, UID:1000 pgtables:44944kB oom_score_adj:0
```
## Environment
- Compiler version: 0.8.18+commit.87f61d96.Linux.g++
- Operating system: Ubuntu 20.04
Contributor guide
Research direction
Save the contract from the issue as Test.sol and first run solc 0.8.18 with --bin --optimize --via-ir, confirming the reported out-of-memory behavior and comparing it with each flag separately. Trace the IR optimization path responsible for the memory growth; done means the combined command completes without exhausting memory for this reproducer.
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
- Mostly clear
- Newbie friendliness
- 35/100