Author: Fraser Cormack Date: 2023-08-31T14:28:16+01:00 New Revision: 37a3de1e2eedf848b8442217ef3790436f69a7db
URL: https://github.com/llvm/llvm-project/commit/37a3de1e2eedf848b8442217ef3790436f69a7db DIFF: https://github.com/llvm/llvm-project/commit/37a3de1e2eedf848b8442217ef3790436f69a7db.diff LOG: libclc: Fix signed integer underflow in abs_diff We noticed this same issue in our own implementation of abs_diff, and the same issue also came up in the abs_diff reference function in the OpenCL CTS. Reviewed By: rjodinchr Differential Revision: https://reviews.llvm.org/D159275 Added: Modified: libclc/generic/lib/integer/abs_diff.inc Removed: ################################################################################ diff --git a/libclc/generic/lib/integer/abs_ diff .inc b/libclc/generic/lib/integer/abs_ diff .inc index f39c3ff4d3e8ab..2d3c492cae0e68 100644 --- a/libclc/generic/lib/integer/abs_ diff .inc +++ b/libclc/generic/lib/integer/abs_ diff .inc @@ -1,3 +1,5 @@ _CLC_OVERLOAD _CLC_DEF __CLC_U_GENTYPE abs_ diff (__CLC_GENTYPE x, __CLC_GENTYPE y) { - return __builtin_astype((__CLC_GENTYPE)(x > y ? x-y : y-x), __CLC_U_GENTYPE); + __CLC_U_GENTYPE ux = __builtin_astype(x, __CLC_U_GENTYPE); + __CLC_U_GENTYPE uy = __builtin_astype(y, __CLC_U_GENTYPE); + return x > y ? ux - uy : uy - ux; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits