[clang] [llvm] [clang] Check validity of SYCL device target (PR #172366)
Tom Honermann via cfe-commits
cfe-commits at lists.llvm.org
Fri May 1 09:46:44 PDT 2026
================
@@ -5111,6 +5111,10 @@ bool CompilerInvocation::CreateFromArgsImpl(
if (LangOpts.OpenMPIsTargetDevice)
Res.getTargetOpts().HostTriple = Res.getFrontendOpts().AuxTriple;
+ // Set the default triple for SYCL device compilation.
+ if (LangOpts.SYCLIsDevice && !Args.hasArg(options::OPT_triple))
+ Res.getTargetOpts().Triple = "spirv64-unknown-unknown";
----------------
tahonermann wrote:
I don't have specific bug reports, but the tests in this PR demonstrate unintended behavior. The desired behavior is that, during device compilation, the `-aux-triple` option is passed to specify the triple for the host (the reverse is not true; host compilation should not include `-aux-triple` for a device since the relationship is 1-N). This is then used to populate `TargetOptions::HostTriple`. The driver already passes `-aux-triple` for SYCL device compilations (correctly as far as I can tell), but that option isn't getting reflected in `TargetOptions::HostTriple. The desired change in this location is to just do what is done for CUDA and OpenMP above.
```suggestion
// Set the default and host triples for SYCL device compilation.
if (LangOpts.SYCLIsDevice) {
if (!Args.hasArg(options::OPT_triple))
Res.getTargetOpts().Triple = "spirv64-unknown-unknown";
Res.getTargetOpts().HostTriple = Res.getFrontendOpts().AuxTriple;
}
```
Some additional changes should be made too:
- In `clang/include/clang/Frontend/FrontendOptions.h`, add "SYCL" to the comment preceding the declaration of `AuxTriple`.
- In `clang/lib/Driver/ToolChains/Clang.cpp`, in the definition of `Clang::ConstructJob()`, add `IsSYCLDevice` to the conditional for the local initialization of `AuxTriple`. The use of `IsSYCL` a few lines later around the initialization of `IsWindowsMSVC` could also be changed to `IsSYCLDevice`, but it doesn't really matter since `AuxTriple` will be null for host compilation anyway.
Per one of the other comments, it sounds like we'll defer the addition of `clang/test/Driver/sycl-device.cpp`. I would like to see the above changes in this PR though since we're already touching this code. If these changes provoke other issues though, then we should probably defer them as well.
https://github.com/llvm/llvm-project/pull/172366
More information about the cfe-commits
mailing list