diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 558debe95999b..ea07c5246d7a9 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -9407,9 +9407,19 @@ void OffloadDeps::constructJob(Compilation &C, const JobAction &JA, Targets += ','; Targets += Action::GetOffloadKindName(Dep.DependentOffloadKind); Targets += '-'; - std::string NormalizedTriple = - Dep.DependentToolChain->getTriple().normalize(); - Targets += NormalizedTriple; + // When -fsycl-force-target is used, this value overrides the expected + // output type we are creating deps for. + if (Dep.DependentOffloadKind == Action::OFK_SYCL && + TCArgs.hasArg(options::OPT_fsycl_force_target_EQ)) { + StringRef Val( + TCArgs.getLastArg(options::OPT_fsycl_force_target_EQ)->getValue()); + llvm::Triple TT(C.getDriver().MakeSYCLDeviceTriple(Val)); + Targets += TT.normalize(); + } else { + std::string NormalizedTriple = + Dep.DependentToolChain->getTriple().normalize(); + Targets += NormalizedTriple; + } if ((Dep.DependentOffloadKind == Action::OFK_HIP || Dep.DependentOffloadKind == Action::OFK_SYCL) && !Dep.DependentBoundArch.empty()) { diff --git a/clang/test/Driver/sycl-force-target.cpp b/clang/test/Driver/sycl-force-target.cpp index 9b91fdf3c2c0e..6caef214cf9ff 100644 --- a/clang/test/Driver/sycl-force-target.cpp +++ b/clang/test/Driver/sycl-force-target.cpp @@ -21,6 +21,18 @@ // CHECK_FORCE_TARGET_GEN: llvm-foreach{{.*}} {{.*}}ocloc{{.*}} // CHECK_FORCE_TARGET_CPU: llvm-foreach{{.*}} {{.*}}opencl-aot{{.*}} +/// Verify the usage of -fsycl-force-target applies to all expected unbundlings +/// and also applies to clang-offload-deps step +// RUN: %clangxx -fsycl -fsycl-targets=spir64_gen -fsycl-force-target=spir64 \ +// RUN: -target x86_64-unknown-linux-gnu -fno-sycl-device-lib=all \ +// RUN: %s %S/Inputs/SYCL/liblin64.a -### 2>&1 \ +// RUN: | FileCheck %s -check-prefix=CHECK_FORCE_TARGET_ARCHIVE +// CHECK_FORCE_TARGET_ARCHIVE: clang-offload-deps{{.*}} "-targets=sycl-spir64-unknown-unknown" "-outputs={{.*}}" +// CHECK_FORCE_TARGET_ARCHIVE: clang-offload-bundler{{.*}} "-type=aoo" "-targets=sycl-spir64-unknown-unknown" "-input={{.*}}liblin64.a" "-output=[[DEVICELISTOUT:.+]]" "-unbundle" "-allow-missing-bundles" +// CHECK_FORCE_TARGET_ARCHIVE: spirv-to-ir-wrapper{{.*}} "[[DEVICELISTOUT]]" "-o" "[[DEVICELISTBC:.+\.txt]]" +// CHECK_FORCE_TARGET_ARCHIVE: llvm-link{{.*}} "@[[DEVICELISTBC]]"{{.*}} "-o" "[[DEVICEARCHIVELINKED:.+\.bc]]" "--suppress-warnings" +// CHECK_FORCE_TARGET_ARCHIVE: llvm-foreach{{.*}} {{.*}}ocloc{{.*}} + /// -fsycl-force-target is only valid with -fsycl-target with single targets // RUN: %clangxx -fsycl -fsycl-targets=spir64_gen,spir64_x86_64 \ // RUN: -fsycl-force-target=spir64 %s -### 2>&1 \