Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ICE when calling static and static mut function pointers #8594

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/librustc/middle/trans/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ pub fn trans(bcx: @mut Block, expr: @ast::expr) -> Callee {
ast::def_struct(def_id) => {
fn_callee(bcx, trans_fn_ref(bcx, def_id, ref_expr.id))
}
ast::def_static(*) |
ast::def_arg(*) |
ast::def_local(*) |
ast::def_binding(*) |
Expand All @@ -140,7 +141,7 @@ pub fn trans(bcx: @mut Block, expr: @ast::expr) -> Callee {
datum_callee(bcx, ref_expr)
}
ast::def_mod(*) | ast::def_foreign_mod(*) | ast::def_trait(*) |
ast::def_static(*) | ast::def_ty(*) | ast::def_prim_ty(*) |
ast::def_ty(*) | ast::def_prim_ty(*) |
ast::def_use(*) | ast::def_typaram_binder(*) |
ast::def_region(*) | ast::def_label(*) | ast::def_ty_param(*) |
ast::def_self_ty(*) | ast::def_method(*) => {
Expand Down
14 changes: 14 additions & 0 deletions src/test/auxiliary/static-function-pointer-aux.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

pub fn f(x: int) -> int { -x }

pub static F: extern fn(int) -> int = f;
pub static mut MutF: extern fn(int) -> int = f;
26 changes: 26 additions & 0 deletions src/test/run-pass/static-function-pointer-xc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// xfail-fast
// aux-build:static-function-pointer-aux.rs
extern mod aux(name = "static-function-pointer-aux");

fn f(x: int) -> int { x }

fn main() {
assert_eq!(aux::F(42), -42);
unsafe {
assert_eq!(aux::MutF(42), -42);
aux::MutF = f;
assert_eq!(aux::MutF(42), 42);
aux::MutF = aux::f;
assert_eq!(aux::MutF(42), -42);
}
}
24 changes: 24 additions & 0 deletions src/test/run-pass/static-function-pointer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

fn f(x: int) -> int { x }
fn g(x: int) -> int { 2 * x }

static F: extern fn(int) -> int = f;
static mut G: extern fn(int) -> int = f;

fn main() {
Copy link
Member

Choose a reason for hiding this comment

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

I think for windows this also needs to be pub fn main

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

assert_eq!(F(42), 42);
unsafe {
assert_eq!(G(42), 42);
G = g;
assert_eq!(G(42), 84);
}
}