Skip to content

Commit

Permalink
[Driver][SYCL] Handle invalid characters from device in temp files
Browse files Browse the repository at this point in the history
When using command lines such as -fsycl -fsycl-targets=spir64_gen
--offload-new-driver -Xsycl-target-backend "-device *" there is a
temporary file that is generated that contains the arch value.
Eliminate any possible invalid characters from being used with this
temporary file.
  • Loading branch information
mdtoguchi committed Jul 12, 2024
1 parent 56e88d5 commit 0636c88
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
5 changes: 3 additions & 2 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9484,9 +9484,10 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
StringRef OffloadingPrefix) const {
std::string BoundArch = OrigBoundArch.str();
if (is_style_windows(llvm::sys::path::Style::native)) {
// BoundArch may contains ':', which is invalid in file names on Windows,
// therefore replace it with '%'.
// BoundArch may contain ':' or '*', which is invalid in file names on
// Windows, therefore replace it with '@'.
std::replace(BoundArch.begin(), BoundArch.end(), ':', '@');
std::replace(BoundArch.begin(), BoundArch.end(), '*', '@');
}

llvm::PrettyStackTraceString CrashInfo("Computing output path");
Expand Down
20 changes: 20 additions & 0 deletions clang/test/Driver/sycl-windows-device-filename.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Test valid file names from -device values for GPU
// REQUIRES: system-windows

// RUN: %clang -### --target=x86_64-pc-windows-msvc -fsycl \
// RUN: -fsycl-targets=spir64_gen --offload-new-driver \
// RUN: -Xsycl-target-backend "-device arch1:arch2" %s 2>&1 \
// RUN: | FileCheck %s -check-prefix=CHECK_COLON

// CHECK_COLON: sycl-windows-device-filename-arch1@arch2
// CHECK_COLON: arch=arch1:arch2
// CHECK_COLON-NOT: sycl-windows-device-filename-arch1:arch2

// RUN: %clang -### --target=x86_64-pc-windows-msvc -fsycl \
// RUN: -fsycl-targets=spir64_gen --offload-new-driver \
// RUN: -Xsycl-target-backend "-device *" %s 2>&1 \
// RUN: | FileCheck %s -check-prefix=CHECK_STAR

// CHECK_STAR: sycl-windows-device-filename-@
// CHECK_STAR: arch=*
// CHECK_STAR-NOT: sycl-windows-device-filename-*

0 comments on commit 0636c88

Please sign in to comment.