Skip to content

Commit 37a3de1

Browse files
committed
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
1 parent 27313b6 commit 37a3de1

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
_CLC_OVERLOAD _CLC_DEF __CLC_U_GENTYPE abs_diff(__CLC_GENTYPE x, __CLC_GENTYPE y) {
2-
return __builtin_astype((__CLC_GENTYPE)(x > y ? x-y : y-x), __CLC_U_GENTYPE);
2+
__CLC_U_GENTYPE ux = __builtin_astype(x, __CLC_U_GENTYPE);
3+
__CLC_U_GENTYPE uy = __builtin_astype(y, __CLC_U_GENTYPE);
4+
return x > y ? ux - uy : uy - ux;
35
}

0 commit comments

Comments
 (0)