Skip to content

Support using const pointers in asm const operand - #138618

Merged
rust-bors[bot] merged 13 commits into
rust-lang:mainfrom
nbdd0121:asm_const_ptr
Jul 26, 2026
Merged

Support using const pointers in asm const operand#138618
rust-bors[bot] merged 13 commits into
rust-lang:mainfrom
nbdd0121:asm_const_ptr

Conversation

@nbdd0121

@nbdd0121 nbdd0121 commented Mar 17, 2025

Copy link
Copy Markdown
Member

View all comments

Implements RFC#3848 with tracking issue #128464

This adds support of const pointers for asm const in addition to plain integers.

The inline asm! support is implemented using i constraint, and the global_asm! and naked_asm! support is implemented by inserting symbol + offset and make symbol compiler-used. For unnamed consts, it will create additional internal & hidden symbols so that they can be referenced by global_asm.

The feature is also implemented for GCC backend but it's untested. Tested now.

@rustbot

This comment was marked as outdated.

@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 Mar 17, 2025
@fmease

fmease commented Mar 17, 2025

Copy link
Copy Markdown
Member

r? codegen

@rustbot rustbot assigned workingjubilee and unassigned fmease Mar 17, 2025
@rust-log-analyzer

This comment has been minimized.

@compiler-errors

Copy link
Copy Markdown
Contributor

r? compiler-errors

@rustbot

rustbot commented Apr 10, 2025

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

Comment thread compiler/rustc_monomorphize/src/collector.rs
Comment thread compiler/rustc_codegen_ssa/src/traits/asm.rs Outdated
Comment thread compiler/rustc_codegen_ssa/src/traits/asm.rs Outdated
@bors

bors commented Apr 29, 2025

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (presumably #140415) made this pull request unmergeable. Please resolve the merge conflicts.

@traviscross

Copy link
Copy Markdown
Contributor

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 4, 2025
@rustbot

rustbot commented May 4, 2025

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rust-log-analyzer

This comment has been minimized.

@rustbot

rustbot commented May 13, 2025

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_codegen_cranelift

cc @bjorn3

@bors

bors commented May 28, 2025

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (presumably #141668) made this pull request unmergeable. Please resolve the merge conflicts.

Comment thread tests/ui/asm/const-refs-to-static.rs
Comment thread tests/assembly-llvm/asm/x86-types.rs Outdated
Comment thread compiler/rustc_codegen_llvm/src/asm.rs Outdated
@rust-bors rust-bors Bot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 23, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 23, 2026
Support using const pointers in asm `const` operand

Implements [RFC#3848](rust-lang/rfcs#3848) with tracking issue rust-lang#128464

This adds support of const pointers for asm `const` in addition to plain integers.

The inline `asm!` support is implemented using `i` constraint, and the `global_asm!` and `naked_asm!` support is implemented by inserting `symbol + offset` and make `symbol` compiler-used. For unnamed consts, it will create additional internal & hidden symbols so that they can be referenced by global_asm.

~~The feature is also implemented for GCC backend but it's untested.~~ Tested now.
rust-bors Bot pushed a commit that referenced this pull request Jul 23, 2026
Rollup of 18 pull requests

Successful merges:

 - #138618 (Support using const pointers in asm `const` operand)
 - #150161 (Remove 'static requirement on try_as_dyn)
 - #158362 (trait solver: account for universes from replace_bound_vars)
 - #159173 (Add allowed list check on EII implementations attributes)
 - #159466 (cmse: clear variant-dependent padding in `enum`s)
 - #159718 (Make `DocLinkResMap` an `FxIndexMap`)
 - #155795 (constify `vec![1, 2, 3]` macro)
 - #157776 (ci: Enable autodiff tests on x86_64 linux)
 - #157905 (Update comments and add tests for `-Zrandomize-layout` for some guaranteed ZSTs)
 - #159041 (Reorganize `tests/ui/issues` [22/N])
 - #159108 (Reorganize `tests/ui/issues` [23/N])
 - #159138 (doc: document wasm import symbol mangling)
 - #159531 (Reorganize `tests/ui/issues` [28/N])
 - #159608 (early_otherwise: Don't hoist dereferences when the otherwise branch is reachable)
 - #159612 (Reorganize `tests/ui/issues` [29/N])
 - #159653 (run `tests/assembly-llvm/asm/aarch64-types.rs` for `aarch64_be`)
 - #159759 (rustc-dev-guide subtree update)
 - #159761 (Remove outdated comment for resolve_vars_with_obligations)
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 23, 2026
Support using const pointers in asm `const` operand

Implements [RFC#3848](rust-lang/rfcs#3848) with tracking issue rust-lang#128464

This adds support of const pointers for asm `const` in addition to plain integers.

The inline `asm!` support is implemented using `i` constraint, and the `global_asm!` and `naked_asm!` support is implemented by inserting `symbol + offset` and make `symbol` compiler-used. For unnamed consts, it will create additional internal & hidden symbols so that they can be referenced by global_asm.

~~The feature is also implemented for GCC backend but it's untested.~~ Tested now.
@folkertdev

Copy link
Copy Markdown
Contributor

This PR fails the tests/assembly-llvm/asm/global_asm.rs locally on x86_64, and is the likely cause of this rollup failure:

@bors r- #159762 (comment)

cc @jhpratt

This test should maybe be a minicore test anyway?

@rust-bors

rust-bors Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved.

This PR was contained in a rollup (#159766), which was unapproved.

View changes since this unapproval

nbdd0121 added 3 commits July 23, 2026 18:51
The backend now fully supports codegen of const pointers, remove the
block inside typeck behind a new feature gate. Tests are also added.
Use edition 2021 so c-string literals are supported.
@nbdd0121

nbdd0121 commented Jul 23, 2026

Copy link
Copy Markdown
Member Author

Sorry, forgot to update the assembly-llvm tests when changing the symbol names. Fixed now.

Changing to use minicore fails with the error below, so I kept it untouched.

error[E0608]: cannot index into a value of type `[{integer}; 2]`
  --> tests/assembly-llvm/asm/global_asm.rs:36:49
   |
36 | global_asm!("lea rax, [rip + {}]", const &[1; 2][1]);
   |                                                 ^^^

error: aborting due to 1 previous error

@rustbot ready

@bjorn3

bjorn3 commented Jul 23, 2026

Copy link
Copy Markdown
Member

r=me once CI passes

@folkertdev

Copy link
Copy Markdown
Contributor

@bors try jobs=x86_64-gnu-llvm-22-*

@rust-bors

This comment has been minimized.

@rust-bors

rust-bors Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 72cd1f7 (72cd1f73c1af9e44d62bc5d04fc24363d2b3bf3e)
Base parent: 165cce8 (165cce8d820b229af8f6a8226cf0b910b57600ff)

@bjorn3

bjorn3 commented Jul 24, 2026

Copy link
Copy Markdown
Member

@bors r+

@rust-bors

rust-bors Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 0316085 has been approved by bjorn3

It is now in the queue for this repository.

🌲 The tree is currently closed for pull requests below priority 1. This pull request will be tested once the tree is reopened.

Reason for tree closure: spurious CI failures

@rust-bors

This comment has been minimized.

@rust-bors

rust-bors Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

💔 Test for 2e47e68 failed: CI

@JonathanBrouwer

Copy link
Copy Markdown
Contributor

@bors retry
Spurious

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

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.