Skip to content

[clang] Clang unnecessarily removes code during optimization (regression) #149802

@damiandcoherent

Description

@damiandcoherent

Putting these lines at the beginning of a function causes clang to remove the entire function. Does not happen if dummy variable inside the if is removed. Can cause strange jumps to other functions. The UB does not cause this in GCC/MSVC.

unsigned A = 32;
unsigned B = 1 << A;
if (B) { unsigned Dummy; }

Clang version: 15+, works fine in clang 14.
Optimization level: -O1 or higher

https://godbolt.org/z/554qxxnbz

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:codegenIR generation bugs: mangling, exceptions, etc.clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerundefined behaviour

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions