Fix uninit() intrinsic when used with empty types
This commit is contained in:
parent
fd318300cf
commit
76c90283ce
2 changed files with 25 additions and 1 deletions
|
@ -317,7 +317,7 @@ pub fn trans_intrinsic(ccx: @CrateContext,
|
|||
"uninit" => {
|
||||
// Do nothing, this is effectively a no-op
|
||||
let retty = substs.tys[0];
|
||||
if type_is_immediate(ccx, retty) && !ty::type_is_nil(retty) {
|
||||
if type_is_immediate(ccx, retty) && !type_is_voidish(ccx, retty) {
|
||||
unsafe {
|
||||
Ret(bcx, lib::llvm::llvm::LLVMGetUndef(type_of(ccx, retty).to_ref()));
|
||||
}
|
||||
|
|
24
src/test/run-pass/uninit-empty-types.rs
Normal file
24
src/test/run-pass/uninit-empty-types.rs
Normal file
|
@ -0,0 +1,24 @@
|
|||
// Copyright 2012-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.
|
||||
|
||||
// Test the uninit() construct returning various empty types.
|
||||
|
||||
use std::vec;
|
||||
use std::unstable::intrinsics;
|
||||
|
||||
#[deriving(Clone)]
|
||||
struct Foo;
|
||||
|
||||
fn main() {
|
||||
unsafe {
|
||||
let _x: Foo = intrinsics::uninit();
|
||||
let _x: [Foo, ..2] = intrinsics::uninit();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue