Skip to content

Commit 54ae12b

Browse files
wenju-heclaude
andauthored
[SYCL] Fix TCAndArchs leaking across offload kinds in BuildOffloadingActions (#22463)
TCAndArchs was declared outside the per-kind loop but only cleared inside it after the bug was introduced by ccdf2c6. Without the clear, entries from prior kinds (e.g. OpenMP's spir64 TC) accumulated and were incorrectly used when processing subsequent kinds (SYCL), causing SYCL device actions to pick up the wrong toolchain triple. CMPLRLLVM-76332 Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 14c7adc commit 54ae12b

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

clang/lib/Driver/Driver.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7936,6 +7936,7 @@ Driver::BuildOffloadingActions(Compilation &C, llvm::opt::DerivedArgList &Args,
79367936
for (Action::OffloadKind Kind : OffloadKinds) {
79377937
SmallVector<const ToolChain *, 2> ToolChains;
79387938
ActionList DeviceActions;
7939+
TCAndArchs.clear();
79397940

79407941
auto TCRange = C.getOffloadToolChains(Kind);
79417942
for (auto TI = TCRange.first, TE = TCRange.second; TI != TE; ++TI)

clang/test/Driver/sycl-offload-new-driver.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,3 +280,20 @@
280280
// RUN: -fsycl-link %s 2>&1 \
281281
// RUN: | FileCheck -check-prefix CHECK_SYCL_DEVICE_LINKING %s
282282
// CHECK_SYCL_DEVICE_LINKING: clang-linker-wrapper{{.*}} "--sycl-device-link"
283+
284+
/// Check that SYCL device uses its own toolchain triple when combined with
285+
/// OpenMP offloading. Regression test: TCAndArchs must be cleared per offload
286+
/// kind to prevent OpenMP's TC leaking into SYCL's device phases.
287+
// RUN: %clang -ccc-print-phases --target=x86_64-unknown-linux-gnu -fsycl \
288+
// RUN: --no-offloadlib -fopenmp -fopenmp-targets=spir64 \
289+
// RUN: --offload-new-driver %s 2>&1 \
290+
// RUN: | FileCheck -check-prefix=CHK-OPENMP-SYCL-PHASES %s
291+
// CHK-OPENMP-SYCL-PHASES: [[#OMP_DEV:]]: input, "{{.*}}", c++, (device-openmp)
292+
// CHK-OPENMP-SYCL-PHASES: [[#OMP_DEV+1]]: preprocessor, {[[#OMP_DEV]]}, c++-cpp-output, (device-openmp)
293+
// CHK-OPENMP-SYCL-PHASES: [[#OMP_DEV+2]]: compiler, {[[#OMP_DEV+1]]}, ir, (device-openmp)
294+
// CHK-OPENMP-SYCL-PHASES: offload, {{.*}} "device-openmp (spir64)" {[[#OMP_DEV+2]]}, ir
295+
// CHK-OPENMP-SYCL-PHASES: [[#SYCL_DEV:]]: input, "{{.*}}", c++, (device-sycl)
296+
// CHK-OPENMP-SYCL-PHASES: [[#SYCL_DEV+1]]: preprocessor, {[[#SYCL_DEV]]}, c++-cpp-output, (device-sycl)
297+
// CHK-OPENMP-SYCL-PHASES: [[#SYCL_DEV+2]]: compiler, {[[#SYCL_DEV+1]]}, ir, (device-sycl)
298+
// CHK-OPENMP-SYCL-PHASES: [[#SYCL_DEV+3]]: backend, {[[#SYCL_DEV+2]]}, ir, (device-sycl)
299+
// CHK-OPENMP-SYCL-PHASES: offload, "device-sycl (spir64-unknown-unknown)" {[[#SYCL_DEV+3]]}, ir

0 commit comments

Comments
 (0)