Skip to content

Commit 7fbe800

Browse files
dotdashthestinger
authored andcommitted
Fix a crash when transmuting non-immediate to immediate types
The code to build the transmute intrinsic currently makes the invalid assumption that if the in-type is non-immediate, the out-type is non-immediate as well. But this is wrong, for example when transmuting [int, ..1] to int. So we need to handle this fourth case as well. Fixes #7988
1 parent 254339f commit 7fbe800

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/librustc/middle/trans/foreign.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,9 @@ pub fn trans_intrinsic(ccx: @mut CrateContext,
805805
_ => Ret(bcx, BitCast(bcx, llsrcval, llouttype))
806806
}
807807
}
808+
} else if ty::type_is_immediate(ccx.tcx, out_type) {
809+
let llsrcptr = PointerCast(bcx, llsrcval, llouttype.ptr_to());
810+
Ret(bcx, Load(bcx, llsrcptr));
808811
} else {
809812
// NB: Do not use a Load and Store here. This causes massive
810813
// code bloat when `transmute` is used on large structural
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
// Issue #7988
12+
// Transmuting non-immediate type to immediate type
13+
14+
fn main() {
15+
unsafe {
16+
std::cast::transmute::<[int,..1],int>([1])
17+
};
18+
}

0 commit comments

Comments
 (0)