[PATCH] D159275: libclc: Fix signed integer underflow in abs_diff

Fraser Cormack via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 31 06:28:28 PDT 2023


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG37a3de1e2eed: libclc: Fix signed integer underflow in abs_diff (authored by frasercrmck).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159275/new/

https://reviews.llvm.org/D159275

Files:
  libclc/generic/lib/integer/abs_diff.inc


Index: libclc/generic/lib/integer/abs_diff.inc
===================================================================
--- libclc/generic/lib/integer/abs_diff.inc
+++ 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;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159275.555013.patch
Type: text/x-patch
Size: 549 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230831/49219095/attachment.bin>


More information about the llvm-commits mailing list