Issue 53374
Summary LLVM fails to detect/remove unreachable branch
Labels new issue
Assignees
Reporter y21
    First issue here, so not sure if this is a duplicate, but
```c
#include <stdlib.h>

int divide(int x, int y) {
    y += (y == 0);

    if (y == 0) {
        // unreachable
        abort();
    }

    return x / y;
}
```
`y` can logically never be zero past the first line (if `y == 0`, then it will be set to 1), [yet the abort branch is still emitted](https://gcc.godbolt.org/z/MPPao4Koq). Replacing `abort();` with `__builtin_unreachable();` gets rid of it. 

Originally found this in Rust code, where the `rhs == 0` check is [implicitly inserted due to the division](https://godbolt.org/z/fbxqs7s6n)
```rs
pub fn divide(x: u32, mut y: u32) -> u32 {
    y += (y == 0) as u32;
    x / y
}
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to