Skip to content

Commit af2fe63

Browse files
authored
Auto merge of #34491 - eddyb:return-in-peace, r=nagisa
Remove the return_address intrinsic. This intrinsic to get the return pointer was introduced in #16248 / #16081 by @pcwalton for Servo. However, as explained in #34227, it's impossible to ensure it's used correctly, and it broke with `-Zorbit`. Servo's usage is being replaced in servo/servo#11872, and I expect nobody else to have abused it. But I've also started a crater run, just in case this is a `[breaking-change]` for anyone else.
2 parents 3059bb9 + b30134d commit af2fe63

File tree

6 files changed

+0
-125
lines changed

6 files changed

+0
-125
lines changed

src/libcore/intrinsics.rs

-6
Original file line numberDiff line numberDiff line change
@@ -293,12 +293,6 @@ extern "rust-intrinsic" {
293293
#[stable(feature = "rust1", since = "1.0.0")]
294294
pub fn transmute<T, U>(e: T) -> U;
295295

296-
/// Gives the address for the return value of the enclosing function.
297-
///
298-
/// Using this intrinsic in a function that does not use an out pointer
299-
/// will trigger a compiler error.
300-
pub fn return_address() -> *const u8;
301-
302296
/// Returns `true` if the actual type given as `T` requires drop
303297
/// glue; returns `false` if the actual type provided for `T`
304298
/// implements `Copy`.

src/librustc_trans/diagnostics.rs

-38
Original file line numberDiff line numberDiff line change
@@ -12,44 +12,6 @@
1212

1313
register_long_diagnostics! {
1414

15-
E0510: r##"
16-
`return_address` was used in an invalid context. Erroneous code example:
17-
18-
```ignore
19-
#![feature(intrinsics)]
20-
21-
extern "rust-intrinsic" {
22-
fn return_address() -> *const u8;
23-
}
24-
25-
unsafe fn by_value() -> i32 {
26-
let _ = return_address();
27-
// error: invalid use of `return_address` intrinsic: function does
28-
// not use out pointer
29-
0
30-
}
31-
```
32-
33-
Return values may be stored in a return register(s) or written into a so-called
34-
out pointer. In case the returned value is too big (this is
35-
target-ABI-dependent and generally not portable or future proof) to fit into
36-
the return register(s), the compiler will return the value by writing it into
37-
space allocated in the caller's stack frame. Example:
38-
39-
```
40-
#![feature(intrinsics)]
41-
42-
extern "rust-intrinsic" {
43-
fn return_address() -> *const u8;
44-
}
45-
46-
unsafe fn by_pointer() -> String {
47-
let _ = return_address();
48-
String::new() // ok!
49-
}
50-
```
51-
"##,
52-
5315
E0511: r##"
5416
Invalid monomorphization of an intrinsic function was used. Erroneous code
5517
example:

src/librustc_trans/intrinsic.rs

-12
Original file line numberDiff line numberDiff line change
@@ -617,18 +617,6 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
617617

618618
},
619619

620-
621-
(_, "return_address") => {
622-
if !fcx.fn_ty.ret.is_indirect() {
623-
span_err!(tcx.sess, span, E0510,
624-
"invalid use of `return_address` intrinsic: function \
625-
does not use out pointer");
626-
C_null(Type::i8p(ccx))
627-
} else {
628-
PointerCast(bcx, llvm::get_param(fcx.llfn, 0), Type::i8p(ccx))
629-
}
630-
}
631-
632620
(_, "discriminant_value") => {
633621
let val_ty = substs.types.get(FnSpace, 0);
634622
match val_ty.sty {

src/librustc_typeck/check/intrinsic.rs

-2
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,6 @@ pub fn check_intrinsic_type(ccx: &CrateCtxt, it: &hir::ForeignItem) {
275275
"fadd_fast" | "fsub_fast" | "fmul_fast" | "fdiv_fast" | "frem_fast" =>
276276
(1, vec![param(ccx, 0), param(ccx, 0)], param(ccx, 0)),
277277

278-
"return_address" => (0, vec![], tcx.mk_imm_ptr(tcx.types.u8)),
279-
280278
"assume" => (0, vec![tcx.types.bool], tcx.mk_nil()),
281279

282280
"discriminant_value" => (1, vec![

src/test/compile-fail/intrinsic-return-address.rs

-24
This file was deleted.

src/test/run-pass/intrinsic-return-address.rs

-43
This file was deleted.

0 commit comments

Comments
 (0)