[libclc] [libclc] Make CLC library warning-free (PR #128864)

Fraser Cormack via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 26 03:23:25 PST 2025


https://github.com/frasercrmck created https://github.com/llvm/llvm-project/pull/128864

There is a long-standing workaround in the libclc build system that silences a warning about the use of parentheses in bitwise conditional operations.

In an effort to remove this workaround, this commit re-enables the warning on the internal CLC library, where most of the bodies of the builtins will eventually be defined. Thus as we move builtin implementations into this library, the warnings will trigger and we can clean up the codebase as we go.

As it happens the only instance in the CLC library which triggered the warning was in __clc_ldexp.

>From 82b81dcc02358157a7a10677d075e04451aa5891 Mon Sep 17 00:00:00 2001
From: Fraser Cormack <fraser at codeplay.com>
Date: Wed, 26 Feb 2025 10:58:39 +0000
Subject: [PATCH] [libclc] Make CLC library warning-free

There is a long-standing workaround in the libclc build system that
silences a warning about the use of parentheses in bitwise conditional
operations.

In an effort to remove this workaround, this commit re-enables the
warning on the internal CLC library, where most of the bodies of the
builtins will eventually be defined. Thus as we move builtin
implementations into this library, the warnings will trigger and we can
clean up the codebase as we go.

As it happens the only instance in the CLC library which triggered the
warning was in __clc_ldexp.
---
 libclc/CMakeLists.txt                    | 4 ++--
 libclc/clc/lib/generic/math/clc_ldexp.cl | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index c1a1dd42bcb46..fb5f3638bc4e4 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -377,8 +377,6 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
       -D${CLC_TARGET_DEFINE}
       # All libclc builtin libraries see CLC headers
       -I${CMAKE_CURRENT_SOURCE_DIR}/clc/include
-      # FIXME: Fix libclc to not require disabling this noisy warning
-      -Wno-bitwise-conditional-parentheses
     )
 
     if( NOT "${cpu}" STREQUAL "" )
@@ -400,6 +398,8 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
 
     list( APPEND build_flags
       -I${CMAKE_CURRENT_SOURCE_DIR}/generic/include
+      # FIXME: Fix libclc to not require disabling this noisy warning
+      -Wno-bitwise-conditional-parentheses
     )
 
     add_libclc_builtin_set(
diff --git a/libclc/clc/lib/generic/math/clc_ldexp.cl b/libclc/clc/lib/generic/math/clc_ldexp.cl
index ad54755bee276..5e9cc83201d6e 100644
--- a/libclc/clc/lib/generic/math/clc_ldexp.cl
+++ b/libclc/clc/lib/generic/math/clc_ldexp.cl
@@ -41,7 +41,7 @@ _CLC_DEF_ldexp _CLC_OVERLOAD float __clc_ldexp(float x, int n) {
     int s = i & 0x80000000;
     int v = __clc_add_sat(e, n);
     v = __clc_clamp(v, 0, 0xff);
-    int mr = e == 0 | v == 0 | v == 0xff ? 0 : m;
+    int mr = (e == 0 || v == 0 || v == 0xff) ? 0 : m;
     int c = e == 0xff;
     mr = c ? m : mr;
     int er = c ? e : v;
@@ -96,7 +96,7 @@ _CLC_DEF_ldexp _CLC_OVERLOAD float __clc_ldexp(float x, int n) {
   val_ui = dexp == 0 ? dval_ui : val_ui;
   val_f = __clc_as_float(val_ui);
 
-  val_f = __clc_isnan(x) | __clc_isinf(x) | val_x == 0 ? x : val_f;
+  val_f = (__clc_isnan(x) || __clc_isinf(x) || val_x == 0) ? x : val_f;
   return val_f;
 }
 



More information about the cfe-commits mailing list