[MDEV-21977] main.func_math fails due to undefined behaviour Created: 2020-03-18 Updated: 2022-03-29 Resolved: 2020-03-20 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Data types |
| Affects Version/s: | 5.5, 10.0, 10.1, 10.2, 10.3, 10.4, 10.5 |
| Fix Version/s: | 10.1.45, 10.2.32, 10.3.23, 10.4.13, 10.5.2 |
| Type: | Bug | Priority: | Major |
| Reporter: | Marko Mäkelä | Assignee: | Alexander Barkov |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | UBSAN, wrong_result | ||
| Issue Links: |
|
||||||||||||||||
| Description |
|
The test main.func_math fails on kvm-deb-sid-x86 since the creation of that builder:
The query would wrongly return -9223372036854775808 (0x8000000000000000 in two’s complement signed 64-bit arithmetics). The reason is that undefined behavior allows GCC to optimize away the overflow check. I was able to repeat the failure locally using GCC 9.3.0 and the following invocation:
and the following patch:
Another build cmake -DWITH_UBSAN reported the error:
In the 32-bit build, I noticed that the res= uval0 / uval1 in Item_func_int_div::val_int() is expanded into 4 call __udivdi3. In the code path that is executed for the problematic test, the call to the inlined function Item::check_integer_overflow() is optimized away. The undefined behavior gives the permission for this optimization. It is only a coincidence that it is not being optimized away for other architectures. We do not run the builder for older versions than 10.3, but I believe that any version should be potentially affected by this. |
| Comments |
| Comment by Alexander Barkov [ 2020-03-20 ] | |||||||||||||||
|
The UBSAN error is repeatable on Fedora 31 x86_64:
returns the following related errors (with some other non-related errors):
These two source lines are in:
|