From 019edfe153303af44a3109f21f92a45521f74542 Mon Sep 17 00:00:00 2001 From: "Meszaros, Gergely" Date: Wed, 10 Sep 2025 13:34:29 +0000 Subject: [PATCH 1/2] [SYCL][E2E] Stop CMAKE_CXX_FLAGS cache variable passing to clang++ Before #9075 the value of CMAKE_CXX_FLAGS was passed to SYCL E2E compilations. In #9075 the variable was explicitly unset in non-standalone (in-tree) builds of the tests. Unsetting a normal variable however exposes the cmake cache variable of the same name. I believe this was not the intent, rather the intent was to not pass any CMAKE_CXX_FLAGS to the E2E tests in non-standalone builds. It is weird to pass the user's CMAKE_CXX_FLAGS to the E2E tests, as these flags are for the SYCL toolchain, not tests. Passing `CMAKE_CXX_FLAGS` to the E2E tests can cause problems, for example a test might wish to override options such as setting `-ffp-model=fast`, but this can fails with a warning/error if `CMAKE_CXX_FLAGS` contains `-ffp-model=precise`: `error: overriding '-ffp-model=precise' option with '-ffp-model=fast' [-Werror,-Woverriding-option]`. While the error could be worked around in the test by appending `-Wno-overriding-option` to the test flags, I don't believe this is the right solution. It is possible that the user is running on a system where some flags have to be passed to clang++ to make it produce working executables. For this reason, allow setting `SYCL_E2E_CLANG_CXX_FLAGS` by the user if needed in in-tree builds, but do not pass `CMAKE_CXX_FLAGS` by default. Contains a drive-by fix to make sure `-Werror` is passed to clang++ even when the c++ flags are overriden by the lit parameter `--param cxx_flags=...` (it can still be disabled using `-Wno-error` explicitly). --- sycl/test-e2e/CMakeLists.txt | 24 +++--------------------- sycl/test-e2e/lit.cfg.py | 2 +- 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/sycl/test-e2e/CMakeLists.txt b/sycl/test-e2e/CMakeLists.txt index 38afa0ee45e0c..f92c9e4522003 100644 --- a/sycl/test-e2e/CMakeLists.txt +++ b/sycl/test-e2e/CMakeLists.txt @@ -39,10 +39,11 @@ endif() # Standalone. if(SYCL_TEST_E2E_STANDALONE) set(SYCL_CXX_COMPILER ${CMAKE_CXX_COMPILER}) + set(SYCL_E2E_CLANG_CXX_FLAGS "${CMAKE_CXX_FLAGS}") else() set(SYCL_CXX_COMPILER "${LLVM_BINARY_DIR}/bin/clang++") - # Don't want options used for building sycl-toolchain. - unset(CMAKE_CXX_FLAGS) + set(SYCL_E2E_CLANG_CXX_FLAGS "" CACHE STRING + "Flags passed to clang++ when building SYCL end-to-end tests") endif() # Standalone. find_package(Threads REQUIRED) @@ -65,25 +66,6 @@ if(NOT SYCL_TEST_E2E_TARGETS) set(SYCL_TEST_E2E_TARGETS "all") endif() -if(MSVC AND NOT SYCL_TEST_E2E_STANDALONE) - # We're trying to pass MSVC flags to Clang, which doesn't work by default - separate_arguments(cxx_flags NATIVE_COMMAND "${CMAKE_CXX_FLAGS}") - foreach(flag IN ITEMS ${cxx_flags}) - # Skip certain flags that only exists for MSVC - if("${flag}" STREQUAL "/EHsc") - continue() - endif() - # Change the way compiler definitions are passed in - string(REGEX REPLACE "^/D" "-D" clang_flag "${flag}") - list(APPEND SYCL_E2E_CLANG_CXX_FLAGS ${clang_flag}) - endforeach() - string (REPLACE ";" " " SYCL_E2E_CLANG_CXX_FLAGS "${SYCL_E2E_CLANG_CXX_FLAGS}") -else() - set(SYCL_E2E_CLANG_CXX_FLAGS ${CMAKE_CXX_FLAGS}) -endif() - -set(SYCL_E2E_CLANG_CXX_FLAGS "${SYCL_E2E_CLANG_CXX_FLAGS} -Werror") - if(NOT DEFINED CUDA_LIBS_DIR AND NOT DEFINED CUDA_INCLUDE) find_package(CUDAToolkit) diff --git a/sycl/test-e2e/lit.cfg.py b/sycl/test-e2e/lit.cfg.py index 94e189c87f36f..0a05496552d65 100644 --- a/sycl/test-e2e/lit.cfg.py +++ b/sycl/test-e2e/lit.cfg.py @@ -1147,7 +1147,7 @@ def get_sycl_ls_verbose(sycl_device, env): config.substitutions.append(("%clangxx", " true ")) config.substitutions.append(("%clang", " true ")) else: - clangxx = " " + config.dpcpp_compiler + " " + clangxx = " " + config.dpcpp_compiler + " -Werror " if "preview-mode" in config.available_features: # Technically, `-fpreview-breaking-changes` is reported as unused option # if used without `-fsycl`. However, we have far less tests compiling From 2812abb6726dc0c7487bef6fb0672123e9a9d172 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9sz=C3=A1ros=20Gergely?= Date: Wed, 10 Sep 2025 16:32:58 +0200 Subject: [PATCH 2/2] Preserve original code in case of standalone --- sycl/test-e2e/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sycl/test-e2e/CMakeLists.txt b/sycl/test-e2e/CMakeLists.txt index f92c9e4522003..a430d8475f193 100644 --- a/sycl/test-e2e/CMakeLists.txt +++ b/sycl/test-e2e/CMakeLists.txt @@ -39,7 +39,7 @@ endif() # Standalone. if(SYCL_TEST_E2E_STANDALONE) set(SYCL_CXX_COMPILER ${CMAKE_CXX_COMPILER}) - set(SYCL_E2E_CLANG_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + set(SYCL_E2E_CLANG_CXX_FLAGS ${CMAKE_CXX_FLAGS}) else() set(SYCL_CXX_COMPILER "${LLVM_BINARY_DIR}/bin/clang++") set(SYCL_E2E_CLANG_CXX_FLAGS "" CACHE STRING