julia
047f9ee0 - Try to avoid undefined behavior in runtime intrinsics (#31548)

Commit
6 years ago
Try to avoid undefined behavior in runtime intrinsics (#31548) The analyzer complains ``` /home/keno/julia/src/runtime_intrinsics.c:886:38: note: The result of the left shift is undefined because the left operand is negative checked_iintrinsic_fast(LLVMSub_sov, check_ssub_int, sub, checked_ssub_int, ) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/keno/julia/src/runtime_intrinsics.c:510:25: note: expanded from macro 'checked_iintrinsic_fast' checked_intrinsic_ctype(CHECK_OP, OP, name, 64, u##int##64_t) \ ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/keno/julia/src/runtime_intrinsics.c:251:12: note: expanded from macro '\ checked_intrinsic_ctype' return CHECK_OP(a, b); \ ^~~~~~~~~~~~~~ /home/keno/julia/src/runtime_intrinsics.c:885:49: note: expanded from macro 'check_ssub_int' (b >= 0) ? (a < sTYPEMIN(a) + b) : (a > sTYPEMAX(a) + b) ^~~~~~~~~~~ /home/keno/julia/src/runtime_intrinsics.c:868:23: note: expanded from macro 'sTYPEMAX' ? ~((a - a + ~0) << (8 * sizeof(a) - 1)) \ ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~ 16 warnings generated. ``` And indeed shifting a negative number to the left is undefined in `C`. Try an alternative expression for these that hopefully steers clear of any UB.
Author
Parents
Loading