Skip to content

[SYCL][CMAKE] Only apply extra warnings to SYCL RT #19306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: sycl
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 15 additions & 21 deletions llvm/cmake/modules/AddSecurityFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 35 additions & 0 deletions sycl/source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,13 +32,46 @@ 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
${ARG_COMPILE_OPTIONS}
$<$<BOOL:${HAS_INST_AFTER_SPEC}>:-Winstantiation-after-specialization>
$<$<BOOL:${HAS_FUNCTION_SECTIONS_FLAG}>:-ffunction-sections>
$<$<BOOL:${HAS_DATA_SECTIONS_FLAG}>:-fdata-sections>
# $<$<BOOL:${HAS_WALL_FLAG}>:-Wall>
# $<$<BOOL:${HAS_WEXTRA_FLAG}>:-Wextra>
# $<$<BOOL:${HAS_SLASH_WALL_FLAG}>:/Wall>
# $<$<BOOL:${HAS_SLASH_W4_FLAG}>:/W4>
# $<$<AND:$<BOOL:${HAS_WCONVERSION_FLAG},$<STREQUAL:"${CMAKE_BUILD_TYPE}","Release">>>:-Wconversion>
# $<$<AND:$<BOOL:${HAS_WIMPLICIT_FALLTHROUGH_FLAG},$<STREQUAL:"${CMAKE_BUILD_TYPE}","Release">>>:-Wimplicit-fallthrough>
PUBLIC
$<$<NOT:$<BOOL:${MSVC}>>:-fvisibility=hidden -fvisibility-inlines-hidden>
# Sycl math built-in macros cause a GCC 4.6 'note' to be output
Expand Down