Skip to content

Commit b1c23f6

Browse files
committed
rollup merge of rust-lang#20611: simnalamburt/master
This PR fixes the issue rust-lang#20460, and it doesn't touch any existing behavior except the bug of the SIMD types. Closes rust-lang#20460.
2 parents ebe8411 + 9041e6e commit b1c23f6

File tree

3 files changed

+75
-3
lines changed

3 files changed

+75
-3
lines changed

src/librustc_trans/trans/intrinsic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
313313
(_, "size_of") => {
314314
let tp_ty = *substs.types.get(FnSpace, 0);
315315
let lltp_ty = type_of::type_of(ccx, tp_ty);
316-
C_uint(ccx, machine::llsize_of_real(ccx, lltp_ty))
316+
C_uint(ccx, machine::llsize_of_alloc(ccx, lltp_ty))
317317
}
318318
(_, "min_align_of") => {
319319
let tp_ty = *substs.types.get(FnSpace, 0);

src/librustc_trans/trans/machine.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ pub fn llsize_of_alloc(cx: &CrateContext, ty: Type) -> llsize {
4343

4444
// Returns, as near as we can figure, the "real" size of a type. As in, the
4545
// bits in this number of bytes actually carry data related to the datum
46-
// with the type. Not junk, padding, accidentally-damaged words, or
47-
// whatever. Rounds up to the nearest byte though, so if you have a 1-bit
46+
// with the type. Not junk, accidentally-damaged words, or whatever.
47+
// Note that padding of the type will be included for structs, but not for the
48+
// other types (i.e. SIMD types).
49+
// Rounds up to the nearest byte though, so if you have a 1-bit
4850
// value, we return 1 here, not 0. Most of rustc works in bytes. Be warned
4951
// that LLVM *does* distinguish between e.g. a 1-bit value and an 8-bit value
5052
// at the codegen level! In general you should prefer `llbitsize_of_real`

src/test/run-pass/simd-size-align.rs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Copyright 2015 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+
#![feature(simd)]
12+
#![allow(non_camel_case_types)]
13+
14+
use std::mem;
15+
16+
/// `T` should satisfy `size_of T (mod min_align_of T) === 0` to be stored at `Vec<T>` properly
17+
/// Please consult the issue #20460
18+
fn check<T>() {
19+
assert_eq!(mem::size_of::<T>() % mem::min_align_of::<T>(), 0)
20+
}
21+
22+
fn main() {
23+
check::<u8x2>();
24+
check::<u8x3>();
25+
check::<u8x4>();
26+
check::<u8x5>();
27+
check::<u8x6>();
28+
check::<u8x7>();
29+
check::<u8x8>();
30+
31+
check::<i16x2>();
32+
check::<i16x3>();
33+
check::<i16x4>();
34+
check::<i16x5>();
35+
check::<i16x6>();
36+
check::<i16x7>();
37+
check::<i16x8>();
38+
39+
check::<f32x2>();
40+
check::<f32x3>();
41+
check::<f32x4>();
42+
check::<f32x5>();
43+
check::<f32x6>();
44+
check::<f32x7>();
45+
check::<f32x8>();
46+
}
47+
48+
#[simd] struct u8x2(u8, u8);
49+
#[simd] struct u8x3(u8, u8, u8);
50+
#[simd] struct u8x4(u8, u8, u8, u8);
51+
#[simd] struct u8x5(u8, u8, u8, u8, u8);
52+
#[simd] struct u8x6(u8, u8, u8, u8, u8, u8);
53+
#[simd] struct u8x7(u8, u8, u8, u8, u8, u8, u8);
54+
#[simd] struct u8x8(u8, u8, u8, u8, u8, u8, u8, u8);
55+
56+
#[simd] struct i16x2(i16, i16);
57+
#[simd] struct i16x3(i16, i16, i16);
58+
#[simd] struct i16x4(i16, i16, i16, i16);
59+
#[simd] struct i16x5(i16, i16, i16, i16, i16);
60+
#[simd] struct i16x6(i16, i16, i16, i16, i16, i16);
61+
#[simd] struct i16x7(i16, i16, i16, i16, i16, i16, i16);
62+
#[simd] struct i16x8(i16, i16, i16, i16, i16, i16, i16, i16);
63+
64+
#[simd] struct f32x2(f32, f32);
65+
#[simd] struct f32x3(f32, f32, f32);
66+
#[simd] struct f32x4(f32, f32, f32, f32);
67+
#[simd] struct f32x5(f32, f32, f32, f32, f32);
68+
#[simd] struct f32x6(f32, f32, f32, f32, f32, f32);
69+
#[simd] struct f32x7(f32, f32, f32, f32, f32, f32, f32);
70+
#[simd] struct f32x8(f32, f32, f32, f32, f32, f32, f32, f32);

0 commit comments

Comments
 (0)