Skip to content

Commit 7f5867e

Browse files
committed
Try zero-init for the unaligned block instead of undef
1 parent fb97bb5 commit 7f5867e

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/libcore/ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ unsafe fn swap_nonoverlapping_bytes(x: *mut u8, y: *mut u8, len: usize) {
226226

227227
if i < len {
228228
// Swap any remaining bytes
229-
let mut t: UnalignedBlock = mem::uninitialized();
229+
let mut t = UnalignedBlock(0, 0, 0, 0);
230230
let rem = len - i;
231231

232232
let t = &mut t as *mut _ as *mut u8;

src/test/codegen/swap-small-types.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2018 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+
// compile-flags: -O
12+
13+
#![crate_type = "lib"]
14+
15+
use std::mem::swap;
16+
17+
type RGB48 = [u16; 3];
18+
19+
// CHECK-LABEL: @swap_rgb48
20+
#[no_mangle]
21+
pub fn swap_rgb48(x: &mut RGB48, y: &mut RGB48) {
22+
// CHECK-NOT: alloca
23+
// CHECK: load i48
24+
// CHECK: store i48
25+
swap(x, y)
26+
}

0 commit comments

Comments
 (0)