[llvm] [libsycl][NFC] Suppress shadow warnings from LLVM headers (PR #225089)

Sergey Semenov via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 21 08:56:09 PDT 2026


https://github.com/sergey-semenov updated https://github.com/llvm/llvm-project/pull/225089

>From a86336d4a8cbf4629eea279a05e8880cb9145354 Mon Sep 17 00:00:00 2001
From: Sergey Semenov <sergey.semenov at intel.com>
Date: Mon, 21 Sep 2026 06:13:39 -0700
Subject: [PATCH 1/3] [libsycl][NFC] Suppress shadow warnings from LLVM headers

The warning for a local variable shadowing a class member is enabled
for libsycl, but not LLVM as a whole. Suppress those for included LLVM
headers.
---
 libsycl/src/detail/device_image_wrapper.hpp | 4 ++++
 libsycl/src/detail/program_manager.cpp      | 4 ++++
 libsycl/src/detail/program_manager.hpp      | 4 ++++
 3 files changed, 12 insertions(+)

diff --git a/libsycl/src/detail/device_image_wrapper.hpp b/libsycl/src/detail/device_image_wrapper.hpp
index 5d639a2fe2970..510f075649150 100644
--- a/libsycl/src/detail/device_image_wrapper.hpp
+++ b/libsycl/src/detail/device_image_wrapper.hpp
@@ -17,9 +17,13 @@
 
 #include <sycl/__impl/detail/config.hpp>
 
+// Suppress some additional warnings enabled in libsycl for LLVM headers.
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wshadow"
 #include <llvm/Object/OffloadBinary.h>
 
 #include <OffloadAPI.h>
+#pragma GCC diagnostic pop
 
 #include <memory>
 #include <string_view>
diff --git a/libsycl/src/detail/program_manager.cpp b/libsycl/src/detail/program_manager.cpp
index c594f8fe6542e..78e79c310fb99 100644
--- a/libsycl/src/detail/program_manager.cpp
+++ b/libsycl/src/detail/program_manager.cpp
@@ -15,7 +15,11 @@
 #include <detail/device_impl.hpp>
 #include <detail/offload/offload_utils.hpp>
 
+// Suppress some additional warnings enabled in libsycl for LLVM headers.
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wshadow"
 #include <llvm/Frontend/Offloading/Utility.h>
+#pragma GCC diagnostic pop
 
 _LIBSYCL_BEGIN_NAMESPACE_SYCL
 namespace detail {
diff --git a/libsycl/src/detail/program_manager.hpp b/libsycl/src/detail/program_manager.hpp
index 64df1834fc8cc..0e94ed1d69b98 100644
--- a/libsycl/src/detail/program_manager.hpp
+++ b/libsycl/src/detail/program_manager.hpp
@@ -21,9 +21,13 @@
 #include <detail/device_image_wrapper.hpp>
 #include <detail/device_kernel_info.hpp>
 
+// Suppress some additional warnings enabled in libsycl for LLVM headers.
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wshadow"
 #include <llvm/Object/OffloadBinary.h>
 
 #include <OffloadAPI.h>
+#pragma GCC diagnostic pop
 
 #include <memory>
 #include <mutex>

>From 536ad534a0a914c8475fe6b454a047661d0a2407 Mon Sep 17 00:00:00 2001
From: Sergey Semenov <sergey.semenov at intel.com>
Date: Mon, 21 Sep 2026 08:01:10 -0700
Subject: [PATCH 2/3] Add macros

---
 libsycl/src/detail/device_image_wrapper.hpp   |  8 ++++----
 libsycl/src/detail/program_manager.cpp        |  6 ++----
 libsycl/src/detail/program_manager.hpp        |  7 +++----
 .../src/detail/suppress_extra_warnings.hpp    | 20 +++++++++++++++++++
 4 files changed, 29 insertions(+), 12 deletions(-)
 create mode 100644 libsycl/src/detail/suppress_extra_warnings.hpp

diff --git a/libsycl/src/detail/device_image_wrapper.hpp b/libsycl/src/detail/device_image_wrapper.hpp
index 510f075649150..2831993f6e962 100644
--- a/libsycl/src/detail/device_image_wrapper.hpp
+++ b/libsycl/src/detail/device_image_wrapper.hpp
@@ -17,13 +17,13 @@
 
 #include <sycl/__impl/detail/config.hpp>
 
-// Suppress some additional warnings enabled in libsycl for LLVM headers.
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wshadow"
+#include <detail/suppress_extra_warnings.hpp>
+
+_LIBSYCL_SUPPRESS_EXTRA_WARNINGS_BEGIN
 #include <llvm/Object/OffloadBinary.h>
+_LIBSYCL_SUPPRESS_EXTRA_WARNINGS_END
 
 #include <OffloadAPI.h>
-#pragma GCC diagnostic pop
 
 #include <memory>
 #include <string_view>
diff --git a/libsycl/src/detail/program_manager.cpp b/libsycl/src/detail/program_manager.cpp
index 78e79c310fb99..12a38a8b75053 100644
--- a/libsycl/src/detail/program_manager.cpp
+++ b/libsycl/src/detail/program_manager.cpp
@@ -15,11 +15,9 @@
 #include <detail/device_impl.hpp>
 #include <detail/offload/offload_utils.hpp>
 
-// Suppress some additional warnings enabled in libsycl for LLVM headers.
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wshadow"
+_LIBSYCL_SUPPRESS_EXTRA_WARNINGS_BEGIN
 #include <llvm/Frontend/Offloading/Utility.h>
-#pragma GCC diagnostic pop
+_LIBSYCL_SUPPRESS_EXTRA_WARNINGS_END
 
 _LIBSYCL_BEGIN_NAMESPACE_SYCL
 namespace detail {
diff --git a/libsycl/src/detail/program_manager.hpp b/libsycl/src/detail/program_manager.hpp
index 0e94ed1d69b98..afe660add63f7 100644
--- a/libsycl/src/detail/program_manager.hpp
+++ b/libsycl/src/detail/program_manager.hpp
@@ -20,14 +20,13 @@
 #include <detail/device_binary_structures.hpp>
 #include <detail/device_image_wrapper.hpp>
 #include <detail/device_kernel_info.hpp>
+#include <detail/suppress_extra_warnings.hpp>
 
-// Suppress some additional warnings enabled in libsycl for LLVM headers.
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wshadow"
+_LIBSYCL_SUPPRESS_EXTRA_WARNINGS_BEGIN
 #include <llvm/Object/OffloadBinary.h>
+_LIBSYCL_SUPPRESS_EXTRA_WARNINGS_END
 
 #include <OffloadAPI.h>
-#pragma GCC diagnostic pop
 
 #include <memory>
 #include <mutex>
diff --git a/libsycl/src/detail/suppress_extra_warnings.hpp b/libsycl/src/detail/suppress_extra_warnings.hpp
new file mode 100644
index 0000000000000..9b435ee4b4b03
--- /dev/null
+++ b/libsycl/src/detail/suppress_extra_warnings.hpp
@@ -0,0 +1,20 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains macros for suppressing extra warnings enabled in libsycl
+/// for LLVM headers.
+///
+//===----------------------------------------------------------------------===//
+
+#define _LIBSYCL_DO_PRAGMA(x) _Pragma(#x)
+#define _LIBSYCL_SUPPRESS_EXTRA_WARNINGS_BEGIN                                 \
+  _LIBSYCL_DO_PRAGMA(GCC diagnostic push)                                      \
+  _LIBSYCL_DO_PRAGMA(GCC diagnostic ignored "-Wshadow")
+#define _LIBSYCL_SUPPRESS_EXTRA_WARNINGS_END                                   \
+  _LIBSYCL_DO_PRAGMA(GCC diagnostic pop)

>From b291bd2ce6263a9abd58ece287dc2d512c0e73bf Mon Sep 17 00:00:00 2001
From: Sergey Semenov <sergey.semenov at intel.com>
Date: Mon, 21 Sep 2026 08:30:11 -0700
Subject: [PATCH 3/3] Add ifdef guards

---
 libsycl/src/detail/suppress_extra_warnings.hpp | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/libsycl/src/detail/suppress_extra_warnings.hpp b/libsycl/src/detail/suppress_extra_warnings.hpp
index 9b435ee4b4b03..e6fcbb65a432e 100644
--- a/libsycl/src/detail/suppress_extra_warnings.hpp
+++ b/libsycl/src/detail/suppress_extra_warnings.hpp
@@ -12,9 +12,14 @@
 ///
 //===----------------------------------------------------------------------===//
 
+#ifndef _LIBSYCL_SUPPRESS_EXTRA_WARNINGS
+#define _LIBSYCL_SUPPRESS_EXTRA_WARNINGS
+
 #define _LIBSYCL_DO_PRAGMA(x) _Pragma(#x)
 #define _LIBSYCL_SUPPRESS_EXTRA_WARNINGS_BEGIN                                 \
   _LIBSYCL_DO_PRAGMA(GCC diagnostic push)                                      \
   _LIBSYCL_DO_PRAGMA(GCC diagnostic ignored "-Wshadow")
 #define _LIBSYCL_SUPPRESS_EXTRA_WARNINGS_END                                   \
   _LIBSYCL_DO_PRAGMA(GCC diagnostic pop)
+
+#endif // _LIBSYCL_SUPPRESS_EXTRA_WARNINGS



More information about the llvm-commits mailing list