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

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.

let ty = self.type_ix(32);
let val = self.const_int(ty, 0);
self.call_intrinsic("llvm.returnaddress", &[], &[val])
}
Copy link
Copy Markdown
Member

@bjorn3 bjorn3 Apr 8, 2026

Choose a reason for hiding this comment

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

View changes since the review

This can be implemented in cg_clif using fx.bcx.ins().get_return_address(fx.pointer_type).

/// Other forms of the corresponding gcc or llvm intrinsic (which can have wildly unpredictable results or even crash at runtime) are not exposed.
#[rustc_intrinsic]
#[rustc_nounwind]
pub fn return_address<T>() -> *const T {
Copy link
Copy Markdown
Member

@RalfJung RalfJung Apr 8, 2026

Choose a reason for hiding this comment

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

View changes since the review

It seems the only user hard-codes T to be (). Why make it generic?

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.

This is to handle later switches to use Code if that's ultimately desirable later (only the use site would need to change).

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.

Given that this intrinsic is an implementation detail, I don't think it is worth preparing it for hypothetical future changes. It just causes unnecessary confusion now.

Wording/docs changes.

Co-authored-by: Ralf Jung <post@ralfj.de>
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.

6 participants