diff --git a/clang/lib/Sema/SemaSYCL.cpp b/clang/lib/Sema/SemaSYCL.cpp index 5cf06a33e016b..a3b2fb2728b55 100644 --- a/clang/lib/Sema/SemaSYCL.cpp +++ b/clang/lib/Sema/SemaSYCL.cpp @@ -6029,6 +6029,23 @@ static void OutputStableNameInChars(raw_ostream &O, StringRef Name) { } } +static void EmitPragmaDiagnosticPush(raw_ostream &O, StringRef DiagName) { + O << "\n"; + O << "#ifdef __clang__\n"; + O << "#pragma clang diagnostic push\n"; + O << "#pragma clang diagnostic ignored \"" << DiagName.str() << "\"\n"; + O << "#endif // defined(__clang__)\n"; + O << "\n"; +} + +static void EmitPragmaDiagnosticPop(raw_ostream &O) { + O << "\n"; + O << "#ifdef __clang__\n"; + O << "#pragma clang diagnostic pop\n"; + O << "#endif // defined(__clang__)\n"; + O << "\n"; +} + void SYCLIntegrationHeader::emit(raw_ostream &O) { O << "// This is auto-generated SYCL integration header.\n"; O << "\n"; @@ -6127,6 +6144,9 @@ void SYCLIntegrationHeader::emit(raw_ostream &O) { // main() function. if (NeedToEmitDeviceGlobalRegistration) { + // Supress the reserved identifier diagnostic that clang generates + // for the construct below. + EmitPragmaDiagnosticPush(O, "-Wreserved-identifier"); O << "namespace {\n"; O << "class __sycl_device_global_registration {\n"; @@ -6138,12 +6158,16 @@ void SYCLIntegrationHeader::emit(raw_ostream &O) { O << "} // namespace\n"; O << "\n"; + EmitPragmaDiagnosticPop(O); } // Generate declaration of variable of type __sycl_host_pipe_registration // whose sole purpose is to run its constructor before the application's // main() function. if (NeedToEmitHostPipeRegistration) { + // Supress the reserved identifier diagnostic that clang generates + // for the construct below. + EmitPragmaDiagnosticPush(O, "-Wreserved-identifier"); O << "namespace {\n"; O << "class __sycl_host_pipe_registration {\n"; @@ -6155,6 +6179,7 @@ void SYCLIntegrationHeader::emit(raw_ostream &O) { O << "} // namespace\n"; O << "\n"; + EmitPragmaDiagnosticPop(O); } @@ -6723,12 +6748,16 @@ bool SYCLIntegrationFooter::emit(raw_ostream &OS) { OS << "#include \n"; DeviceGlobOS.flush(); OS << "namespace sycl::detail {\n"; + // Supress the old-style case diagnostic that clang generates + // for the construct below in DeviceGlobalsBuf. + EmitPragmaDiagnosticPush(OS, "-Wold-style-cast"); OS << "namespace {\n"; OS << "__sycl_device_global_registration::__sycl_device_global_" "registration() noexcept {\n"; OS << DeviceGlobalsBuf; OS << "}\n"; OS << "} // namespace (unnamed)\n"; + EmitPragmaDiagnosticPop(OS); OS << "} // namespace sycl::detail\n"; S.getSyclIntegrationHeader().addDeviceGlobalRegistration(); @@ -6738,12 +6767,16 @@ bool SYCLIntegrationFooter::emit(raw_ostream &OS) { OS << "#include \n"; HostPipesOS.flush(); OS << "namespace sycl::detail {\n"; + // Supress the old-style case diagnostic that clang generates + // for the construct below in HostPipesBuf. + EmitPragmaDiagnosticPush(OS, "-Wold-style-cast"); OS << "namespace {\n"; OS << "__sycl_host_pipe_registration::__sycl_host_pipe_" "registration() noexcept {\n"; OS << HostPipesBuf; OS << "}\n"; OS << "} // namespace (unnamed)\n"; + EmitPragmaDiagnosticPop(OS); OS << "} // namespace sycl::detail\n"; S.getSyclIntegrationHeader().addHostPipeRegistration(); diff --git a/clang/test/CodeGenSYCL/device_global_int_footer_header.cpp b/clang/test/CodeGenSYCL/device_global_int_footer_header.cpp index 42793f34abdd5..2b32b41d966bb 100644 --- a/clang/test/CodeGenSYCL/device_global_int_footer_header.cpp +++ b/clang/test/CodeGenSYCL/device_global_int_footer_header.cpp @@ -16,13 +16,20 @@ int main() { // CHECK-HEADER: namespace sycl { // CHECK-HEADER-NEXT: inline namespace _V1 { // CHECK-HEADER-NEXT: namespace detail { -// CHECK-HEADER-NEXT: namespace { +// CHECK-HEADER: #ifdef __clang__ +// CHECK-HEADER-NEXT: #pragma clang diagnostic push +// CHECK-HEADER-NEXT: #pragma clang diagnostic ignored "-Wreserved-identifier" +// CHECK-HEADER-NEXT: #endif // defined(__clang__) +// CHECK-HEADER: namespace { // CHECK-HEADER-NEXT: class __sycl_device_global_registration { // CHECK-HEADER-NEXT: public: // CHECK-HEADER-NEXT: __sycl_device_global_registration() noexcept; // CHECK-HEADER-NEXT: }; // CHECK-HEADER-NEXT: __sycl_device_global_registration __sycl_device_global_registrar; // CHECK-HEADER-NEXT: } // namespace +// CHECK-HEADER: #ifdef __clang__ +// CHECK-HEADER-NEXT: #pragma clang diagnostic pop +// CHECK-HEADER-NEXT: #endif // defined(__clang__) // CHECK-HEADER: } // namespace detail // CHECK-HEADER: } // namespace _V1 // CHECK-HEADER: } // namespace sycl @@ -49,7 +56,11 @@ int main() { // CHECK-FOOTER: #include // CHECK-FOOTER: namespace sycl::detail { -// CHECK-FOOTER-NEXT: namespace { +// CHECK-FOOTER: #ifdef __clang__ +// CHECK-FOOTER-NEXT: #pragma clang diagnostic push +// CHECK-FOOTER-NEXT: #pragma clang diagnostic ignored "-Wold-style-cast" +// CHECK-FOOTER-NEXT: #endif // defined(__clang__) +// CHECK-FOOTER: namespace { // CHECK-FOOTER-NEXT: __sycl_device_global_registration::__sycl_device_global_registration() noexcept { extern device_global Basic; @@ -111,3 +122,6 @@ struct HasVarTemplate { } // namespace const auto x = HasVarTemplate::VarTempl.get(); // CHECK-FOOTER-NEXT: device_global_map::add((void *)&::__sycl_detail::__shim_[[SHIM1]](), "THE_PREFIX____ZN12_GLOBAL__N_114HasVarTemplate8VarTemplIiEE"); +// CHECK-FOOTER: #ifdef __clang__ +// CHECK-FOOTER-NEXT: #pragma clang diagnostic pop +// CHECK-FOOTER-NEXT: #endif // defined(__clang__) diff --git a/clang/test/CodeGenSYCL/device_globals_with_spec_ids.cpp b/clang/test/CodeGenSYCL/device_globals_with_spec_ids.cpp index 26fe81abb89f5..bbea2e58fcdaa 100644 --- a/clang/test/CodeGenSYCL/device_globals_with_spec_ids.cpp +++ b/clang/test/CodeGenSYCL/device_globals_with_spec_ids.cpp @@ -249,7 +249,7 @@ struct Wrapper { // CHECK: #include // CHECK-NEXT: #include // CHECK-NEXT: namespace sycl::detail { -// CHECK-NEXT: namespace { +// CHECK: namespace { // CHECK-NEXT: __sycl_device_global_registration::__sycl_device_global_registration() noexcept { // CHECK-NEXT: device_global_map::add((void *)&::b, "_Z1b"); // CHECK-NEXT: device_global_map::add((void *)&::Wrapper::b, "_ZN7Wrapper1bE"); @@ -260,4 +260,4 @@ struct Wrapper { // CHECK-NEXT: device_global_map::add((void *)&::outer::__sycl_detail::__shim_[[SHIM11]](), "____ZN5outer12_GLOBAL__N_15inner12_GLOBAL__N_17Wrapper1cE"); // CHECK-NEXT: } // CHECK-NEXT: } // namespace (unnamed) -// CHECK-NEXT: } // namespace sycl::detail +// CHECK: } // namespace sycl::detail diff --git a/clang/test/CodeGenSYCL/host_pipe_int_footer_header.cpp b/clang/test/CodeGenSYCL/host_pipe_int_footer_header.cpp index f6537fee5fc4c..2c56af7b0d003 100644 --- a/clang/test/CodeGenSYCL/host_pipe_int_footer_header.cpp +++ b/clang/test/CodeGenSYCL/host_pipe_int_footer_header.cpp @@ -23,7 +23,7 @@ void foo() { // CHECK-HEADER: namespace sycl { // CHECK-HEADER-NEXT: inline namespace _V1 { // CHECK-HEADER-NEXT: namespace detail { -// CHECK-HEADER-NEXT: namespace { +// CHECK-HEADER: namespace { // CHECK-HEADER-NEXT: class __sycl_host_pipe_registration { // CHECK-HEADER-NEXT: public: // CHECK-HEADER-NEXT: __sycl_host_pipe_registration() noexcept; @@ -37,7 +37,7 @@ void foo() { // CHECK-FOOTER: #include // CHECK-FOOTER: #include // CHECK-FOOTER-NEXT: namespace sycl::detail { -// CHECK-FOOTER-NEXT: namespace { +// CHECK-FOOTER: namespace { // CHECK-FOOTER-NEXT: __sycl_host_pipe_registration::__sycl_host_pipe_registration() noexcept { // CHECK-FOOTER: host_pipe_map::add((void *)&::sycl::ext::intel::experimental::host_pipe::__pipe, "THE_PREFIX____ZN4sycl3_V13ext5intel12experimental9host_pipeIZZZ3foovENKUlRNS0_7handlerEE_clES6_ENKUlvE_clEvE5HPIntiE6__pipeE"); diff --git a/clang/test/CodeGenSYCL/int_header_without_kernels.cpp b/clang/test/CodeGenSYCL/int_header_without_kernels.cpp index 05c4382cf6b09..fcbdb9a7c539a 100644 --- a/clang/test/CodeGenSYCL/int_header_without_kernels.cpp +++ b/clang/test/CodeGenSYCL/int_header_without_kernels.cpp @@ -12,7 +12,7 @@ using namespace sycl::ext::oneapi; // CHECK-HEADER: namespace sycl { // CHECK-HEADER-NEXT: inline namespace _V1 { // CHECK-HEADER-NEXT: namespace detail { -// CHECK-HEADER-NEXT: namespace { +// CHECK-HEADER: namespace { // CHECK-HEADER-NEXT: class __sycl_device_global_registration { // CHECK-HEADER-NEXT: public: // CHECK-HEADER-NEXT: __sycl_device_global_registration() noexcept; @@ -27,7 +27,7 @@ using namespace sycl::ext::oneapi; // CHECK-FOOTER: #include // CHECK-FOOTER: namespace sycl::detail { -// CHECK-FOOTER-NEXT: namespace { +// CHECK-FOOTER: namespace { // CHECK-FOOTER-NEXT: __sycl_device_global_registration::__sycl_device_global_registration() noexcept { device_global Basic; @@ -35,4 +35,4 @@ device_global Basic; // CHECK-FOOTER-NEXT: } // CHECK-FOOTER-NEXT: } -// CHECK-FOOTER-NEXT: } +// CHECK-FOOTER: } diff --git a/sycl/test/basic_tests/header_footer_diagnostics.cpp b/sycl/test/basic_tests/header_footer_diagnostics.cpp new file mode 100644 index 0000000000000..4f6fcf4628519 --- /dev/null +++ b/sycl/test/basic_tests/header_footer_diagnostics.cpp @@ -0,0 +1,8 @@ +// RUN: %clangxx -fsycl -Werror=reserved-identifier -Werror=old-style-cast %s + +// Check that the generated header and footer files do not generate +// errors when pedantic warnings are enabled. + +#include +sycl::ext::oneapi::experimental::device_global devGlobVar; +int main(int argc, char **argv) { return 0; }