The issue when using clang 21 with the `-O2` compilation flag
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Hello, I have a piece of code that, when compiled with clang 21 and the `-O2` flag, produces an executable that crashes with a coredump at runtime.
The problematic compilation command is:
```
clang++ -O2 main.cpp
```
However, if I omit the `-O2` flag, or use an older version of Clang or GCC to compile, the resulting executable runs without any issues. For example:
```
# Without `-O2`
clang++ main.cpp
# Using GCC
g++ main.cpp
g++ -O2 main.cpp
# Using an older version of Clang
/usr/lib/llvm20/bin/clang++ -O2 main.cpp
```
[main.cpp](https://github.com/user-attachments/files/23257372/main.cpp)
[cedarpp.h](https://github.com/DevO2012/cedar/blob/master/cedarpp.h)
Contributor guide
Research direction
Start by compiling the attached main.cpp with clang++ -O2 and inspect the resulting coredump. Compare the behavior with clang++ without -O2, /usr/lib/llvm20/bin/clang++ -O2, and g++ -O2, using cedarpp.h as referenced. Done means confirming the regression and isolating its cause sufficiently for the compiler team to act.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100