Skip to content

Commit c4b4cb3

Browse files
committed
Fix segfault when calling tuple struct constructor as extern fn
Fixes #5315
1 parent 7503396 commit c4b4cb3

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/librustc/middle/trans/expr.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -795,14 +795,18 @@ fn trans_def_dps_unadjusted(bcx: @mut Block, ref_expr: &ast::expr,
795795
return bcx;
796796
}
797797
}
798-
ast::def_struct(*) => {
798+
ast::def_struct(def_id) => {
799799
let ty = expr_ty(bcx, ref_expr);
800800
match ty::get(ty).sty {
801801
ty::ty_struct(did, _) if ty::has_dtor(ccx.tcx, did) => {
802802
let repr = adt::represent_type(ccx, ty);
803803
adt::trans_start_init(bcx, repr, lldest, 0);
804804
}
805-
_ => {}
805+
ty::ty_bare_fn(*) => {
806+
let fn_data = callee::trans_fn_ref(bcx, def_id, ref_expr.id);
807+
Store(bcx, fn_data.llfn, lldest);
808+
}
809+
_ => ()
806810
}
807811
return bcx;
808812
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2012 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+
struct Foo(int);
12+
struct Bar(int, int);
13+
14+
fn main() {
15+
let f: extern fn(int) -> Foo = Foo;
16+
let g: extern fn(int, int) -> Bar = Bar;
17+
f(42);
18+
g(4, 7);
19+
}

0 commit comments

Comments
 (0)