Issue 162717
Summary Failure to match signed sub overflow test idiom
Labels new issue
Assignees
Reporter sh1boot
    Checking for signed integer overflow after an addItion seems to work fine, but this subtraction test gives bad code on multiple architectures (every one I tried, both 32-bit and 64-bit):

```c++
bool idiomatic_check_sub(int x, int y) {
    int64_t result = int64_t(x) - int64_t(y);
    return !(INT_MIN <= result && result <= INT_MAX);
}

bool expected_check_sub(int x, int y) {
    int result;
 return __builtin_ssub_overflow(x, y, &result);
}
```
https://godbolt.org/z/a91sjPzGz

I haven't checked but this issue may generalise across overflow tests for multiple destination data types.  And presumably there's another pattern which people would use when there's no larger temporary type, but I have tested any of those yet.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to