From f4c35636bf188a231a5bce1a753a51b3f88e098f Mon Sep 17 00:00:00 2001 From: Alexey Sachkov Date: Fri, 4 Jul 2025 15:00:04 +0200 Subject: [PATCH 1/2] [SYCL][CMAKE] Only apply extra warnings to SYCL RT We can't enable all warnings globally, because LLVM itself isn't warning-free. Therefore, moved all necessary flags to the `sycl` subproject. There are more places where we need those extra flags, but they will be added there in separate PRs because in absolute cases it requires addional fixes to the codebase. --- llvm/cmake/modules/AddSecurityFlags.cmake | 36 ++++++++++------------- sycl/source/CMakeLists.txt | 35 ++++++++++++++++++++++ 2 files changed, 50 insertions(+), 21 deletions(-) diff --git a/llvm/cmake/modules/AddSecurityFlags.cmake b/llvm/cmake/modules/AddSecurityFlags.cmake index 45179178e8800..b48d677c6222a 100644 --- a/llvm/cmake/modules/AddSecurityFlags.cmake +++ b/llvm/cmake/modules/AddSecurityFlags.cmake @@ -51,27 +51,21 @@ endif() macro(append_common_extra_security_flags) # Compiler Warnings and Error Detection - # Note: in intel/llvm we build both linux and win with --ci-defaults. - # This flag also enables -Werror or /WX. - if(is_gcc - OR is_clang - OR (is_icpx AND MSVC)) - add_compile_option_ext("-Wall" WALL) - add_compile_option_ext("-Wextra" WEXTRA) - elseif(is_icpx) - add_compile_option_ext("/Wall" WALL) - elseif(is_msvc) - add_compile_option_ext("/W4" WALL) - endif() - - if(CMAKE_BUILD_TYPE MATCHES "Release") - if(is_gcc - OR is_clang - OR (is_icpx AND MSVC)) - add_compile_option_ext("-Wconversion" WCONVERSION) - add_compile_option_ext("-Wimplicit-fallthrough" WIMPLICITFALLTHROUGH) - endif() - endif() + # Any flags applied here will be applied globally to all LLVM sub-projects. + # Since LLVM itself is not warning-free, enabling any extra warnings globally + # will most likely cause -Werror build to fail. Therefore, any necessary + # warnings should be enabled on a per-project basis. + # Things that we care about: + # - sycl + # - sycl-jit + # - unified-runtime + # - xpti + # - xptifw + # - SYCL-specific passes in LLVM (SYCLLowerIR, sycl-post-link, etc.) + # - SYCL-specific files in clang (SemaSYCL.cpp, etc.) + # The list above may not be complete and it is given for reference in case + # someone needs to enable more flags. There is also no guarantee that all + # sub-projects above already use all necessary flags uniformly. # Control Flow Integrity if(is_gcc diff --git a/sycl/source/CMakeLists.txt b/sycl/source/CMakeLists.txt index dd1b833383055..fbe516abb5c4b 100644 --- a/sycl/source/CMakeLists.txt +++ b/sycl/source/CMakeLists.txt @@ -16,6 +16,8 @@ if (SYCL_ENABLE_XPTI_TRACING) include_directories(${LLVM_EXTERNAL_XPTI_SOURCE_DIR}/include) endif() + + function(add_sycl_rt_library LIB_NAME LIB_OBJ_NAME) # Add an optional argument so we can get the library name to # link with for Windows Debug version @@ -30,6 +32,33 @@ function(add_sycl_rt_library LIB_NAME LIB_OBJ_NAME) check_cxx_compiler_flag(-ffunction-sections HAS_FUNCTION_SECTIONS_FLAG) check_cxx_compiler_flag(-fdata-sections HAS_DATA_SECTIONS_FLAG) + if(is_gcc + OR is_clang + OR (is_icpx AND MSVC)) + add_compile_option_ext("-Wall" WALL) + add_compile_option_ext("-Wextra" WEXTRA) + elseif(is_icpx) + add_compile_option_ext("/Wall" WALL) + elseif(is_msvc) + add_compile_option_ext("/W4" WALL) + endif() + + if(CMAKE_BUILD_TYPE MATCHES "Release") + if(is_gcc + OR is_clang + OR (is_icpx AND MSVC)) + add_compile_option_ext("-Wconversion" WCONVERSION) + add_compile_option_ext("-Wimplicit-fallthrough" WIMPLICITFALLTHROUGH) + endif() + endif() + + # check_cxx_compiler_flag(-Wall HAS_WALL_FLAG) + # check_cxx_compiler_flag(-Wextra HAS_WEXTRA_FLAG) + # check_cxx_compiler_flag(/Wall HAS_SLASH_WALL_FLAG) + # check_cxx_compiler_flag(/W4 HAS_SLASH_W4_FLAG) + # check_cxx_compiler_flag(-Wconversion HAS_WCONVERSION_FLAG) + # check_cxx_compiler_flag(-Wimplicit-fallthrough HAS_WIMPLICIT_FALLTHROUGH_FLAG) + target_compile_options( ${LIB_OBJ_NAME} PRIVATE @@ -37,6 +66,12 @@ function(add_sycl_rt_library LIB_NAME LIB_OBJ_NAME) $<$:-Winstantiation-after-specialization> $<$:-ffunction-sections> $<$:-fdata-sections> + # $<$:-Wall> + # $<$:-Wextra> + # $<$:/Wall> + # $<$:/W4> + # $<$>>:-Wconversion> + # $<$>>:-Wimplicit-fallthrough> PUBLIC $<$>:-fvisibility=hidden -fvisibility-inlines-hidden> # Sycl math built-in macros cause a GCC 4.6 'note' to be output From c6e2d2fc672b1c5b2aeffe03591ca879daf916c3 Mon Sep 17 00:00:00 2001 From: Alexey Sachkov Date: Mon, 7 Jul 2025 15:09:21 +0200 Subject: [PATCH 2/2] Drop commented lines, move the code a little bit --- sycl/source/CMakeLists.txt | 51 ++++++++++++++------------------------ 1 file changed, 18 insertions(+), 33 deletions(-) diff --git a/sycl/source/CMakeLists.txt b/sycl/source/CMakeLists.txt index fbe516abb5c4b..e55796b8d45e0 100644 --- a/sycl/source/CMakeLists.txt +++ b/sycl/source/CMakeLists.txt @@ -16,7 +16,25 @@ if (SYCL_ENABLE_XPTI_TRACING) include_directories(${LLVM_EXTERNAL_XPTI_SOURCE_DIR}/include) endif() +if(is_gcc + OR is_clang + OR (is_icpx AND MSVC)) + add_compile_option_ext("-Wall" WALL) + add_compile_option_ext("-Wextra" WEXTRA) +elseif(is_icpx) + add_compile_option_ext("/Wall" WALL) +elseif(is_msvc) + add_compile_option_ext("/W4" WALL) +endif() +if(CMAKE_BUILD_TYPE MATCHES "Release") + if(is_gcc + OR is_clang + OR (is_icpx AND MSVC)) + add_compile_option_ext("-Wconversion" WCONVERSION) + add_compile_option_ext("-Wimplicit-fallthrough" WIMPLICITFALLTHROUGH) + endif() +endif() function(add_sycl_rt_library LIB_NAME LIB_OBJ_NAME) # Add an optional argument so we can get the library name to @@ -32,33 +50,6 @@ function(add_sycl_rt_library LIB_NAME LIB_OBJ_NAME) check_cxx_compiler_flag(-ffunction-sections HAS_FUNCTION_SECTIONS_FLAG) check_cxx_compiler_flag(-fdata-sections HAS_DATA_SECTIONS_FLAG) - if(is_gcc - OR is_clang - OR (is_icpx AND MSVC)) - add_compile_option_ext("-Wall" WALL) - add_compile_option_ext("-Wextra" WEXTRA) - elseif(is_icpx) - add_compile_option_ext("/Wall" WALL) - elseif(is_msvc) - add_compile_option_ext("/W4" WALL) - endif() - - if(CMAKE_BUILD_TYPE MATCHES "Release") - if(is_gcc - OR is_clang - OR (is_icpx AND MSVC)) - add_compile_option_ext("-Wconversion" WCONVERSION) - add_compile_option_ext("-Wimplicit-fallthrough" WIMPLICITFALLTHROUGH) - endif() - endif() - - # check_cxx_compiler_flag(-Wall HAS_WALL_FLAG) - # check_cxx_compiler_flag(-Wextra HAS_WEXTRA_FLAG) - # check_cxx_compiler_flag(/Wall HAS_SLASH_WALL_FLAG) - # check_cxx_compiler_flag(/W4 HAS_SLASH_W4_FLAG) - # check_cxx_compiler_flag(-Wconversion HAS_WCONVERSION_FLAG) - # check_cxx_compiler_flag(-Wimplicit-fallthrough HAS_WIMPLICIT_FALLTHROUGH_FLAG) - target_compile_options( ${LIB_OBJ_NAME} PRIVATE @@ -66,12 +57,6 @@ function(add_sycl_rt_library LIB_NAME LIB_OBJ_NAME) $<$:-Winstantiation-after-specialization> $<$:-ffunction-sections> $<$:-fdata-sections> - # $<$:-Wall> - # $<$:-Wextra> - # $<$:/Wall> - # $<$:/W4> - # $<$>>:-Wconversion> - # $<$>>:-Wimplicit-fallthrough> PUBLIC $<$>:-fvisibility=hidden -fvisibility-inlines-hidden> # Sycl math built-in macros cause a GCC 4.6 'note' to be output