diff options
author | Fraser Cormack <fraser@codeplay.com> | 2023-08-31 13:41:53 +0100 |
---|---|---|
committer | Fraser Cormack <fraser@codeplay.com> | 2023-08-31 14:28:16 +0100 |
commit | 37a3de1e2eedf848b8442217ef3790436f69a7db (patch) | |
tree | 2b39ddc6421cb08d21621ca18413da3a0932a88f /libclc | |
parent | 27313b68ef0ec9a94c4288eca9af6ca25cd17f8f (diff) | |
download | llvm-37a3de1e2eedf848b8442217ef3790436f69a7db.zip llvm-37a3de1e2eedf848b8442217ef3790436f69a7db.tar.gz llvm-37a3de1e2eedf848b8442217ef3790436f69a7db.tar.bz2 |
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
Diffstat (limited to 'libclc')
-rw-r--r-- | libclc/generic/lib/integer/abs_diff.inc | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/libclc/generic/lib/integer/abs_diff.inc b/libclc/generic/lib/integer/abs_diff.inc index f39c3ff..2d3c492 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; } |