Skip to content

Commit

Permalink
Fix uninit() intrinsic when used with empty types
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Jan 16, 2014
1 parent fd31830 commit 76c9028
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
Expand Down
24 changes: 24 additions & 0 deletions src/test/run-pass/uninit-empty-types.rs
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit 76c9028

Please sign in to comment.