mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-02 15:32:06 +00:00
Auto merge of #93670 - erikdesjardins:noundef, r=nikic
Apply noundef attribute to &T, &mut T, Box<T>, bool This doesn't handle `char` because it's a bit awkward to distinguish it from `u32` at this point in codegen. Note that this _does not_ change whether or not it is UB for `&`, `&mut`, or `Box` to point to undef. It only applies to the pointer itself, not the pointed-to memory. Fixes (partially) #74378. r? `@nikic` cc `@RalfJung`
This commit is contained in:
commit
5c30d65683
@ -37,7 +37,7 @@ impl ArgAttributeExt for ArgAttribute {
|
|||||||
where
|
where
|
||||||
F: FnMut(llvm::Attribute),
|
F: FnMut(llvm::Attribute),
|
||||||
{
|
{
|
||||||
for_each_kind!(self, f, NoAlias, NoCapture, NonNull, ReadOnly, InReg)
|
for_each_kind!(self, f, NoAlias, NoCapture, NonNull, ReadOnly, InReg, NoUndef)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,6 +189,7 @@ pub enum Attribute {
|
|||||||
StackProtectReq = 30,
|
StackProtectReq = 30,
|
||||||
StackProtectStrong = 31,
|
StackProtectStrong = 31,
|
||||||
StackProtect = 32,
|
StackProtect = 32,
|
||||||
|
NoUndef = 33,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// LLVMIntPredicate
|
/// LLVMIntPredicate
|
||||||
|
@ -82,6 +82,7 @@ enum LLVMRustAttribute {
|
|||||||
StackProtectReq = 30,
|
StackProtectReq = 30,
|
||||||
StackProtectStrong = 31,
|
StackProtectStrong = 31,
|
||||||
StackProtect = 32,
|
StackProtect = 32,
|
||||||
|
NoUndef = 33,
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct OpaqueRustString *RustStringRef;
|
typedef struct OpaqueRustString *RustStringRef;
|
||||||
|
@ -224,6 +224,8 @@ static Attribute::AttrKind fromRust(LLVMRustAttribute Kind) {
|
|||||||
return Attribute::StackProtectStrong;
|
return Attribute::StackProtectStrong;
|
||||||
case StackProtect:
|
case StackProtect:
|
||||||
return Attribute::StackProtect;
|
return Attribute::StackProtect;
|
||||||
|
case NoUndef:
|
||||||
|
return Attribute::NoUndef;
|
||||||
}
|
}
|
||||||
report_fatal_error("bad AttributeKind");
|
report_fatal_error("bad AttributeKind");
|
||||||
}
|
}
|
||||||
|
@ -3051,9 +3051,10 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
|||||||
layout: TyAndLayout<'tcx>,
|
layout: TyAndLayout<'tcx>,
|
||||||
offset: Size,
|
offset: Size,
|
||||||
is_return: bool| {
|
is_return: bool| {
|
||||||
// Booleans are always an i1 that needs to be zero-extended.
|
// Booleans are always a noundef i1 that needs to be zero-extended.
|
||||||
if scalar.is_bool() {
|
if scalar.is_bool() {
|
||||||
attrs.ext(ArgExtension::Zext);
|
attrs.ext(ArgExtension::Zext);
|
||||||
|
attrs.set(ArgAttribute::NoUndef);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3078,6 +3079,11 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
|||||||
_ => pointee.size,
|
_ => pointee.size,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// `Box`, `&T`, and `&mut T` cannot be undef.
|
||||||
|
// Note that this only applies to the value of the pointer itself;
|
||||||
|
// this attribute doesn't make it UB for the pointed-to data to be undef.
|
||||||
|
attrs.set(ArgAttribute::NoUndef);
|
||||||
|
|
||||||
// `Box` pointer parameters never alias because ownership is transferred
|
// `Box` pointer parameters never alias because ownership is transferred
|
||||||
// `&mut` pointer parameters never alias other parameters,
|
// `&mut` pointer parameters never alias other parameters,
|
||||||
// or mutable global data
|
// or mutable global data
|
||||||
|
@ -74,6 +74,7 @@ mod attr_impl {
|
|||||||
// or not to actually emit the attribute. It can also be controlled
|
// or not to actually emit the attribute. It can also be controlled
|
||||||
// with the `-Zmutable-noalias` debugging option.
|
// with the `-Zmutable-noalias` debugging option.
|
||||||
const NoAliasMutRef = 1 << 6;
|
const NoAliasMutRef = 1 << 6;
|
||||||
|
const NoUndef = 1 << 7;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -495,7 +496,11 @@ impl<'a, Ty> ArgAbi<'a, Ty> {
|
|||||||
// For non-immediate arguments the callee gets its own copy of
|
// For non-immediate arguments the callee gets its own copy of
|
||||||
// the value on the stack, so there are no aliases. It's also
|
// the value on the stack, so there are no aliases. It's also
|
||||||
// program-invisible so can't possibly capture
|
// program-invisible so can't possibly capture
|
||||||
attrs.set(ArgAttribute::NoAlias).set(ArgAttribute::NoCapture).set(ArgAttribute::NonNull);
|
attrs
|
||||||
|
.set(ArgAttribute::NoAlias)
|
||||||
|
.set(ArgAttribute::NoCapture)
|
||||||
|
.set(ArgAttribute::NonNull)
|
||||||
|
.set(ArgAttribute::NoUndef);
|
||||||
attrs.pointee_size = layout.size;
|
attrs.pointee_size = layout.size;
|
||||||
// FIXME(eddyb) We should be doing this, but at least on
|
// FIXME(eddyb) We should be doing this, but at least on
|
||||||
// i686-pc-windows-msvc, it results in wrong stack offsets.
|
// i686-pc-windows-msvc, it results in wrong stack offsets.
|
||||||
|
@ -2,52 +2,17 @@
|
|||||||
// as "inreg" like the C/C++ compilers for the platforms.
|
// as "inreg" like the C/C++ compilers for the platforms.
|
||||||
// x86 only.
|
// x86 only.
|
||||||
|
|
||||||
// ignore-aarch64
|
// compile-flags: --target i686-unknown-linux-gnu -C no-prepopulate-passes
|
||||||
// ignore-aarch64_be
|
// needs-llvm-components: x86
|
||||||
// ignore-arm
|
|
||||||
// ignore-armeb
|
|
||||||
// ignore-avr
|
|
||||||
// ignore-bpfel
|
|
||||||
// ignore-bpfeb
|
|
||||||
// ignore-hexagon
|
|
||||||
// ignore-mips
|
|
||||||
// ignore-mips64
|
|
||||||
// ignore-msp430
|
|
||||||
// ignore-powerpc64
|
|
||||||
// ignore-powerpc64le
|
|
||||||
// ignore-powerpc
|
|
||||||
// ignore-r600
|
|
||||||
// ignore-riscv64
|
|
||||||
// ignore-amdgcn
|
|
||||||
// ignore-sparc
|
|
||||||
// ignore-sparc64
|
|
||||||
// ignore-sparcv9
|
|
||||||
// ignore-sparcel
|
|
||||||
// ignore-s390x
|
|
||||||
// ignore-tce
|
|
||||||
// ignore-thumb
|
|
||||||
// ignore-thumbeb
|
|
||||||
// ignore-x86_64
|
|
||||||
// ignore-xcore
|
|
||||||
// ignore-nvptx
|
|
||||||
// ignore-nvptx64
|
|
||||||
// ignore-le32
|
|
||||||
// ignore-le64
|
|
||||||
// ignore-amdil
|
|
||||||
// ignore-amdil64
|
|
||||||
// ignore-hsail
|
|
||||||
// ignore-hsail64
|
|
||||||
// ignore-spir
|
|
||||||
// ignore-spir64
|
|
||||||
// ignore-kalimba
|
|
||||||
// ignore-shave
|
|
||||||
// ignore-wasm32
|
|
||||||
// ignore-wasm64
|
|
||||||
// ignore-emscripten
|
|
||||||
|
|
||||||
// compile-flags: -C no-prepopulate-passes
|
|
||||||
|
|
||||||
#![crate_type = "lib"]
|
#![crate_type = "lib"]
|
||||||
|
#![no_core]
|
||||||
|
#![feature(no_core, lang_items)]
|
||||||
|
|
||||||
|
#[lang = "sized"]
|
||||||
|
trait Sized {}
|
||||||
|
#[lang = "copy"]
|
||||||
|
trait Copy {}
|
||||||
|
|
||||||
pub mod tests {
|
pub mod tests {
|
||||||
// CHECK: @f1(i32 inreg %_1, i32 inreg %_2, i32 %_3)
|
// CHECK: @f1(i32 inreg %_1, i32 inreg %_2, i32 %_3)
|
||||||
@ -70,7 +35,7 @@ pub mod tests {
|
|||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "fastcall" fn f5(_: i64, _: i32) {}
|
pub extern "fastcall" fn f5(_: i64, _: i32) {}
|
||||||
|
|
||||||
// CHECK: @f6(i1 inreg zeroext %_1, i32 inreg %_2, i32 %_3)
|
// CHECK: @f6(i1 inreg noundef zeroext %_1, i32 inreg %_2, i32 %_3)
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "fastcall" fn f6(_: bool, _: i32, _: i32) {}
|
pub extern "fastcall" fn f6(_: bool, _: i32, _: i32) {}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
#![crate_type = "lib"]
|
#![crate_type = "lib"]
|
||||||
#![feature(rustc_attrs)]
|
#![feature(rustc_attrs)]
|
||||||
|
|
||||||
|
use std::mem::MaybeUninit;
|
||||||
|
|
||||||
pub struct S {
|
pub struct S {
|
||||||
_field: [i32; 8],
|
_field: [i32; 8],
|
||||||
}
|
}
|
||||||
@ -11,68 +13,79 @@ pub struct UnsafeInner {
|
|||||||
_field: std::cell::UnsafeCell<i16>,
|
_field: std::cell::UnsafeCell<i16>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// CHECK: zeroext i1 @boolean(i1 zeroext %x)
|
// CHECK: noundef zeroext i1 @boolean(i1 noundef zeroext %x)
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn boolean(x: bool) -> bool {
|
pub fn boolean(x: bool) -> bool {
|
||||||
x
|
x
|
||||||
}
|
}
|
||||||
|
|
||||||
// CHECK: @readonly_borrow(i32* noalias readonly align 4 dereferenceable(4) %_1)
|
// CHECK: i8 @maybeuninit_boolean(i8 %x)
|
||||||
|
#[no_mangle]
|
||||||
|
pub fn maybeuninit_boolean(x: MaybeUninit<bool>) -> MaybeUninit<bool> {
|
||||||
|
x
|
||||||
|
}
|
||||||
|
|
||||||
|
// CHECK: @readonly_borrow(i32* noalias noundef readonly align 4 dereferenceable(4) %_1)
|
||||||
// FIXME #25759 This should also have `nocapture`
|
// FIXME #25759 This should also have `nocapture`
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn readonly_borrow(_: &i32) {
|
pub fn readonly_borrow(_: &i32) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CHECK: @static_borrow(i32* noalias readonly align 4 dereferenceable(4) %_1)
|
// CHECK: @static_borrow(i32* noalias noundef readonly align 4 dereferenceable(4) %_1)
|
||||||
// static borrow may be captured
|
// static borrow may be captured
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn static_borrow(_: &'static i32) {
|
pub fn static_borrow(_: &'static i32) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CHECK: @named_borrow(i32* noalias readonly align 4 dereferenceable(4) %_1)
|
// CHECK: @named_borrow(i32* noalias noundef readonly align 4 dereferenceable(4) %_1)
|
||||||
// borrow with named lifetime may be captured
|
// borrow with named lifetime may be captured
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn named_borrow<'r>(_: &'r i32) {
|
pub fn named_borrow<'r>(_: &'r i32) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CHECK: @unsafe_borrow(i16* align 2 dereferenceable(2) %_1)
|
// CHECK: @unsafe_borrow(i16* noundef align 2 dereferenceable(2) %_1)
|
||||||
// unsafe interior means this isn't actually readonly and there may be aliases ...
|
// unsafe interior means this isn't actually readonly and there may be aliases ...
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn unsafe_borrow(_: &UnsafeInner) {
|
pub fn unsafe_borrow(_: &UnsafeInner) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CHECK: @mutable_unsafe_borrow(i16* noalias align 2 dereferenceable(2) %_1)
|
// CHECK: @mutable_unsafe_borrow(i16* noalias noundef align 2 dereferenceable(2) %_1)
|
||||||
// ... unless this is a mutable borrow, those never alias
|
// ... unless this is a mutable borrow, those never alias
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn mutable_unsafe_borrow(_: &mut UnsafeInner) {
|
pub fn mutable_unsafe_borrow(_: &mut UnsafeInner) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CHECK: @mutable_borrow(i32* noalias align 4 dereferenceable(4) %_1)
|
// CHECK: @mutable_borrow(i32* noalias noundef align 4 dereferenceable(4) %_1)
|
||||||
// FIXME #25759 This should also have `nocapture`
|
// FIXME #25759 This should also have `nocapture`
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn mutable_borrow(_: &mut i32) {
|
pub fn mutable_borrow(_: &mut i32) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CHECK: @indirect_struct(%S* noalias nocapture dereferenceable(32) %_1)
|
// CHECK: @indirect_struct(%S* noalias nocapture noundef dereferenceable(32) %_1)
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn indirect_struct(_: S) {
|
pub fn indirect_struct(_: S) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CHECK: @borrowed_struct(%S* noalias readonly align 4 dereferenceable(32) %_1)
|
// CHECK: @borrowed_struct(%S* noalias noundef readonly align 4 dereferenceable(32) %_1)
|
||||||
// FIXME #25759 This should also have `nocapture`
|
// FIXME #25759 This should also have `nocapture`
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn borrowed_struct(_: &S) {
|
pub fn borrowed_struct(_: &S) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CHECK: @raw_struct(%S* %_1)
|
||||||
|
#[no_mangle]
|
||||||
|
pub fn raw_struct(_: *const S) {
|
||||||
|
}
|
||||||
|
|
||||||
// `Box` can get deallocated during execution of the function, so it should
|
// `Box` can get deallocated during execution of the function, so it should
|
||||||
// not get `dereferenceable`.
|
// not get `dereferenceable`.
|
||||||
// CHECK: noalias nonnull align 4 i32* @_box(i32* noalias nonnull align 4 %x)
|
// CHECK: noalias noundef nonnull align 4 i32* @_box(i32* noalias noundef nonnull align 4 %x)
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn _box(x: Box<i32>) -> Box<i32> {
|
pub fn _box(x: Box<i32>) -> Box<i32> {
|
||||||
x
|
x
|
||||||
}
|
}
|
||||||
|
|
||||||
// CHECK: @struct_return(%S* noalias nocapture sret(%S) dereferenceable(32){{( %0)?}})
|
// CHECK: @struct_return(%S* noalias nocapture noundef sret(%S) dereferenceable(32){{( %0)?}})
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn struct_return() -> S {
|
pub fn struct_return() -> S {
|
||||||
S {
|
S {
|
||||||
@ -86,48 +99,58 @@ pub fn struct_return() -> S {
|
|||||||
pub fn helper(_: usize) {
|
pub fn helper(_: usize) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CHECK: @slice([0 x i8]* noalias nonnull readonly align 1 %_1.0, [[USIZE]] %_1.1)
|
// CHECK: @slice([0 x i8]* noalias noundef nonnull readonly align 1 %_1.0, [[USIZE]] %_1.1)
|
||||||
// FIXME #25759 This should also have `nocapture`
|
// FIXME #25759 This should also have `nocapture`
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn slice(_: &[u8]) {
|
pub fn slice(_: &[u8]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CHECK: @mutable_slice([0 x i8]* noalias nonnull align 1 %_1.0, [[USIZE]] %_1.1)
|
// CHECK: @mutable_slice([0 x i8]* noalias noundef nonnull align 1 %_1.0, [[USIZE]] %_1.1)
|
||||||
// FIXME #25759 This should also have `nocapture`
|
// FIXME #25759 This should also have `nocapture`
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn mutable_slice(_: &mut [u8]) {
|
pub fn mutable_slice(_: &mut [u8]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CHECK: @unsafe_slice([0 x i16]* nonnull align 2 %_1.0, [[USIZE]] %_1.1)
|
// CHECK: @unsafe_slice([0 x i16]* noundef nonnull align 2 %_1.0, [[USIZE]] %_1.1)
|
||||||
// unsafe interior means this isn't actually readonly and there may be aliases ...
|
// unsafe interior means this isn't actually readonly and there may be aliases ...
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn unsafe_slice(_: &[UnsafeInner]) {
|
pub fn unsafe_slice(_: &[UnsafeInner]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CHECK: @str([0 x i8]* noalias nonnull readonly align 1 %_1.0, [[USIZE]] %_1.1)
|
// CHECK: @raw_slice([0 x i8]* %_1.0, [[USIZE]] %_1.1)
|
||||||
|
#[no_mangle]
|
||||||
|
pub fn raw_slice(_: *const [u8]) {
|
||||||
|
}
|
||||||
|
|
||||||
|
// CHECK: @str([0 x i8]* noalias noundef nonnull readonly align 1 %_1.0, [[USIZE]] %_1.1)
|
||||||
// FIXME #25759 This should also have `nocapture`
|
// FIXME #25759 This should also have `nocapture`
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn str(_: &[u8]) {
|
pub fn str(_: &[u8]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CHECK: @trait_borrow({}* nonnull align 1 %_1.0, [3 x [[USIZE]]]* noalias readonly align {{.*}} dereferenceable({{.*}}) %_1.1)
|
// CHECK: @trait_borrow({}* noundef nonnull align 1 %_1.0, [3 x [[USIZE]]]* noalias noundef readonly align {{.*}} dereferenceable({{.*}}) %_1.1)
|
||||||
// FIXME #25759 This should also have `nocapture`
|
// FIXME #25759 This should also have `nocapture`
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn trait_borrow(_: &Drop) {
|
pub fn trait_borrow(_: &Drop) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CHECK: @trait_box({}* noalias nonnull align 1{{( %0)?}}, [3 x [[USIZE]]]* noalias readonly align {{.*}} dereferenceable({{.*}}){{( %1)?}})
|
// CHECK: @trait_raw({}* %_1.0, [3 x [[USIZE]]]* noalias noundef readonly align {{.*}} dereferenceable({{.*}}) %_1.1)
|
||||||
|
#[no_mangle]
|
||||||
|
pub fn trait_raw(_: *const Drop) {
|
||||||
|
}
|
||||||
|
|
||||||
|
// CHECK: @trait_box({}* noalias noundef nonnull align 1{{( %0)?}}, [3 x [[USIZE]]]* noalias noundef readonly align {{.*}} dereferenceable({{.*}}){{( %1)?}})
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn trait_box(_: Box<Drop>) {
|
pub fn trait_box(_: Box<Drop>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CHECK: { i8*, i8* } @trait_option(i8* noalias align 1 %x.0, i8* %x.1)
|
// CHECK: { i8*, i8* } @trait_option(i8* noalias noundef align 1 %x.0, i8* %x.1)
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn trait_option(x: Option<Box<Drop>>) -> Option<Box<Drop>> {
|
pub fn trait_option(x: Option<Box<Drop>>) -> Option<Box<Drop>> {
|
||||||
x
|
x
|
||||||
}
|
}
|
||||||
|
|
||||||
// CHECK: { [0 x i16]*, [[USIZE]] } @return_slice([0 x i16]* noalias nonnull readonly align 2 %x.0, [[USIZE]] %x.1)
|
// CHECK: { [0 x i16]*, [[USIZE]] } @return_slice([0 x i16]* noalias noundef nonnull readonly align 2 %x.0, [[USIZE]] %x.1)
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn return_slice(x: &[u16]) -> &[u16] {
|
pub fn return_slice(x: &[u16]) -> &[u16] {
|
||||||
x
|
x
|
||||||
@ -139,7 +162,7 @@ pub fn enum_id_1(x: Option<Result<u16, u16>>) -> Option<Result<u16, u16>> {
|
|||||||
x
|
x
|
||||||
}
|
}
|
||||||
|
|
||||||
// CHECK: { i8, i8 } @enum_id_2(i1 zeroext %x.0, i8 %x.1)
|
// CHECK: { i8, i8 } @enum_id_2(i1 noundef zeroext %x.0, i8 %x.1)
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn enum_id_2(x: Option<u8>) -> Option<u8> {
|
pub fn enum_id_2(x: Option<u8>) -> Option<u8> {
|
||||||
x
|
x
|
||||||
|
@ -52,7 +52,7 @@ pub struct BigPacked2 {
|
|||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn call_pkd1(f: fn() -> Array) -> BigPacked1 {
|
pub fn call_pkd1(f: fn() -> Array) -> BigPacked1 {
|
||||||
// CHECK: [[ALLOCA:%[_a-z0-9]+]] = alloca %Array
|
// CHECK: [[ALLOCA:%[_a-z0-9]+]] = alloca %Array
|
||||||
// CHECK: call void %{{.*}}(%Array* noalias nocapture sret{{.*}} dereferenceable(32) [[ALLOCA]])
|
// CHECK: call void %{{.*}}(%Array* noalias nocapture noundef sret{{.*}} dereferenceable(32) [[ALLOCA]])
|
||||||
// CHECK: call void @llvm.memcpy.{{.*}}(i8* align 1 %{{.*}}, i8* align 4 %{{.*}}, i{{[0-9]+}} 32, i1 false)
|
// CHECK: call void @llvm.memcpy.{{.*}}(i8* align 1 %{{.*}}, i8* align 4 %{{.*}}, i{{[0-9]+}} 32, i1 false)
|
||||||
// check that calls whose destination is a field of a packed struct
|
// check that calls whose destination is a field of a packed struct
|
||||||
// go through an alloca rather than calling the function with an
|
// go through an alloca rather than calling the function with an
|
||||||
@ -64,7 +64,7 @@ pub fn call_pkd1(f: fn() -> Array) -> BigPacked1 {
|
|||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn call_pkd2(f: fn() -> Array) -> BigPacked2 {
|
pub fn call_pkd2(f: fn() -> Array) -> BigPacked2 {
|
||||||
// CHECK: [[ALLOCA:%[_a-z0-9]+]] = alloca %Array
|
// CHECK: [[ALLOCA:%[_a-z0-9]+]] = alloca %Array
|
||||||
// CHECK: call void %{{.*}}(%Array* noalias nocapture sret{{.*}} dereferenceable(32) [[ALLOCA]])
|
// CHECK: call void %{{.*}}(%Array* noalias nocapture noundef sret{{.*}} dereferenceable(32) [[ALLOCA]])
|
||||||
// CHECK: call void @llvm.memcpy.{{.*}}(i8* align 2 %{{.*}}, i8* align 4 %{{.*}}, i{{[0-9]+}} 32, i1 false)
|
// CHECK: call void @llvm.memcpy.{{.*}}(i8* align 2 %{{.*}}, i8* align 4 %{{.*}}, i{{[0-9]+}} 32, i1 false)
|
||||||
// check that calls whose destination is a field of a packed struct
|
// check that calls whose destination is a field of a packed struct
|
||||||
// go through an alloca rather than calling the function with an
|
// go through an alloca rather than calling the function with an
|
||||||
|
@ -1,15 +1,21 @@
|
|||||||
//
|
// compile-flags: --target riscv64gc-unknown-linux-gnu -C no-prepopulate-passes
|
||||||
// compile-flags: -C no-prepopulate-passes
|
// needs-llvm-components: riscv
|
||||||
// only-riscv64
|
|
||||||
// only-linux
|
|
||||||
#![crate_type = "lib"]
|
#![crate_type = "lib"]
|
||||||
|
#![no_core]
|
||||||
|
#![feature(no_core, lang_items)]
|
||||||
#![allow(improper_ctypes)]
|
#![allow(improper_ctypes)]
|
||||||
|
|
||||||
|
#[lang = "sized"]
|
||||||
|
trait Sized {}
|
||||||
|
#[lang = "copy"]
|
||||||
|
trait Copy {}
|
||||||
|
|
||||||
// CHECK: define void @f_void()
|
// CHECK: define void @f_void()
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn f_void() {}
|
pub extern "C" fn f_void() {}
|
||||||
|
|
||||||
// CHECK: define zeroext i1 @f_scalar_0(i1 zeroext %a)
|
// CHECK: define noundef zeroext i1 @f_scalar_0(i1 noundef zeroext %a)
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn f_scalar_0(a: bool) -> bool {
|
pub extern "C" fn f_scalar_0(a: bool) -> bool {
|
||||||
a
|
a
|
||||||
@ -70,8 +76,6 @@ pub struct Tiny {
|
|||||||
// CHECK: define void @f_agg_tiny(i64 %0)
|
// CHECK: define void @f_agg_tiny(i64 %0)
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn f_agg_tiny(mut e: Tiny) {
|
pub extern "C" fn f_agg_tiny(mut e: Tiny) {
|
||||||
e.a += e.b;
|
|
||||||
e.c += e.d;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CHECK: define i64 @f_agg_tiny_ret()
|
// CHECK: define i64 @f_agg_tiny_ret()
|
||||||
@ -89,14 +93,12 @@ pub struct Small {
|
|||||||
// CHECK: define void @f_agg_small([2 x i64] %0)
|
// CHECK: define void @f_agg_small([2 x i64] %0)
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn f_agg_small(mut x: Small) {
|
pub extern "C" fn f_agg_small(mut x: Small) {
|
||||||
x.a += unsafe { *x.b };
|
|
||||||
x.b = &mut x.a;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CHECK: define [2 x i64] @f_agg_small_ret()
|
// CHECK: define [2 x i64] @f_agg_small_ret()
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn f_agg_small_ret() -> Small {
|
pub extern "C" fn f_agg_small_ret() -> Small {
|
||||||
Small { a: 1, b: core::ptr::null_mut() }
|
Small { a: 1, b: 0 as *mut _ }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
@ -107,7 +109,6 @@ pub struct SmallAligned {
|
|||||||
// CHECK: define void @f_agg_small_aligned(i128 %0)
|
// CHECK: define void @f_agg_small_aligned(i128 %0)
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn f_agg_small_aligned(mut x: SmallAligned) {
|
pub extern "C" fn f_agg_small_aligned(mut x: SmallAligned) {
|
||||||
x.a += x.a;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
@ -121,7 +122,6 @@ pub struct Large {
|
|||||||
// CHECK: define void @f_agg_large(%Large* {{.*}}%x)
|
// CHECK: define void @f_agg_large(%Large* {{.*}}%x)
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn f_agg_large(mut x: Large) {
|
pub extern "C" fn f_agg_large(mut x: Large) {
|
||||||
x.a = x.b + x.c + x.d;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CHECK: define void @f_agg_large_ret(%Large* {{.*}}sret{{.*}}, i32 signext %i, i8 signext %j)
|
// CHECK: define void @f_agg_large_ret(%Large* {{.*}}sret{{.*}}, i32 signext %i, i8 signext %j)
|
||||||
@ -172,7 +172,7 @@ pub unsafe extern "C" fn f_va_caller() {
|
|||||||
4.0f64,
|
4.0f64,
|
||||||
5.0f64,
|
5.0f64,
|
||||||
Tiny { a: 1, b: 2, c: 3, d: 4 },
|
Tiny { a: 1, b: 2, c: 3, d: 4 },
|
||||||
Small { a: 10, b: core::ptr::null_mut() },
|
Small { a: 10, b: 0 as *mut _ },
|
||||||
SmallAligned { a: 11 },
|
SmallAligned { a: 11 },
|
||||||
Large { a: 12, b: 13, c: 14, d: 15 },
|
Large { a: 12, b: 13, c: 14, d: 15 },
|
||||||
);
|
);
|
||||||
|
@ -2,25 +2,25 @@
|
|||||||
|
|
||||||
#![crate_type = "lib"]
|
#![crate_type = "lib"]
|
||||||
|
|
||||||
// CHECK: define{{.*}}{ i8, i8 } @pair_bool_bool(i1 zeroext %pair.0, i1 zeroext %pair.1)
|
// CHECK: define{{.*}}{ i8, i8 } @pair_bool_bool(i1 noundef zeroext %pair.0, i1 noundef zeroext %pair.1)
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn pair_bool_bool(pair: (bool, bool)) -> (bool, bool) {
|
pub fn pair_bool_bool(pair: (bool, bool)) -> (bool, bool) {
|
||||||
pair
|
pair
|
||||||
}
|
}
|
||||||
|
|
||||||
// CHECK: define{{.*}}{ i8, i32 } @pair_bool_i32(i1 zeroext %pair.0, i32 %pair.1)
|
// CHECK: define{{.*}}{ i8, i32 } @pair_bool_i32(i1 noundef zeroext %pair.0, i32 %pair.1)
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn pair_bool_i32(pair: (bool, i32)) -> (bool, i32) {
|
pub fn pair_bool_i32(pair: (bool, i32)) -> (bool, i32) {
|
||||||
pair
|
pair
|
||||||
}
|
}
|
||||||
|
|
||||||
// CHECK: define{{.*}}{ i32, i8 } @pair_i32_bool(i32 %pair.0, i1 zeroext %pair.1)
|
// CHECK: define{{.*}}{ i32, i8 } @pair_i32_bool(i32 %pair.0, i1 noundef zeroext %pair.1)
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn pair_i32_bool(pair: (i32, bool)) -> (i32, bool) {
|
pub fn pair_i32_bool(pair: (i32, bool)) -> (i32, bool) {
|
||||||
pair
|
pair
|
||||||
}
|
}
|
||||||
|
|
||||||
// CHECK: define{{.*}}{ i8, i8 } @pair_and_or(i1 zeroext %_1.0, i1 zeroext %_1.1)
|
// CHECK: define{{.*}}{ i8, i8 } @pair_and_or(i1 noundef zeroext %_1.0, i1 noundef zeroext %_1.1)
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn pair_and_or((a, b): (bool, bool)) -> (bool, bool) {
|
pub fn pair_and_or((a, b): (bool, bool)) -> (bool, bool) {
|
||||||
// Make sure it can operate directly on the unpacked args
|
// Make sure it can operate directly on the unpacked args
|
||||||
@ -30,7 +30,7 @@ pub fn pair_and_or((a, b): (bool, bool)) -> (bool, bool) {
|
|||||||
(a && b, a || b)
|
(a && b, a || b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CHECK: define{{.*}}void @pair_branches(i1 zeroext %_1.0, i1 zeroext %_1.1)
|
// CHECK: define{{.*}}void @pair_branches(i1 noundef zeroext %_1.0, i1 noundef zeroext %_1.1)
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn pair_branches((a, b): (bool, bool)) {
|
pub fn pair_branches((a, b): (bool, bool)) {
|
||||||
// Make sure it can branch directly on the unpacked bool args
|
// Make sure it can branch directly on the unpacked bool args
|
||||||
|
@ -15,7 +15,7 @@ pub fn f32_to_bits(x: f32) -> u32 {
|
|||||||
unsafe { std::mem::transmute(x) }
|
unsafe { std::mem::transmute(x) }
|
||||||
}
|
}
|
||||||
|
|
||||||
// CHECK-LABEL: define{{.*}}i8 @bool_to_byte(i1 zeroext %b)
|
// CHECK-LABEL: define{{.*}}i8 @bool_to_byte(i1 noundef zeroext %b)
|
||||||
// CHECK: %1 = zext i1 %b to i8
|
// CHECK: %1 = zext i1 %b to i8
|
||||||
// CHECK-NEXT: store i8 %1, i8* %0
|
// CHECK-NEXT: store i8 %1, i8* %0
|
||||||
// CHECK-NEXT: %2 = load i8, i8* %0
|
// CHECK-NEXT: %2 = load i8, i8* %0
|
||||||
@ -25,7 +25,7 @@ pub fn bool_to_byte(b: bool) -> u8 {
|
|||||||
unsafe { std::mem::transmute(b) }
|
unsafe { std::mem::transmute(b) }
|
||||||
}
|
}
|
||||||
|
|
||||||
// CHECK-LABEL: define{{.*}}zeroext i1 @byte_to_bool(i8 %byte)
|
// CHECK-LABEL: define{{.*}}noundef zeroext i1 @byte_to_bool(i8 %byte)
|
||||||
// CHECK: %1 = trunc i8 %byte to i1
|
// CHECK: %1 = trunc i8 %byte to i1
|
||||||
// CHECK-NEXT: %2 = zext i1 %1 to i8
|
// CHECK-NEXT: %2 = zext i1 %1 to i8
|
||||||
// CHECK-NEXT: store i8 %2, i8* %0
|
// CHECK-NEXT: store i8 %2, i8* %0
|
||||||
|
@ -75,7 +75,7 @@ pub union CUnionU128x2{a:(u128, u128)}
|
|||||||
pub fn test_CUnionU128x2(_: CUnionU128x2) { loop {} }
|
pub fn test_CUnionU128x2(_: CUnionU128x2) { loop {} }
|
||||||
|
|
||||||
pub union UnionBool { b:bool }
|
pub union UnionBool { b:bool }
|
||||||
// CHECK: define zeroext i1 @test_UnionBool(i8 %b)
|
// CHECK: define noundef zeroext i1 @test_UnionBool(i8 %b)
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub fn test_UnionBool(b: UnionBool) -> bool { unsafe { b.b } }
|
pub fn test_UnionBool(b: UnionBool) -> bool { unsafe { b.b } }
|
||||||
// CHECK: %0 = trunc i8 %b to i1
|
// CHECK: %0 = trunc i8 %b to i1
|
||||||
|
Loading…
Reference in New Issue
Block a user