From a4b7ed7a42c716ab9f05e351f003d589124fd55d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:18:58 +0200 Subject: Adding upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- tests/codegen/dst-vtable-align-nonzero.rs | 61 +++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 tests/codegen/dst-vtable-align-nonzero.rs (limited to 'tests/codegen/dst-vtable-align-nonzero.rs') diff --git a/tests/codegen/dst-vtable-align-nonzero.rs b/tests/codegen/dst-vtable-align-nonzero.rs new file mode 100644 index 000000000..54f6e7f99 --- /dev/null +++ b/tests/codegen/dst-vtable-align-nonzero.rs @@ -0,0 +1,61 @@ +// compile-flags: -O -Z merge-functions=disabled + +#![crate_type = "lib"] +#![feature(core_intrinsics)] + +// This test checks that we annotate alignment loads from vtables with nonzero range metadata, +// and that this allows LLVM to eliminate redundant `align >= 1` checks. + +pub trait Trait { + fn f(&self); +} + +pub struct WrapperWithAlign1 { x: u8, y: T } + +pub struct WrapperWithAlign2 { x: u16, y: T } + +pub struct Struct { + _field: i8, + dst: W, +} + +// CHECK-LABEL: @eliminates_runtime_check_when_align_1 +#[no_mangle] +pub fn eliminates_runtime_check_when_align_1( + x: &Struct> +) -> &WrapperWithAlign1 { + // CHECK: load [[USIZE:i[0-9]+]], {{.+}} !range [[RANGE_META:![0-9]+]] + // CHECK-NOT: llvm.umax + // CHECK-NOT: icmp + // CHECK-NOT: select + // CHECK: ret + &x.dst +} + +// CHECK-LABEL: @does_not_eliminate_runtime_check_when_align_2 +#[no_mangle] +pub fn does_not_eliminate_runtime_check_when_align_2( + x: &Struct> +) -> &WrapperWithAlign2 { + // CHECK: [[X0:%[0-9]+]] = load [[USIZE]], {{.+}} !range [[RANGE_META]] + // CHECK: {{icmp|llvm.umax}} + // CHECK: ret + &x.dst +} + +// CHECK-LABEL: @align_load_from_align_of_val +#[no_mangle] +pub fn align_load_from_align_of_val(x: &dyn Trait) -> usize { + // CHECK: {{%[0-9]+}} = load [[USIZE]], {{.+}} !range [[RANGE_META]] + core::mem::align_of_val(x) +} + +// CHECK-LABEL: @align_load_from_vtable_align_intrinsic +#[no_mangle] +pub unsafe fn align_load_from_vtable_align_intrinsic(x: &dyn Trait) -> usize { + let (data, vtable): (*const (), *const ()) = core::mem::transmute(x); + // CHECK: {{%[0-9]+}} = load [[USIZE]], {{.+}} !range [[RANGE_META]] + core::intrinsics::vtable_align(vtable) +} + +// CHECK: [[RANGE_META]] = !{[[USIZE]] 1, [[USIZE]] 0} -- cgit v1.2.3