Skip to content

Commit 2aab337

Browse files
authored
[SYCL][Driver] Respect the -target cross-compilation flag. (#2417)
Currently when compiling with for sycl with a -target flag, clang will invoke the device compilation with an auxiliary triple of the machine performing the compilation instead of the host target completely ignoring the -target flag. This patch fixes this.
1 parent 57313f4 commit 2aab337

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4155,7 +4155,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
41554155
CmdArgs.push_back("-fenable-sycl-dae");
41564156

41574157
// Pass the triple of host when doing SYCL
4158-
auto AuxT = llvm::Triple(llvm::sys::getProcessTriple());
4158+
llvm::Triple AuxT = C.getDefaultToolChain().getTriple();
4159+
if (Args.hasFlag(options::OPT_fsycl_device_only, OptSpecifier(), false))
4160+
AuxT = llvm::Triple(llvm::sys::getProcessTriple());
41594161
std::string NormalizedTriple = AuxT.normalize();
41604162
CmdArgs.push_back("-aux-triple");
41614163
CmdArgs.push_back(Args.MakeArgString(NormalizedTriple));

clang/test/Driver/sycl-device.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,9 @@
2222
// RUN: %clang -### -fsycl %s 2>&1 \
2323
// RUN: | FileCheck -check-prefix=CHECK-SYCL-STD_VERSION %s
2424
// CHECK-SYCL-STD_VERSION: clang{{.*}} "-sycl-std=2020"
25+
26+
/// Check that -aux-triple is set correctly
27+
// RUN: %clang -### -fsycl -target aarch64-linux-gnu %s 2>&1 \
28+
// RUN: | FileCheck -check-prefix=CHECK-SYCL-AUX-TRIPLE %s
29+
// TODO: %clang -### -fsycl -fsycl-device-only -target aarch64-linux-gnu
30+
// CHECK-SYCL-AUX-TRIPLE: clang{{.*}} "-aux-triple" "aarch64-unknown-linux-gnu"

0 commit comments

Comments
 (0)