Skip to content

Commit 72259e0

Browse files
jdmcatamorphism
authored andcommitted
Translate const references to extern functions as *i8 instead of the typical closure pair. Fixes #4522.
1 parent 5de1ca9 commit 72259e0

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/librustc/middle/trans/consts.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,10 +401,13 @@ fn const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
401401
ast::expr_path(pth) => {
402402
assert pth.types.len() == 0;
403403
match cx.tcx.def_map.find(e.id) {
404-
Some(ast::def_fn(def_id, _)) => {
404+
Some(ast::def_fn(def_id, purity)) => {
405405
assert ast_util::is_local(def_id);
406406
let f = base::get_item_val(cx, def_id.node);
407-
C_struct(~[f, C_null(T_opaque_box_ptr(cx))])
407+
match purity {
408+
ast::extern_fn => llvm::LLVMConstPointerCast(f, T_ptr(T_i8())),
409+
_ => C_struct(~[f, C_null(T_opaque_box_ptr(cx))])
410+
}
408411
}
409412
Some(ast::def_const(def_id)) => {
410413
get_const_val(cx, def_id)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2013 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+
extern fn foopy() {}
12+
13+
const f: *u8 = foopy;
14+
const s: S = S { f: foopy };
15+
16+
struct S {
17+
f: *u8
18+
}
19+
20+
fn main() {
21+
}

0 commit comments

Comments
 (0)