[SYCL][Driver] Fix spurious OpenMP error with --save-temps and -fsycl-targets - #22808
[SYCL][Driver] Fix spurious OpenMP error with --save-temps and -fsycl-targets#22808srividya-sundaram wants to merge 2 commits into
Conversation
…-targets Without --save-temps, the driver collapses preprocess + compile + backend + assemble into a single cc1 invocation (-emit-obj). The outermost action seen in constructJob is an AssembleJobAction, so the block that injects -fsycl-targets= into cc1 args (guarded by isa<CompileJobAction>(JA)) never fires. With --save-temps, collapsing is disabled and the host compile becomes a separate cc1 invocation emitting LLVM BC (-emit-llvm-bc, output type TY_LLVM_BC). The guard fires and -fsycl-targets=intel_gpu_pvc is added to that cc1's arguments. Since -fsycl-targets= is an alias for --offload-targets=, CompilerInvocation.cpp unconditionally validates the value as an OpenMP target triple. intel_gpu_pvc is a SYCL-specific shorthand, not a valid triple, so it fails with: error: OpenMP target is invalid: 'intel_gpu_pvc' Fix: skip the -fsycl-targets= injection when the output type is TY_LLVM_BC. That step does not need -fsycl-targets= -- all target-specific decisions are already baked into the preprocessed .ii via the integration header. The fix applies to both the old and new offload drivers. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Fixes a SYCL driver issue where --save-temps causes the host -emit-llvm-bc cc1 invocation to receive -fsycl-targets=…, which is an alias for --offload-targets=… and triggers OpenMP target-triple validation (failing on SYCL shorthands like intel_gpu_pvc). The change prevents that argument injection specifically for the host bitcode-emission step and adds regression tests for both the new and old offload driver models.
Changes:
- Skip
-fsycl-targets=injection for host SYCLCompileJobActions producingTY_LLVM_BC(the-emit-llvm-bcstep exposed by--save-temps). - Add driver tests ensuring the host
-emit-llvm-bccommand line does not contain-fsycl-targets=for both a real triple and a SYCL shorthand target. - Cover both the new offload driver and the old model.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| clang/lib/Driver/ToolChains/Clang.cpp | Avoids injecting -fsycl-targets= into the host SYCL bitcode-emission cc1 invocation (prevents spurious OpenMP target validation). |
| clang/test/Driver/sycl-offload-save-temps.cpp | Adds new-driver regression checks that the host -emit-llvm-bc line does not include -fsycl-targets= (including intel_gpu_pvc). |
| clang/test/Driver/sycl-offload-save-temps-old-model.cpp | Adds old-driver regression checks for the same condition as above. |
|
The CI failures on both Linux and Windows are unrelated to this PR. Linux failure (
Windows failure (
This PR's change is a one-line guard in |
…-targets Remove the block in Clang::ConstructJob that injected -fsycl-targets= into host SYCL compile cc1 invocations. The block was introduced for the old offload model but has been effectively dead for some time: without --save-temps the host compile is a single collapsed cc1 step whose JA is an AssembleJobAction, so isa<CompileJobAction>(JA) is never true and the block never fires. With --save-temps, collapsing is disabled and the host compile becomes a separate CompileJobAction emitting LLVM BC. The block would fire and add -fsycl-targets=intel_gpu_pvc to that cc1's args. Since -fsycl-targets= is an alias for --offload-targets=, CompilerInvocation.cpp unconditionally validates the value as an OpenMP target triple, and intel_gpu_pvc (a SYCL-specific shorthand, not a valid triple) produces: error: OpenMP target is invalid: 'intel_gpu_pvc' The fix is to remove the block entirely: -fsycl-targets= is not consumed by any host cc1 code path (not in Sema, CodeGen, or Parse) and the host compile has no use for it. The fix applies to both the old and new offload drivers. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Problem
clang++ --save-temps -fsycl -fsycl-targets=intel_gpu_pvc -o t t.cppfails with:The same command without
--save-tempsworks fine.Root Cause
Without
--save-temps, the driver collapses preprocess + compile + backend + assemble into a single cc1 invocation (-emit-obj). The outermost action inconstructJobis anAssembleJobAction, so the block that injects-fsycl-targets=into cc1 args (guarded byisa<CompileJobAction>(JA)) never fires.With
--save-temps, collapsing is disabled and the host compile becomes a separate cc1 invocation emitting LLVM BC (-emit-llvm-bc, output typeTY_LLVM_BC). The guard fires and-fsycl-targets=intel_gpu_pvcis added to that cc1's arguments.Since
-fsycl-targets=is an alias for--offload-targets=,CompilerInvocation.cppunconditionally validates the value as an OpenMP target triple.intel_gpu_pvcis a SYCL-specific shorthand, not a valid triple, so it fails with the misleading OpenMP error.Fix
Skip the
-fsycl-targets=injection when the output type isTY_LLVM_BC. That step does not need it — all target-specific decisions are already baked into the preprocessed.iivia the integration header. The fix applies to both the old and new offload drivers.Testing
Added tests to
sycl-offload-save-temps.cppandsycl-offload-save-temps-old-model.cppverifying that the host-emit-llvm-bcstep does not receive-fsycl-targets=for bothspir64_gen-unknown-unknownandintel_gpu_pvctargets.🤖 Generated with Claude Code