2017-02-06 16:27:09 +00:00
|
|
|
// Copyright 2016 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.
|
|
|
|
|
2018-06-01 17:20:00 +00:00
|
|
|
// ignore-tidy-linelength
|
2017-02-06 16:27:09 +00:00
|
|
|
// compile-flags: -C no-prepopulate-passes
|
2018-06-01 17:20:00 +00:00
|
|
|
// min-llvm-version 7.0
|
2017-02-06 16:27:09 +00:00
|
|
|
|
|
|
|
#![crate_type = "lib"]
|
2018-02-04 11:10:28 +00:00
|
|
|
#![feature(repr_packed)]
|
2017-02-06 16:27:09 +00:00
|
|
|
|
|
|
|
#[repr(packed)]
|
2018-02-04 11:10:28 +00:00
|
|
|
pub struct Packed1 {
|
2017-02-06 16:27:09 +00:00
|
|
|
dealign: u8,
|
|
|
|
data: u32
|
|
|
|
}
|
|
|
|
|
2018-02-04 11:10:28 +00:00
|
|
|
#[repr(packed(2))]
|
|
|
|
pub struct Packed2 {
|
|
|
|
dealign: u8,
|
|
|
|
data: u32
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: @write_pkd1
|
2017-02-06 16:27:09 +00:00
|
|
|
#[no_mangle]
|
2018-02-04 11:10:28 +00:00
|
|
|
pub fn write_pkd1(pkd: &mut Packed1) -> u32 {
|
2017-02-06 16:27:09 +00:00
|
|
|
// CHECK: %{{.*}} = load i32, i32* %{{.*}}, align 1
|
|
|
|
// CHECK: store i32 42, i32* %{{.*}}, align 1
|
|
|
|
let result = pkd.data;
|
|
|
|
pkd.data = 42;
|
|
|
|
result
|
|
|
|
}
|
2017-03-09 11:28:26 +00:00
|
|
|
|
2018-02-04 11:10:28 +00:00
|
|
|
// CHECK-LABEL: @write_pkd2
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn write_pkd2(pkd: &mut Packed2) -> u32 {
|
|
|
|
// CHECK: %{{.*}} = load i32, i32* %{{.*}}, align 2
|
|
|
|
// CHECK: store i32 42, i32* %{{.*}}, align 2
|
|
|
|
let result = pkd.data;
|
|
|
|
pkd.data = 42;
|
|
|
|
result
|
|
|
|
}
|
|
|
|
|
2017-03-09 11:28:26 +00:00
|
|
|
pub struct Array([i32; 8]);
|
|
|
|
#[repr(packed)]
|
2018-02-04 11:10:28 +00:00
|
|
|
pub struct BigPacked1 {
|
|
|
|
dealign: u8,
|
|
|
|
data: Array
|
|
|
|
}
|
|
|
|
|
|
|
|
#[repr(packed(2))]
|
|
|
|
pub struct BigPacked2 {
|
2017-03-09 11:28:26 +00:00
|
|
|
dealign: u8,
|
|
|
|
data: Array
|
|
|
|
}
|
|
|
|
|
2018-02-04 11:10:28 +00:00
|
|
|
// CHECK-LABEL: @call_pkd1
|
2017-03-09 11:28:26 +00:00
|
|
|
#[no_mangle]
|
2018-02-04 11:10:28 +00:00
|
|
|
pub fn call_pkd1(f: fn() -> Array) -> BigPacked1 {
|
2017-03-09 11:28:26 +00:00
|
|
|
// CHECK: [[ALLOCA:%[_a-z0-9]+]] = alloca %Array
|
2017-11-19 10:13:24 +00:00
|
|
|
// CHECK: call void %{{.*}}(%Array* noalias nocapture sret dereferenceable(32) [[ALLOCA]])
|
2018-11-02 22:38:16 +00:00
|
|
|
// CHECK: call void @llvm.memcpy.{{.*}}(i8* align 1 %{{.*}}, i8* align 4 %{{.*}}, i{{[0-9]+}} 32, i1 false)
|
2017-03-09 11:28:26 +00:00
|
|
|
// check that calls whose destination is a field of a packed struct
|
|
|
|
// go through an alloca rather than calling the function with an
|
|
|
|
// unaligned destination.
|
2018-02-04 11:10:28 +00:00
|
|
|
BigPacked1 { dealign: 0, data: f() }
|
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-LABEL: @call_pkd2
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn call_pkd2(f: fn() -> Array) -> BigPacked2 {
|
|
|
|
// CHECK: [[ALLOCA:%[_a-z0-9]+]] = alloca %Array
|
|
|
|
// CHECK: call void %{{.*}}(%Array* noalias nocapture sret dereferenceable(32) [[ALLOCA]])
|
2018-11-02 22:38:16 +00:00
|
|
|
// CHECK: call void @llvm.memcpy.{{.*}}(i8* align 2 %{{.*}}, i8* align 4 %{{.*}}, i{{[0-9]+}} 32, i1 false)
|
2018-02-04 11:10:28 +00:00
|
|
|
// check that calls whose destination is a field of a packed struct
|
|
|
|
// go through an alloca rather than calling the function with an
|
|
|
|
// unaligned destination.
|
|
|
|
BigPacked2 { dealign: 0, data: f() }
|
2017-03-09 11:28:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[repr(packed)]
|
|
|
|
#[derive(Copy, Clone)]
|
2018-02-04 11:10:28 +00:00
|
|
|
pub struct Packed1Pair(u8, u32);
|
2017-03-09 11:28:26 +00:00
|
|
|
|
2018-02-04 11:10:28 +00:00
|
|
|
#[repr(packed(2))]
|
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
pub struct Packed2Pair(u8, u32);
|
|
|
|
|
|
|
|
// CHECK-LABEL: @pkd1_pair
|
2017-03-09 11:28:26 +00:00
|
|
|
#[no_mangle]
|
2018-02-04 11:10:28 +00:00
|
|
|
pub fn pkd1_pair(pair1: &mut Packed1Pair, pair2: &mut Packed1Pair) {
|
2018-06-01 17:20:00 +00:00
|
|
|
// CHECK: call void @llvm.memcpy.{{.*}}(i8* align 1 %{{.*}}, i8* align 1 %{{.*}}, i{{[0-9]+}} 5, i1 false)
|
2017-03-09 11:28:26 +00:00
|
|
|
*pair2 = *pair1;
|
|
|
|
}
|
2017-12-01 16:36:58 +00:00
|
|
|
|
2018-02-04 11:10:28 +00:00
|
|
|
// CHECK-LABEL: @pkd2_pair
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn pkd2_pair(pair1: &mut Packed2Pair, pair2: &mut Packed2Pair) {
|
2018-06-01 17:20:00 +00:00
|
|
|
// CHECK: call void @llvm.memcpy.{{.*}}(i8* align 2 %{{.*}}, i8* align 2 %{{.*}}, i{{[0-9]+}} 6, i1 false)
|
2018-02-04 11:10:28 +00:00
|
|
|
*pair2 = *pair1;
|
|
|
|
}
|
|
|
|
|
2017-12-01 16:36:58 +00:00
|
|
|
#[repr(packed)]
|
|
|
|
#[derive(Copy, Clone)]
|
2018-02-04 11:10:28 +00:00
|
|
|
pub struct Packed1NestedPair((u32, u32));
|
|
|
|
|
|
|
|
#[repr(packed(2))]
|
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
pub struct Packed2NestedPair((u32, u32));
|
2017-12-01 16:36:58 +00:00
|
|
|
|
2018-02-04 11:10:28 +00:00
|
|
|
// CHECK-LABEL: @pkd1_nested_pair
|
2017-12-01 16:36:58 +00:00
|
|
|
#[no_mangle]
|
2018-02-04 11:10:28 +00:00
|
|
|
pub fn pkd1_nested_pair(pair1: &mut Packed1NestedPair, pair2: &mut Packed1NestedPair) {
|
2018-06-01 17:20:00 +00:00
|
|
|
// CHECK: call void @llvm.memcpy.{{.*}}(i8* align 1 %{{.*}}, i8* align 1 %{{.*}}, i{{[0-9]+}} 8, i1 false)
|
2017-12-01 16:36:58 +00:00
|
|
|
*pair2 = *pair1;
|
|
|
|
}
|
2018-02-04 11:10:28 +00:00
|
|
|
|
|
|
|
// CHECK-LABEL: @pkd2_nested_pair
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn pkd2_nested_pair(pair1: &mut Packed2NestedPair, pair2: &mut Packed2NestedPair) {
|
2018-06-01 17:20:00 +00:00
|
|
|
// CHECK: call void @llvm.memcpy.{{.*}}(i8* align 2 %{{.*}}, i8* align 2 %{{.*}}, i{{[0-9]+}} 8, i1 false)
|
2018-02-04 11:10:28 +00:00
|
|
|
*pair2 = *pair1;
|
|
|
|
}
|
|
|
|
|