Skip to content

Commit cd8d6d8

Browse files
authored
[Driver][SYCL] Handle invalid characters from device in temp files (#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.
1 parent 3c2c938 commit cd8d6d8

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9417,10 +9417,14 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
94179417
StringRef OffloadingPrefix) const {
94189418
std::string BoundArch = OrigBoundArch.str();
94199419
if (is_style_windows(llvm::sys::path::Style::native)) {
9420-
// BoundArch may contains ':', which is invalid in file names on Windows,
9421-
// therefore replace it with '%'.
9420+
// BoundArch may contain ':' or '*', which is invalid in file names on
9421+
// Windows, therefore replace it with '@'.
94229422
std::replace(BoundArch.begin(), BoundArch.end(), ':', '@');
9423+
std::replace(BoundArch.begin(), BoundArch.end(), '*', '@');
94239424
}
9425+
// BoundArch may contain ',', which may create strings that interfere with
9426+
// the StringMap for the clang-offload-packager input values.
9427+
std::replace(BoundArch.begin(), BoundArch.end(), ',', '@');
94249428

94259429
llvm::PrettyStackTraceString CrashInfo("Computing output path");
94269430
// Output to a user requested destination?

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,10 @@
181181
// RUN: -fsycl-embed-ir %s 2>&1 \
182182
// RUN: | FileCheck -check-prefix CHECK_EMBED_IR %s
183183
// CHECK_EMBED_IR: clang-linker-wrapper{{.*}} "-sycl-embed-ir"
184+
185+
/// Verify the filename being passed to the packager does not contain commas
186+
/// that are used in -device settings.
187+
// RUN: %clangxx -fsycl -### -fsycl-targets=spir64_gen --offload-new-driver \
188+
// RUN: -Xsycl-target-backend=spir64_gen "-device pvc,bdw" %s 2>&1 \
189+
// RUN: | FileCheck -check-prefix COMMA_FILE %s
190+
// COMMA_FILE: clang-offload-packager{{.*}} "--image=file={{.*}}pvc@bdw{{.*}},triple=spir64_gen-unknown-unknown,arch=pvc,bdw,kind=sycl"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Test valid file names from -device values for GPU
2+
// REQUIRES: system-windows
3+
4+
// RUN: %clang -### --target=x86_64-pc-windows-msvc -fsycl \
5+
// RUN: -fsycl-targets=spir64_gen --offload-new-driver \
6+
// RUN: -Xsycl-target-backend "-device arch1:arch2" %s 2>&1 \
7+
// RUN: | FileCheck %s -check-prefix=CHECK_COLON
8+
9+
// CHECK_COLON: sycl-windows-device-filename-arch1@arch2
10+
// CHECK_COLON: arch=arch1:arch2
11+
// CHECK_COLON-NOT: sycl-windows-device-filename-arch1:arch2
12+
13+
// RUN: %clang -### --target=x86_64-pc-windows-msvc -fsycl \
14+
// RUN: -fsycl-targets=spir64_gen --offload-new-driver \
15+
// RUN: -Xsycl-target-backend "-device *" %s 2>&1 \
16+
// RUN: | FileCheck %s -check-prefix=CHECK_STAR
17+
18+
// CHECK_STAR: sycl-windows-device-filename-@
19+
// CHECK_STAR: arch=*
20+
// CHECK_STAR-NOT: sycl-windows-device-filename-*

0 commit comments

Comments
 (0)