Skip to content

Commit 4140240

Browse files
authored
[SYCL] Disable clang pedantic diagnostics in header/footer (#15171)
When -Wreserved-identifer or -Wold-style-cast is enabled, some of the constructs used in integration headers and footers for device_globals and host_pipes trigger a diagnostic. This change adds a pragma to the generated files that suppress the diagnostic prior to the construct and reenabled the diagnostic after.
1 parent e8fcff1 commit 4140240

File tree

6 files changed

+64
-9
lines changed

6 files changed

+64
-9
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6029,6 +6029,23 @@ static void OutputStableNameInChars(raw_ostream &O, StringRef Name) {
60296029
}
60306030
}
60316031

6032+
static void EmitPragmaDiagnosticPush(raw_ostream &O, StringRef DiagName) {
6033+
O << "\n";
6034+
O << "#ifdef __clang__\n";
6035+
O << "#pragma clang diagnostic push\n";
6036+
O << "#pragma clang diagnostic ignored \"" << DiagName.str() << "\"\n";
6037+
O << "#endif // defined(__clang__)\n";
6038+
O << "\n";
6039+
}
6040+
6041+
static void EmitPragmaDiagnosticPop(raw_ostream &O) {
6042+
O << "\n";
6043+
O << "#ifdef __clang__\n";
6044+
O << "#pragma clang diagnostic pop\n";
6045+
O << "#endif // defined(__clang__)\n";
6046+
O << "\n";
6047+
}
6048+
60326049
void SYCLIntegrationHeader::emit(raw_ostream &O) {
60336050
O << "// This is auto-generated SYCL integration header.\n";
60346051
O << "\n";
@@ -6127,6 +6144,9 @@ void SYCLIntegrationHeader::emit(raw_ostream &O) {
61276144
// main() function.
61286145

61296146
if (NeedToEmitDeviceGlobalRegistration) {
6147+
// Supress the reserved identifier diagnostic that clang generates
6148+
// for the construct below.
6149+
EmitPragmaDiagnosticPush(O, "-Wreserved-identifier");
61306150
O << "namespace {\n";
61316151

61326152
O << "class __sycl_device_global_registration {\n";
@@ -6138,12 +6158,16 @@ void SYCLIntegrationHeader::emit(raw_ostream &O) {
61386158
O << "} // namespace\n";
61396159

61406160
O << "\n";
6161+
EmitPragmaDiagnosticPop(O);
61416162
}
61426163

61436164
// Generate declaration of variable of type __sycl_host_pipe_registration
61446165
// whose sole purpose is to run its constructor before the application's
61456166
// main() function.
61466167
if (NeedToEmitHostPipeRegistration) {
6168+
// Supress the reserved identifier diagnostic that clang generates
6169+
// for the construct below.
6170+
EmitPragmaDiagnosticPush(O, "-Wreserved-identifier");
61476171
O << "namespace {\n";
61486172

61496173
O << "class __sycl_host_pipe_registration {\n";
@@ -6155,6 +6179,7 @@ void SYCLIntegrationHeader::emit(raw_ostream &O) {
61556179
O << "} // namespace\n";
61566180

61576181
O << "\n";
6182+
EmitPragmaDiagnosticPop(O);
61586183
}
61596184

61606185

@@ -6723,12 +6748,16 @@ bool SYCLIntegrationFooter::emit(raw_ostream &OS) {
67236748
OS << "#include <sycl/detail/device_global_map.hpp>\n";
67246749
DeviceGlobOS.flush();
67256750
OS << "namespace sycl::detail {\n";
6751+
// Supress the old-style case diagnostic that clang generates
6752+
// for the construct below in DeviceGlobalsBuf.
6753+
EmitPragmaDiagnosticPush(OS, "-Wold-style-cast");
67266754
OS << "namespace {\n";
67276755
OS << "__sycl_device_global_registration::__sycl_device_global_"
67286756
"registration() noexcept {\n";
67296757
OS << DeviceGlobalsBuf;
67306758
OS << "}\n";
67316759
OS << "} // namespace (unnamed)\n";
6760+
EmitPragmaDiagnosticPop(OS);
67326761
OS << "} // namespace sycl::detail\n";
67336762

67346763
S.getSyclIntegrationHeader().addDeviceGlobalRegistration();
@@ -6738,12 +6767,16 @@ bool SYCLIntegrationFooter::emit(raw_ostream &OS) {
67386767
OS << "#include <sycl/detail/host_pipe_map.hpp>\n";
67396768
HostPipesOS.flush();
67406769
OS << "namespace sycl::detail {\n";
6770+
// Supress the old-style case diagnostic that clang generates
6771+
// for the construct below in HostPipesBuf.
6772+
EmitPragmaDiagnosticPush(OS, "-Wold-style-cast");
67416773
OS << "namespace {\n";
67426774
OS << "__sycl_host_pipe_registration::__sycl_host_pipe_"
67436775
"registration() noexcept {\n";
67446776
OS << HostPipesBuf;
67456777
OS << "}\n";
67466778
OS << "} // namespace (unnamed)\n";
6779+
EmitPragmaDiagnosticPop(OS);
67476780
OS << "} // namespace sycl::detail\n";
67486781

67496782
S.getSyclIntegrationHeader().addHostPipeRegistration();

clang/test/CodeGenSYCL/device_global_int_footer_header.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,20 @@ int main() {
1616
// CHECK-HEADER: namespace sycl {
1717
// CHECK-HEADER-NEXT: inline namespace _V1 {
1818
// CHECK-HEADER-NEXT: namespace detail {
19-
// CHECK-HEADER-NEXT: namespace {
19+
// CHECK-HEADER: #ifdef __clang__
20+
// CHECK-HEADER-NEXT: #pragma clang diagnostic push
21+
// CHECK-HEADER-NEXT: #pragma clang diagnostic ignored "-Wreserved-identifier"
22+
// CHECK-HEADER-NEXT: #endif // defined(__clang__)
23+
// CHECK-HEADER: namespace {
2024
// CHECK-HEADER-NEXT: class __sycl_device_global_registration {
2125
// CHECK-HEADER-NEXT: public:
2226
// CHECK-HEADER-NEXT: __sycl_device_global_registration() noexcept;
2327
// CHECK-HEADER-NEXT: };
2428
// CHECK-HEADER-NEXT: __sycl_device_global_registration __sycl_device_global_registrar;
2529
// CHECK-HEADER-NEXT: } // namespace
30+
// CHECK-HEADER: #ifdef __clang__
31+
// CHECK-HEADER-NEXT: #pragma clang diagnostic pop
32+
// CHECK-HEADER-NEXT: #endif // defined(__clang__)
2633
// CHECK-HEADER: } // namespace detail
2734
// CHECK-HEADER: } // namespace _V1
2835
// CHECK-HEADER: } // namespace sycl
@@ -49,7 +56,11 @@ int main() {
4956

5057
// CHECK-FOOTER: #include <sycl/detail/device_global_map.hpp>
5158
// CHECK-FOOTER: namespace sycl::detail {
52-
// CHECK-FOOTER-NEXT: namespace {
59+
// CHECK-FOOTER: #ifdef __clang__
60+
// CHECK-FOOTER-NEXT: #pragma clang diagnostic push
61+
// CHECK-FOOTER-NEXT: #pragma clang diagnostic ignored "-Wold-style-cast"
62+
// CHECK-FOOTER-NEXT: #endif // defined(__clang__)
63+
// CHECK-FOOTER: namespace {
5364
// CHECK-FOOTER-NEXT: __sycl_device_global_registration::__sycl_device_global_registration() noexcept {
5465

5566
extern device_global<int> Basic;
@@ -111,3 +122,6 @@ struct HasVarTemplate {
111122
} // namespace
112123
const auto x = HasVarTemplate::VarTempl<int>.get();
113124
// CHECK-FOOTER-NEXT: device_global_map::add((void *)&::__sycl_detail::__shim_[[SHIM1]](), "THE_PREFIX____ZN12_GLOBAL__N_114HasVarTemplate8VarTemplIiEE");
125+
// CHECK-FOOTER: #ifdef __clang__
126+
// CHECK-FOOTER-NEXT: #pragma clang diagnostic pop
127+
// CHECK-FOOTER-NEXT: #endif // defined(__clang__)

clang/test/CodeGenSYCL/device_globals_with_spec_ids.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ struct Wrapper {
249249
// CHECK: #include <sycl/detail/spec_const_integration.hpp>
250250
// CHECK-NEXT: #include <sycl/detail/device_global_map.hpp>
251251
// CHECK-NEXT: namespace sycl::detail {
252-
// CHECK-NEXT: namespace {
252+
// CHECK: namespace {
253253
// CHECK-NEXT: __sycl_device_global_registration::__sycl_device_global_registration() noexcept {
254254
// CHECK-NEXT: device_global_map::add((void *)&::b, "_Z1b");
255255
// CHECK-NEXT: device_global_map::add((void *)&::Wrapper::b, "_ZN7Wrapper1bE");
@@ -260,4 +260,4 @@ struct Wrapper {
260260
// CHECK-NEXT: device_global_map::add((void *)&::outer::__sycl_detail::__shim_[[SHIM11]](), "____ZN5outer12_GLOBAL__N_15inner12_GLOBAL__N_17Wrapper1cE");
261261
// CHECK-NEXT: }
262262
// CHECK-NEXT: } // namespace (unnamed)
263-
// CHECK-NEXT: } // namespace sycl::detail
263+
// CHECK: } // namespace sycl::detail

clang/test/CodeGenSYCL/host_pipe_int_footer_header.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void foo() {
2323
// CHECK-HEADER: namespace sycl {
2424
// CHECK-HEADER-NEXT: inline namespace _V1 {
2525
// CHECK-HEADER-NEXT: namespace detail {
26-
// CHECK-HEADER-NEXT: namespace {
26+
// CHECK-HEADER: namespace {
2727
// CHECK-HEADER-NEXT: class __sycl_host_pipe_registration {
2828
// CHECK-HEADER-NEXT: public:
2929
// CHECK-HEADER-NEXT: __sycl_host_pipe_registration() noexcept;
@@ -37,7 +37,7 @@ void foo() {
3737
// CHECK-FOOTER: #include <sycl/detail/defines_elementary.hpp>
3838
// CHECK-FOOTER: #include <sycl/detail/host_pipe_map.hpp>
3939
// CHECK-FOOTER-NEXT: namespace sycl::detail {
40-
// CHECK-FOOTER-NEXT: namespace {
40+
// CHECK-FOOTER: namespace {
4141
// CHECK-FOOTER-NEXT: __sycl_host_pipe_registration::__sycl_host_pipe_registration() noexcept {
4242

4343
// CHECK-FOOTER: host_pipe_map::add((void *)&::sycl::ext::intel::experimental::host_pipe<HPInt, int>::__pipe, "THE_PREFIX____ZN4sycl3_V13ext5intel12experimental9host_pipeIZZZ3foovENKUlRNS0_7handlerEE_clES6_ENKUlvE_clEvE5HPIntiE6__pipeE");

clang/test/CodeGenSYCL/int_header_without_kernels.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ using namespace sycl::ext::oneapi;
1212
// CHECK-HEADER: namespace sycl {
1313
// CHECK-HEADER-NEXT: inline namespace _V1 {
1414
// CHECK-HEADER-NEXT: namespace detail {
15-
// CHECK-HEADER-NEXT: namespace {
15+
// CHECK-HEADER: namespace {
1616
// CHECK-HEADER-NEXT: class __sycl_device_global_registration {
1717
// CHECK-HEADER-NEXT: public:
1818
// CHECK-HEADER-NEXT: __sycl_device_global_registration() noexcept;
@@ -27,12 +27,12 @@ using namespace sycl::ext::oneapi;
2727

2828
// CHECK-FOOTER: #include <sycl/detail/device_global_map.hpp>
2929
// CHECK-FOOTER: namespace sycl::detail {
30-
// CHECK-FOOTER-NEXT: namespace {
30+
// CHECK-FOOTER: namespace {
3131
// CHECK-FOOTER-NEXT: __sycl_device_global_registration::__sycl_device_global_registration() noexcept {
3232

3333
device_global<int> Basic;
3434
// CHECK-FOOTER-NEXT: device_global_map::add((void *)&::Basic, "_Z5Basic");
3535

3636
// CHECK-FOOTER-NEXT: }
3737
// CHECK-FOOTER-NEXT: }
38-
// CHECK-FOOTER-NEXT: }
38+
// CHECK-FOOTER: }
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %clangxx -fsycl -Werror=reserved-identifier -Werror=old-style-cast %s
2+
3+
// Check that the generated header and footer files do not generate
4+
// errors when pedantic warnings are enabled.
5+
6+
#include <sycl/sycl.hpp>
7+
sycl::ext::oneapi::experimental::device_global<int> devGlobVar;
8+
int main(int argc, char **argv) { return 0; }

0 commit comments

Comments
 (0)