Skip to content

Commit 56800d0

Browse files
Maetveisbader
andauthored
[SYCL][Driver] Emit unused argument warning for -fno-libspirv (#19135)
<!-- start git-machete generated --> # Based on PR #19134 ## Chain of upstream PRs & tree of downstream PRs as of 2025-06-25 * PR #19130 * PR #19131 * PR #19134 * **PR #19135 (THIS ONE)** * PR #19136 <!-- end git-machete generated --> Previously the `-fno-libspirv` option was not warned about when there was no SYCL compilation. Remove the explicit target check for the targets that support `-fno-libspirv` and instead rely on each target to emit appropriate warnings when its used. This commit slightly degrades diagnostic quality, from "ignoring '-fno-sycl-libspirv' option as it is not currently supported for target" to "argument unused during compilation: '-fno-sycl-libspirv'" , but I believe this is acceptable as it allows to remove the list of targets that support the option from the driver. Additionally, now if the user mixes targets that support and do not support `-fno-libspirv` in the same compilation, they will not get warnings that are not actionable. --------- Co-authored-by: Alexey Bader <alexey.bader@intel.com>
1 parent 8b815fb commit 56800d0

File tree

4 files changed

+15
-19
lines changed

4 files changed

+15
-19
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,19 +1570,6 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
15701570
}
15711571
}
15721572

1573-
// -fno-sycl-libspirv flag is reserved for very unusual cases where the
1574-
// libspirv library is not linked when using CUDA/HIP: so output appropriate
1575-
// warnings.
1576-
if (C.getInputArgs().hasArg(options::OPT_fno_sycl_libspirv)) {
1577-
for (auto &TT : UniqueSYCLTriplesVec) {
1578-
if (TT.isNVPTX() || TT.isAMDGCN()) {
1579-
Diag(diag::warn_flag_no_sycl_libspirv) << TT.getTriple();
1580-
continue;
1581-
}
1582-
Diag(diag::warn_drv_unsupported_option_for_target)
1583-
<< "-fno-sycl-libspirv" << TT.getTriple() << 0;
1584-
}
1585-
}
15861573
// -fsycl-fp64-conv-emu is valid only for AOT compilation with an Intel GPU
15871574
// target. For other scenarios, we emit a warning message.
15881575
if (C.getInputArgs().hasArg(options::OPT_fsycl_fp64_conv_emu)) {

clang/lib/Driver/ToolChains/SYCL.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,18 @@ const char *SYCLInstallationDetector::findLibspirvPath(
209209
void SYCLInstallationDetector::addLibspirvLinkArgs(
210210
const llvm::Triple &DeviceTriple, const llvm::opt::ArgList &DriverArgs,
211211
const llvm::Triple &HostTriple, llvm::opt::ArgStringList &CC1Args) const {
212-
if (DriverArgs.hasArg(options::OPT_fno_sycl_libspirv) ||
213-
D.offloadDeviceOnly())
212+
DriverArgs.claimAllArgs(options::OPT_fno_sycl_libspirv);
213+
214+
if (D.offloadDeviceOnly())
215+
return;
216+
217+
if (DriverArgs.hasArg(options::OPT_fno_sycl_libspirv)) {
218+
// -fno-sycl-libspirv flag is reserved for very unusual cases where the
219+
// libspirv library is not linked when required by the device: so output
220+
// appropriate warnings.
221+
D.Diag(diag::warn_flag_no_sycl_libspirv) << DeviceTriple.str();
214222
return;
223+
}
215224

216225
if (const char *LibSpirvFile =
217226
findLibspirvPath(DeviceTriple, DriverArgs, HostTriple)) {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/// Test that appropriate warnings are output when -fno-sycl-libspirv is used.
22

3-
// RUN: not %clangxx -fsycl -fsycl-targets=nvptx64-nvidia-cuda,amdgcn-amd-amdhsa -fno-sycl-libspirv %s -### 2>&1 | FileCheck %s
3+
// RUN: %clangxx -fsycl -fsycl-targets=nvptx64-nvidia-cuda,amdgcn-amd-amdhsa -Xsycl-target-backend=amdgcn-amd-amdhsa --offload-arch=gfx908 -nogpulib -fno-sycl-libspirv %s -### 2>&1 | FileCheck %s
44
// CHECK-DAG: warning: '-fno-sycl-libspirv' should not be used with target 'nvptx64-nvidia-cuda'; libspirv is required for correct behavior [-Wunsafe-libspirv-not-linked]
55
// CHECK-DAG: warning: '-fno-sycl-libspirv' should not be used with target 'amdgcn-amd-amdhsa'; libspirv is required for correct behavior [-Wunsafe-libspirv-not-linked]
66
// RUN: %clangxx -fsycl -fsycl-targets=spir64-unknown-unknown -fno-sycl-libspirv %s -### 2>&1 | FileCheck --check-prefix=CHECK-SPIR64 %s
7-
// CHECK-SPIR64: ignoring '-fno-sycl-libspirv' option as it is not currently supported for target 'spir64-unknown-unknown' [-Woption-ignored]
7+
// CHECK-SPIR64: argument unused during compilation: '-fno-sycl-libspirv' [-Wunused-command-line-argument]

clang/test/Driver/sycl-libspirv-toolchain.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
// CHECK-DEVICE-ONLY: "-cc1"{{.*}} "-fsycl-is-device"
2525
// CHECK-DEVICE-ONLY-NOT: "-mlink-builtin-bitcode" "{{.*}}.libspirv-{{.*}}.bc"
2626
//
27-
// Only link libspirv in SYCL language mode, but `-fno-sycl-libspirv` does not result in a warning
27+
// Only link libspirv in SYCL language mode, `-fno-sycl-libspirv` should result in a warning
2828
// RUN: %clang -### -x cu -fno-sycl-libspirv -nocudainc -nocudalib %s 2>&1 | FileCheck %s --check-prefixes=CHECK-CUDA
29-
// CHECK-CUDA-NOT: warning: argument unused during compilation: '-fno-sycl-libspirv' [-Wunused-command-line-argument]
29+
// CHECK-CUDA: warning: argument unused during compilation: '-fno-sycl-libspirv' [-Wunused-command-line-argument]
3030
// CHECK-CUDA: "-cc1"{{.*}} "-fcuda-is-device"
3131
// CHECK-CUDA-NOT: "-mlink-builtin-bitcode" "{{.*}}.libspirv-{{.*}}.bc"
3232
//

0 commit comments

Comments
 (0)