Skip to content

Implement core::arch::return_address and tests#154972

Open
chorman0773 wants to merge 3 commits intorust-lang:mainfrom
chorman0773:return_address
Open

Implement core::arch::return_address and tests#154972
chorman0773 wants to merge 3 commits intorust-lang:mainfrom
chorman0773:return_address

Conversation

@chorman0773
Copy link
Copy Markdown
Contributor

@chorman0773 chorman0773 commented Apr 7, 2026

View all comments

Tracking issue: #154966

Implements libs-team#768

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 7, 2026

Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter
gets adapted for the changes, if necessary.

cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. 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. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 7, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 7, 2026

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @scottmcm, libs
  • @scottmcm, libs expanded to 8 candidates
  • Random selection from Mark-Simulacrum, jhpratt, scottmcm

@rust-log-analyzer

This comment has been minimized.

Comment thread compiler/rustc_codegen_llvm/src/intrinsic.rs
Comment thread library/core/src/intrinsics/mod.rs Outdated
Comment thread library/core/src/arch.rs Outdated
Comment thread library/core/src/intrinsics/mod.rs Outdated
@rust-log-analyzer

This comment has been minimized.

@chorman0773
Copy link
Copy Markdown
Contributor Author

Helpful comment, thanks rustbot 😐

Copy link
Copy Markdown
Member

@Mark-Simulacrum Mark-Simulacrum left a comment

Choose a reason for hiding this comment

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

I'm not a huge fan of the doc comment's language. Could you try iterating on it a bit?

I think adding the cranelift implementation in this PR would also make sense (and maybe a gcc backend implementation -- not sure how easy that is?).

r=me with at least the comment fixed.

View changes since this review

Comment thread library/core/src/arch.rs Outdated
@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 Apr 11, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 11, 2026

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

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 13, 2026

Some changes occurred in compiler/rustc_codegen_cranelift

cc @bjorn3

@chorman0773
Copy link
Copy Markdown
Contributor Author

chorman0773 commented Apr 13, 2026

I've changed the wording of the comment arround a bit, in part to make it more clear than returning null is something the compiler tries to do if it can't return a useful value for some reason, but doesn't guarantee. I've also added a cranelift impl. I'll figure out gcc/miri in a future PR.

r=@Mark-Simulacrum

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 13, 2026
Comment thread compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs Outdated
@rustbot rustbot assigned bjorn3 and unassigned Mark-Simulacrum Apr 18, 2026
@Mark-Simulacrum
Copy link
Copy Markdown
Member

r=me with commits squashed

r? me

@rustbot rustbot assigned Mark-Simulacrum and unassigned bjorn3 Apr 18, 2026
Fix typo

Apply suggestions from code review

Wording/docs changes.

Co-authored-by: Ralf Jung <post@ralfj.de>

Change signature according to Ralf's comment

Fix call to `core::intrinsics::return_address()` according to the new signature

Add cranelift implementation for intrinsic

Change wording on `return_address!()` to be clear that returning a null pointer is best-effort.

Fix formatting of doc comment

Fix mistake in cranelift codegen
@rust-bors rust-bors Bot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 19, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Apr 19, 2026
…-Simulacrum

Implement `core::arch::return_address` and tests

Tracking issue: rust-lang#154966

Implements libs-team#768
rust-bors Bot pushed a commit that referenced this pull request Apr 19, 2026
Rollup of 9 pull requests

Successful merges:

 - #155370 (Add regression test for dead code elimination with drop + panic)
 - #154823 (Replace the spdx-rs dependency with a minimal in-tree SPDX tag-value parser)
 - #154972 (Implement `core::arch::return_address` and tests)
 - #155294 (Add test for coalescing of diagnostic attribute duplicates)
 - #155352 (triagebot.toml: Sync `assign.owners` with `autolabel."T-compiler"`)
 - #155431 (Add temporary scope to assert_matches)
 - #152995 (ACP Implementation of PermissionsExt for Windows )
 - #153873 (deprecate `std::char` constants and functions)
 - #154865 (libtest: use binary search for --exact test filtering)
@jhpratt
Copy link
Copy Markdown
Member

jhpratt commented Apr 19, 2026

@bors r-

#155506 (comment)

@rust-bors rust-bors Bot 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Apr 19, 2026
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 19, 2026

This pull request was unapproved.

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

@chorman0773
Copy link
Copy Markdown
Contributor Author

Oh ok. lang-ref forgets to mention that the intrinsic doesn't work on some targets (wasm).

@chorman0773
Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 19, 2026
@Mark-Simulacrum
Copy link
Copy Markdown
Member

@bors r+ rollup=iffy

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 19, 2026

📌 Commit 592e9c0 has been approved by Mark-Simulacrum

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 19, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Apr 19, 2026
Implement `core::arch::return_address` and tests



Tracking issue: #154966 

Implements libs-team#768
@rust-log-analyzer

This comment has been minimized.

@rust-bors rust-bors Bot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Apr 20, 2026
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Apr 20, 2026

💔 Test for ec8f768 failed: CI. Failed job:

@rust-bors rust-bors Bot 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 Apr 22, 2026
Comment thread library/core/src/arch.rs
///
/// ## Example
/// ```
/// # #![cfg(not(miri))] // FIXME: Figure out how to make miri work before stabilizing this macro
Copy link
Copy Markdown
Member

@RalfJung RalfJung Apr 22, 2026

Choose a reason for hiding this comment

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

Miri should probably just pick an arbitrary 64bit integer and return that? Or is that too adversarial and we should return null?

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It probably should (though I see it doing either). Right now, I'd like something landed though. My plan is to figure out miri (and codegen_gcc) before stabilization.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

(I suppose we could briefly discuss whether it is "fine" to return just null tomorrow)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That's more of a Miri thing than an opsem thing so I'd prefer to discuss that in the PR which implements it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fair. In any case, the main thing a random implementation would detect is someone doing a null test, then some form of stupid shenanigans like transmuting to a function pointer and calling it (or .read()ing it). Raw .read() or transmute/call would be detected since null pointer would trip anyways.

@chorman0773
Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 23, 2026
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-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. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants