Skip to content

Commit 29fa994

Browse files
committed
[SYCL] Fix libspirv invalid path in -###
In our downstream repo, bf21b9d exposed a regression that libspirv path is invalid in -### output. Before bf21b9d, the path was correctly found by `searchAt(D.ResourceDir, "..", "..", "clc")`, which was deleted by the commit. Root cause is that in -### mode the process should not early return upon the first candidate, which may do not exist. Instead, it should evaluate all candidates.
1 parent 8128c0c commit 29fa994

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

clang/lib/Driver/ToolChains/SYCL.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,11 @@ const char *SYCLInstallationDetector::findLibspirvPath(
6464
const SmallString<64> Basename =
6565
getLibSpirvBasename(DeviceTriple, HostTriple);
6666
auto searchAt = [&](StringRef Path, const Twine &a = "", const Twine &b = "",
67-
const Twine &c = "") -> const char * {
67+
bool HashHashHashEnabled = false) -> const char * {
6868
SmallString<128> LibraryPath(Path);
69-
llvm::sys::path::append(LibraryPath, a, b, c, Basename);
69+
llvm::sys::path::append(LibraryPath, a, b, "", Basename);
7070

71-
if (Args.hasArgNoClaim(options::OPT__HASH_HASH_HASH) ||
72-
llvm::sys::fs::exists(LibraryPath))
71+
if (HashHashHashEnabled || llvm::sys::fs::exists(LibraryPath))
7372
return Args.MakeArgString(LibraryPath);
7473

7574
return nullptr;
@@ -81,7 +80,9 @@ const char *SYCLInstallationDetector::findLibspirvPath(
8180
return R;
8281

8382
// Expected path w/ install.
84-
if (const char *R = searchAt(IC, "share", "clc"))
83+
bool HashHashHashEnabled = (&IC == &InstallationCandidates.back()) &&
84+
Args.hasArgNoClaim(options::OPT__HASH_HASH_HASH);
85+
if (const char *R = searchAt(IC, "share", "clc", HashHashHashEnabled))
8586
return R;
8687
}
8788

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
// CHECK-CUDA: "-cc1"{{.*}} "-fcuda-is-device"
3030
// CHECK-CUDA-NOT: "-mlink-builtin-bitcode" "{{.*}}.libspirv-{{.*}}.bc"
3131
//
32-
// The path to the remangled libspirv bitcode file is determined by the installation directory
32+
// The path to the remangled libspirv bitcode file is determined by the installation directory and `/share/clc/` is part of the path.
3333
// RUN: %clang -### -ccc-install-dir %{install_dir} -resource-dir %{resource_dir} -fsycl -fsycl-targets=nvptx64-nvidia-cuda -nocudalib %s 2>&1 \
34-
// RUN: | FileCheck %s -DINSTALL_DIR=%{install_dir} -DRESOURCE_DIR=%{resource_dir} --check-prefixes=CHECK-DIR
35-
// CHECK-DIR: "-cc1"{{.*}} "-fsycl-is-device"{{.*}} "-mlink-builtin-bitcode" "[[INSTALL_DIR]]{{.*[\\/]}}remangled-{{.*}}.libspirv-nvptx64-nvidia-cuda.bc"
34+
// RUN: | FileCheck %s -DINSTALL_DIR=%{install_dir} --check-prefixes=CHECK-DIR
35+
// CHECK-DIR: "-cc1"{{.*}} "-fsycl-is-device"{{.*}} "-mlink-builtin-bitcode" "[[INSTALL_DIR]]{{.*[\\/]}}share{{.*}}clc{{.*}}remangled-{{.*}}.libspirv-nvptx64-nvidia-cuda.bc"
3636
//
3737
// The `-###` option disables file existence checks
3838
// DEFINE: %{nonexistent_dir} = %/S/Inputs/SYCL/does_not_exist/lib/clang/resource_dir

0 commit comments

Comments
 (0)