Skip to content

Commit 538e870

Browse files
authored
[Driver][SYCL] Remove object upon failure (#18190)
Typical behaviors when the compilation fails is to have the resulting output object to be removed. Due to the fact that there are multiple compilations that occur during an offload compilation, the actual final output object may not be directly associated with the compile causing it to not be removed. Update the cleanup file list to remove the output result file regardless of the associated job action when we are performing offload. --------- Signed-off-by: Michael D Toguchi <[email protected]>
1 parent 3ed0666 commit 538e870

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

clang/lib/Driver/Driver.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -2708,7 +2708,11 @@ int Driver::ExecuteCompilation(
27082708
// Remove result files if we're not saving temps.
27092709
if (!isSaveTempsEnabled()) {
27102710
const JobAction *JA = cast<JobAction>(&FailingCommand->getSource());
2711-
C.CleanupFileMap(C.getResultFiles(), JA, true);
2711+
// When performing offload compilations, the result files may not match
2712+
// the JobAction that fails. In that case, do not pass in the JobAction
2713+
// to allow for the proper resulting file to be removed upon failure.
2714+
C.CleanupFileMap(C.getResultFiles(),
2715+
C.getActiveOffloadKinds() ? nullptr : JA, true);
27122716

27132717
// Failure result files are valid unless we crashed.
27142718
if (CommandRes < 0)

clang/test/Driver/sycl-obj-remove.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/// Verify object removal when the offload compilation fails.
2+
3+
// REQUIRES: system-linux
4+
5+
/// Force failure during device compilation
6+
// RUN: touch %t.o
7+
// RUN: not %clangxx -fsycl -Xsycl-target-frontend -DCOMPILE_FAIL=1 -c -o %t.o %s
8+
// RUN: not ls %t.o
9+
10+
// RUN: touch %t.o
11+
// RUN: not %clangxx --offload-new-driver -fsycl -Xsycl-target-frontend -DCOMPILE_FAIL=1 -c -o %t.o %s
12+
// RUN: not ls %t.o
13+
14+
/// Force failure during compilation
15+
// RUN: touch %t.o
16+
// RUN: not %clangxx -fsycl -DCOMPILE_FAIL=1 -c -o %t.o %s
17+
// RUN: not ls %t.o
18+
19+
// RUN: touch %t.o
20+
// RUN: not %clangxx --offload-new-driver -fsycl -DCOMPILE_FAIL=1 -c -o %t.o %s
21+
// RUN: not ls %t.o
22+
23+
void func(){};
24+
#ifdef COMPILE_FAIL
25+
#error FAIL
26+
#endif // COMPILE_FAIL

0 commit comments

Comments
 (0)