Skip to content

Commit a21aeec

Browse files
committed
[Driver][SYCL] Remove object upon failure
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.
1 parent 5261637 commit a21aeec

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-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(), C.getActiveOffloadKinds()
2715+
? nullptr : JA, true);
27122716

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

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

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/// Verify object removal when the offload compilation fails.
2+
3+
// REQUIRES: system-linux
4+
5+
// RUN: touch %t.o
6+
// RUN: not %clangxx -fsycl -Xsycl-target-frontend -DCOMPILE_HOST_FAIL=1 -o %t.o %s
7+
// RUN: not ls %t.o
8+
9+
// RUN: touch %t.o
10+
// RUN: not %clangxx --offload-new-driver -fsycl -Xsycl-target-frontend -DCOMPILE_HOST_FAIL=1 -o %t.o %s
11+
// RUN: not ls %t.o
12+
13+
void func(){};
14+
#ifdef COMPILE_HOST_FAIL
15+
#error FAIL
16+
#endif // COMPILE_HOST_FAIL

0 commit comments

Comments
 (0)