Skip to content

Commit c4d73a6

Browse files
committed
Fix to 128 bit int unaligned loads
1 parent 82160c4 commit c4d73a6

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/builder.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,9 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
924924
// dereference after a drop, for instance.
925925
// FIXME(antoyo): this check that we don't call get_aligned() a second time on a type.
926926
// Ideally, we shouldn't need to do this check.
927-
let aligned_type = if pointee_ty == self.cx.u128_type || pointee_ty == self.cx.i128_type {
927+
let aligned_type = if (pointee_ty == self.cx.u128_type || pointee_ty == self.cx.i128_type)
928+
&& align == Align::from_bytes(16).unwrap()
929+
{
928930
pointee_ty
929931
} else {
930932
pointee_ty.get_aligned(align.bytes())

tests/run/packed_u128.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Compiler:
2+
//
3+
// Run-time:
4+
// status: 0
5+
6+
#![feature(no_core)]
7+
#![no_std]
8+
#![no_core]
9+
#![no_main]
10+
11+
extern crate mini_core;
12+
use intrinsics::black_box;
13+
use mini_core::*;
14+
#[repr(packed(1))]
15+
pub struct ScalarInt {
16+
data: u128,
17+
size: u8,
18+
}
19+
#[inline(never)]
20+
#[no_mangle]
21+
fn read_data(a: &ScalarInt) {
22+
black_box(a.data);
23+
}
24+
25+
#[no_mangle]
26+
extern "C" fn main(argc: i32, _argv: *const *const u8) -> i32 {
27+
let data =
28+
[black_box(ScalarInt { data: 0, size: 1 }), black_box(ScalarInt { data: 0, size: 1 })];
29+
read_data(&data[1]);
30+
0
31+
}

0 commit comments

Comments
 (0)