Skip to content

Commit ef0d151

Browse files
authored
[Driver][SYCL] Fix crash when using libraries with -fsycl (#9276)
When performing any non-linking behaviors with -fsycl (like -c or -E) and adding any non-compiled input value such as a library the driver would crash due to invalid phase information. Update the usage of the phase information to be more accurate depending on the input (i.e. Archive)
1 parent 58e64ce commit ef0d151

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6713,8 +6713,7 @@ class OffloadingActionBuilder final {
67136713
return C.MakeAction<OffloadAction>(HDep, DDeps);
67146714
}
67156715

6716-
void unbundleStaticArchives(Compilation &C, DerivedArgList &Args,
6717-
DeviceActionBuilder::PhasesTy &PL) {
6716+
void unbundleStaticArchives(Compilation &C, DerivedArgList &Args) {
67186717
if (!Args.hasFlag(options::OPT_fsycl, options::OPT_fno_sycl, false))
67196718
return;
67206719

@@ -6727,6 +6726,7 @@ class OffloadingActionBuilder final {
67276726
Arg *InputArg = MakeInputArg(Args, Opts, Args.MakeArgString(A));
67286727
Action *Current = C.MakeAction<InputAction>(*InputArg, T);
67296728
addHostDependenceToDeviceActions(Current, InputArg, Args);
6729+
auto PL = types::getCompilationPhases(T);
67306730
addDeviceDependencesToHostAction(Current, InputArg, phases::Link,
67316731
PL.back(), PL);
67326732
};
@@ -7120,7 +7120,7 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
71207120
if (!LinkerInputs.empty() && C.getDriver().getOffloadStaticLibSeen())
71217121
OffloadBuilder->addDeviceLinkDependenciesFromHost(LinkerInputs);
71227122

7123-
OffloadBuilder->unbundleStaticArchives(C, Args, PL);
7123+
OffloadBuilder->unbundleStaticArchives(C, Args);
71247124
}
71257125

71267126
// For an FPGA archive, we add the unbundling step above to take care of

clang/test/Driver/sycl-offload.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,13 @@
160160
// RUN: %clangxx -### -fsycl-device-only %s 2>&1 | FileCheck -check-prefixes=CHECK_BITFIELD_OPTION %s
161161
// CHECK_BITFIELD_OPTION: clang{{.*}} "-ffine-grained-bitfield-accesses"
162162

163+
/// Using linker specific items at the end of the command should not fail when
164+
/// we are performing a non-linking compilation behavior
165+
// RUN: %clangxx -E -fsycl %S/Inputs/SYCL/liblin64.a \
166+
// RUN: -target x86_64-unknown-linux-gnu -### 2>&1 \
167+
// RUN: | FileCheck -check-prefix IGNORE_INPUT %s
168+
// RUN: %clangxx -c -fsycl %S/Inputs/SYCL/liblin64.a \
169+
// RUN: -target x86_64-unknown-linux-gnu -### 2>&1 \
170+
// RUN: | FileCheck -check-prefix IGNORE_INPUT %s
171+
// IGNORE_INPUT: input unused
172+

0 commit comments

Comments
 (0)