diff --git a/src/librustc/middle/trans/adt.rs b/src/librustc/middle/trans/adt.rs index 7b194690b2f23..5a3d226fa3c0a 100644 --- a/src/librustc/middle/trans/adt.rs +++ b/src/librustc/middle/trans/adt.rs @@ -46,6 +46,7 @@ use std::container::Map; use std::libc::c_ulonglong; use std::option::{Option, Some, None}; +use std::num::{Bitwise}; use lib::llvm::{ValueRef, True, IntEQ, IntNE}; use middle::trans::_match; @@ -424,19 +425,22 @@ fn generic_type_of(cx: &CrateContext, r: &Repr, name: Option<&str>, sizing: bool let align = most_aligned.align; let discr_ty = ll_inttype(cx, ity); let discr_size = machine::llsize_of_alloc(cx, discr_ty) as u64; + let align_units = (size + align - 1) / align - 1; let pad_ty = match align { - 1 => Type::i8(), - 2 => Type::i16(), - 4 => Type::i32(), - 8 if machine::llalign_of_min(cx, Type::i64()) == 8 => Type::i64(), + 1 => Type::array(&Type::i8(), align_units), + 2 => Type::array(&Type::i16(), align_units), + 4 => Type::array(&Type::i32(), align_units), + 8 if machine::llalign_of_min(cx, Type::i64()) == 8 => + Type::array(&Type::i64(), align_units), + a if a.population_count() == 1 => Type::array(&Type::vector(&Type::i32(), a / 4), + align_units), _ => fail!("Unsupported enum alignment: {:?}", align) }; assert_eq!(machine::llalign_of_min(cx, pad_ty) as u64, align); - let align_units = (size + align - 1) / align; assert_eq!(align % discr_size, 0); let fields = ~[discr_ty, - Type::array(&discr_ty, align / discr_size - 1), - Type::array(&pad_ty, align_units - 1)]; + Type::array(&discr_ty, align / discr_size - 1), + pad_ty]; match name { None => Type::struct_(fields, false), Some(name) => { diff --git a/src/test/run-pass/simd-generics.rs b/src/test/run-pass/simd-generics.rs new file mode 100644 index 0000000000000..900d2befea432 --- /dev/null +++ b/src/test/run-pass/simd-generics.rs @@ -0,0 +1,38 @@ +// Copyright 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// xfail-fast + +#[feature(simd)]; + +use std::ops; + +#[simd] struct f32x4(f32, f32, f32, f32); + +fn add>(lhs: T, rhs: T) -> T { + lhs + rhs +} + +impl ops::Add for f32x4 { + fn add(&self, rhs: &f32x4) -> f32x4 { + *self + *rhs + } +} + +pub fn main() { + let lr = f32x4(1.0f32, 2.0f32, 3.0f32, 4.0f32); + + // lame-o + let f32x4(x, y, z, w) = add(lr, lr); + assert_eq!(x, 2.0f32); + assert_eq!(y, 4.0f32); + assert_eq!(z, 6.0f32); + assert_eq!(w, 8.0f32); +} diff --git a/src/test/run-pass/simd-issue-10604.rs b/src/test/run-pass/simd-issue-10604.rs new file mode 100644 index 0000000000000..4132ec0059ff9 --- /dev/null +++ b/src/test/run-pass/simd-issue-10604.rs @@ -0,0 +1,18 @@ +// Copyright 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// xfail-fast + +#[allow(experimental)]; +#[feature(simd)]; + +pub fn main() { + let _o = None::; +}