Skip to content

Fix Xtensa clobber_abi("C") and clobbers of optional registers - #166700

Open
AlixANNERAUD wants to merge 2 commits into
rust-lang:mainfrom
AlixANNERAUD:fix/xtensa-clobber-abi
Open

AlixANNERAUD wants to merge 2 commits into
rust-lang:mainfrom
AlixANNERAUD:fix/xtensa-clobber-abi

Conversation

@AlixANNERAUD

@AlixANNERAUD AlixANNERAUD commented Nov 28, 2026 •

Copy link
Copy Markdown

This PR fixes two problems with inline assembly clobbers on Xtensa.

Changes

  • The has_fp, has_bool, has_loop, has_mac16 and has_s32c1i register filters now accept clobbers when the target does not have the feature. RISC-V and Arm already work this way.

  • InlineAsmClobberAbi::Xtensa is replaced by two ABIs:

    • XtensaWindowed clobbers a8-a15.
    • XtensaCall0 clobbers a2-a11.

    The windowed target feature selects the ABI for clobber_abi("C"). Both ABIs also clobber the floating-point, special and boolean registers.

Why

rustc requires the windowed feature on all Xtensa targets. But clobber_abi("C") used the call0 register set. On windowed targets, this set is incorrect:

  • It does not contain a12-a15. A function called with call8 can overwrite these registers.
  • It contains a7. In the windowed ABI, a7 is the frame pointer, and inline assembly cannot use it as an operand. Because of this, clobber_abi("C") does not compile on ESP32.

On ESP32-S2, clobber_abi("C") also fails for a second reason. The target does not have the floating-point, loop, boolean and MAC16 features, and the register filters rejected the clobbers of these registers.

Testing

  • New test tests/codegen-llvm/asm/xtensa-clobbers.rs, with the esp32, esp32s2 and call0 revisions.
  • The test has no ESP32-S3 revision. The LLVM that rustc uses does not know the esp32s3 CPU. Because of this, xtensa-esp32s3-none-elf currently compiles with the generic CPU, without the windowed feature.
  • Upstream CI does not build the Xtensa backend of LLVM, so these tests do not run in CI.
  • I ran them on my fork with an LLVM build that includes the Xtensa backend: run 46091649823. Results:
    • The new codegen test passes.
    • The two existing Xtensa assembly tests pass.
    • LLVM accepts all the clobbers when it generates assembly.
    • tidy passes.

Disclosure

This PR was made with an LLM (Claude Opus 5.5) and reviewed by the author.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 28, 2026
@rustbot

rustbot commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project has assigned @Enselic (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks.

Please see the contribution instructions and our LLM policy for more information.

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 79 candidates
  • Random selection from 20 candidates

@AlixANNERAUD

Copy link
Copy Markdown
Author

r? @Amanieu

@rustbot rustbot assigned Amanieu and unassigned Enselic Nov 28, 2026
@rust-log-analyzer

This comment has been minimized.

@AlixANNERAUD
AlixANNERAUD force-pushed the fix/xtensa-clobber-abi branch from 8eb2d7e to c5a8cc9 Compare November 29, 2026 22:46
@rust-log-analyzer

This comment has been minimized.

@AlixANNERAUD
AlixANNERAUD force-pushed the fix/xtensa-clobber-abi branch from c5a8cc9 to f8e7c9e Compare November 29, 2026 22:58

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants