Skip to content

Commit

Permalink
[Driver][SYCL] Handle invalid characters from device in temp files (i…
Browse files Browse the repository at this point in the history
…ntel#14563)

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 authored and hdelan committed Jul 26, 2024
1 parent 590be2d commit ffe6d4d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
8 changes: 6 additions & 2 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9417,10 +9417,14 @@ 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(), '*', '@');
}
// BoundArch may contain ',', which may create strings that interfere with
// the StringMap for the clang-offload-packager input values.
std::replace(BoundArch.begin(), BoundArch.end(), ',', '@');

llvm::PrettyStackTraceString CrashInfo("Computing output path");
// Output to a user requested destination?
Expand Down
7 changes: 7 additions & 0 deletions clang/test/Driver/sycl-offload-new-driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,10 @@
// RUN: -fsycl-embed-ir %s 2>&1 \
// RUN: | FileCheck -check-prefix CHECK_EMBED_IR %s
// CHECK_EMBED_IR: clang-linker-wrapper{{.*}} "-sycl-embed-ir"

/// Verify the filename being passed to the packager does not contain commas
/// that are used in -device settings.
// RUN: %clangxx -fsycl -### -fsycl-targets=spir64_gen --offload-new-driver \
// RUN: -Xsycl-target-backend=spir64_gen "-device pvc,bdw" %s 2>&1 \
// RUN: | FileCheck -check-prefix COMMA_FILE %s
// COMMA_FILE: clang-offload-packager{{.*}} "--image=file={{.*}}pvc@bdw{{.*}},triple=spir64_gen-unknown-unknown,arch=pvc,bdw,kind=sycl"
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 ffe6d4d

Please sign in to comment.