Skip to content

[Driver][SYCL] Remove object upon failure #18190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: sycl
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2708,7 +2708,11 @@ int Driver::ExecuteCompilation(
// Remove result files if we're not saving temps.
if (!isSaveTempsEnabled()) {
const JobAction *JA = cast<JobAction>(&FailingCommand->getSource());
C.CleanupFileMap(C.getResultFiles(), JA, true);
// When performing offload compilations, the result files may not match
// the JobAction that fails. In that case, do not pass in the JobAction
Copy link
Contributor

@srividya-sundaram srividya-sundaram Apr 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// When performing offload compilations, the result files may not match the JobAction that fails.

Can you add some details on why they don't match?
And also give an example Offload JobAction for this scenario?

// to allow for the proper resulting file to be removed upon failure.
C.CleanupFileMap(C.getResultFiles(),
C.getActiveOffloadKinds() ? nullptr : JA, true);

// Failure result files are valid unless we crashed.
if (CommandRes < 0)
Expand Down
16 changes: 16 additions & 0 deletions clang/test/Driver/sycl-obj-remove.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/// Verify object removal when the offload compilation fails.

// REQUIRES: system-linux

// RUN: touch %t.o
// RUN: not %clangxx -fsycl -Xsycl-target-frontend -DCOMPILE_HOST_FAIL=1 -o %t.o %s
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand this test. Could you please elaborate?
I think you are creating a new object file.
And triggering a host compilation failure.
And the expectation is that the object file created gets removed?

The test description mentions, Verify object removal when the offload compilation fails , but you are triggering a host compilation failure.
Can you trigger any offload compilation action failure instead?

// RUN: not ls %t.o

// RUN: touch %t.o
// RUN: not %clangxx --offload-new-driver -fsycl -Xsycl-target-frontend -DCOMPILE_HOST_FAIL=1 -o %t.o %s
// RUN: not ls %t.o

void func(){};
#ifdef COMPILE_HOST_FAIL
#error FAIL
#endif // COMPILE_HOST_FAIL