Skip to content

The issue when using clang 21 with the -O2 compilation flag #165847

@solomonwzs

Description

@solomonwzs

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
cedarpp.h

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions