Skip to content

Commit dc36cba

Browse files
committed
---
yaml --- r: 128739 b: refs/heads/try c: 5aedcb1 h: refs/heads/master i: 128737: 4b9d9bd 128735: 2d714e8 v: v3
1 parent f421683 commit dc36cba

File tree

6 files changed

+52
-7
lines changed

6 files changed

+52
-7
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 07d86b46a949a94223da714e35b343243e4ecce4
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: a86d9ad15e339ab343a12513f9c90556f677b9ca
5-
refs/heads/try: 9dac85f92daa094f94f124fd06cfeb5339d48772
5+
refs/heads/try: 5aedcb1e916711bfeb65c26b5c6210a3fb5d72bf
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/libcore/intrinsics.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,13 @@ extern "rust-intrinsic" {
310310
/// ```
311311
pub fn transmute<T,U>(e: T) -> U;
312312

313+
/// Gives the address for the return value of the enclosing function.
314+
///
315+
/// Using this instrinsic in a function that does not use an out pointer
316+
/// will trigger a compiler error.
317+
#[cfg(not(stage0))]
318+
pub fn return_address() -> *const u8;
319+
313320
/// Returns `true` if a type requires drop glue.
314321
pub fn needs_drop<T>() -> bool;
315322

branches/try/src/librustc/middle/trans/callee.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,9 +765,11 @@ pub fn trans_call_inner<'a>(
765765
assert!(abi == synabi::RustIntrinsic);
766766
assert!(dest.is_some());
767767

768+
let call_info = call_info.expect("no call info for intrinsic call?");
768769
return intrinsic::trans_intrinsic_call(bcx, node, callee_ty,
769770
arg_cleanup_scope, args,
770-
dest.unwrap(), substs);
771+
dest.unwrap(), substs,
772+
call_info);
771773
}
772774
NamedTupleConstructor(substs, disr) => {
773775
assert!(dest.is_some());

branches/try/src/librustc/middle/trans/intrinsic.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ pub fn check_intrinsics(ccx: &CrateContext) {
126126
pub fn trans_intrinsic_call<'a>(mut bcx: &'a Block<'a>, node: ast::NodeId,
127127
callee_ty: ty::t, cleanup_scope: cleanup::CustomScopeIndex,
128128
args: callee::CallArgs, dest: expr::Dest,
129-
substs: subst::Substs) -> Result<'a> {
129+
substs: subst::Substs, call_info: NodeInfo) -> Result<'a> {
130130

131131
let fcx = bcx.fcx;
132132
let ccx = fcx.ccx;
@@ -426,9 +426,14 @@ pub fn trans_intrinsic_call<'a>(mut bcx: &'a Block<'a>, node: ast::NodeId,
426426
*llargs.get(0), *llargs.get(1)),
427427

428428
(_, "return_address") => {
429-
PointerCast(bcx,
430-
bcx.fcx.llretptr.get().unwrap(),
431-
Type::i8p(bcx.ccx()))
429+
if !fcx.caller_expects_out_pointer {
430+
tcx.sess.span_err(call_info.span,
431+
"invalid use of `return_address` intrinsic: function \
432+
does not use out pointer");
433+
C_null(Type::i8p(ccx))
434+
} else {
435+
PointerCast(bcx, llvm::get_param(fcx.llfn, 0), Type::i8p(ccx))
436+
}
432437
}
433438

434439
// This requires that atomic intrinsics follow a specific naming pattern:
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![allow(warnings)]
12+
#![feature(intrinsics)]
13+
14+
extern "rust-intrinsic" {
15+
fn return_address() -> *const u8;
16+
}
17+
18+
unsafe fn f() {
19+
let _ = return_address();
20+
//~^ ERROR invalid use of `return_address` intrinsic: function does not use out pointer
21+
}
22+
23+
unsafe fn g() -> int {
24+
let _ = return_address();
25+
//~^ ERROR invalid use of `return_address` intrinsic: function does not use out pointer
26+
0
27+
}
28+
29+
fn main() {}
30+
31+

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(intrinsics)];
11+
#![feature(intrinsics)]
1212

1313
use std::ptr;
1414

0 commit comments

Comments
 (0)