Skip to content

[SYCL][Driver] Fix spurious OpenMP error with --save-temps and -fsycl-targets - #22808

Open
srividya-sundaram wants to merge 2 commits into
intel:syclfrom
srividya-sundaram:fix-save-temps-sycl-targets-openmp-error
Open

[SYCL][Driver] Fix spurious OpenMP error with --save-temps and -fsycl-targets#22808
srividya-sundaram wants to merge 2 commits into
intel:syclfrom
srividya-sundaram:fix-save-temps-sycl-targets-openmp-error

Conversation

@srividya-sundaram

Copy link
Copy Markdown
Contributor

Problem

clang++ --save-temps -fsycl -fsycl-targets=intel_gpu_pvc -o t t.cpp fails with:

error: OpenMP target is invalid: 'intel_gpu_pvc'

The same command without --save-temps works fine.

Root Cause

Without --save-temps, the driver collapses preprocess + compile + backend + assemble into a single cc1 invocation (-emit-obj). The outermost action 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 the misleading OpenMP error.

Fix

Skip the -fsycl-targets= injection when the output type is TY_LLVM_BC. That step does not need it — 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.

Testing

Added tests to sycl-offload-save-temps.cpp and sycl-offload-save-temps-old-model.cpp verifying that the host -emit-llvm-bc step does not receive -fsycl-targets= for both spir64_gen-unknown-unknown and intel_gpu_pvc targets.

🤖 Generated with Claude Code

…-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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 SYCL CompileJobActions producing TY_LLVM_BC (the -emit-llvm-bc step exposed by --save-temps).
  • Add driver tests ensuring the host -emit-llvm-bc command 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.

@srividya-sundaram
srividya-sundaram marked this pull request as ready for review July 29, 2026 19:14
@srividya-sundaram
srividya-sundaram requested a review from a team as a code owner July 29, 2026 19:14
@srividya-sundaram

Copy link
Copy Markdown
Contributor Author

The CI failures on both Linux and Windows are unrelated to this PR.

Linux failure (SYCL Pre Commit on Linux):

  • Failing test: SYCL :: SpecConstants/2020/nested-non-packed-struct.cpp
  • This is an E2E runtime test for SYCL specialization constants on the CUDA GPU backend. It fails with Assertion 'new_data == data' failed — a pre-existing bug in the CUDA adapter's handling of specialization constants for structs with large alignas alignment.
  • This PR only touches clang/lib/Driver/ToolChains/Clang.cpp and two driver test files; no specialization constant or CUDA adapter code was modified.

Windows failure (SYCL Pre Commit on Windows):

  • sycl/test-e2e/ESIMD/api/replicate_smoke.cpp - an end-to-end ESIMD GPU kernel test that hung on the Windows GPU runner.

This PR's change is a one-line guard in Clang::ConstructJob that skips injecting -fsycl-targets= when the output type is TY_LLVM_BC, fixing a spurious OpenMP error with --save-temps. It has no impact on runtime behavior, specialization constants, or any Windows-specific compilation paths beyond what is covered by the added driver tests.

Comment thread clang/lib/Driver/ToolChains/Clang.cpp Outdated
…-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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants