Skip to content

Rollup of 4 pull requests #116924

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 28 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
316c9a9
Add stack-protector test for Windows
wesleywiser Sep 19, 2023
dfadd17
Make TCP connect() handle EINTR correctly
darthunix Oct 5, 2023
786834d
Allow to run filecheck in mir-opt tests.
cjgillot Oct 16, 2023
5175e1c
Run filecheck on reference_prop.rs
cjgillot Oct 16, 2023
64103d7
FileCheck array_index_is_temporary.rs
cjgillot Oct 16, 2023
4c3dfb8
FileCheck asm_unwind_panic_abort.rs
cjgillot Oct 16, 2023
3e9fa2d
FileCheck basic_assignment.rs.
cjgillot Oct 16, 2023
cc03573
FileCheck box_expr.rs
cjgillot Oct 16, 2023
9db3aeb
Add README.
cjgillot Oct 16, 2023
8b500db
FileCheck combine_array_len.
cjgillot Oct 16, 2023
c65e373
FileCheck bool_compare.
cjgillot Oct 16, 2023
2f599af
FileCheck combine_clone_of_primitives.
cjgillot Oct 16, 2023
a293463
FileCheck intrinsic_asserts.
cjgillot Oct 16, 2023
75081b7
FileCheck duplicate_switch_targets.
cjgillot Oct 16, 2023
3417fe2
FileCheck combine_transmutes.
cjgillot Oct 16, 2023
98312ea
FileCheck casts.
cjgillot Oct 16, 2023
f77a3ef
FileCheck lower_intrinsics.
cjgillot Oct 16, 2023
d556de3
FileCheck lower_array_len.
cjgillot Oct 16, 2023
aad5093
FileCheck lower_slice_len.
cjgillot Oct 16, 2023
809c3cf
Mention skip in README.
cjgillot Oct 16, 2023
8fa8777
FileCheck issue_106141.
cjgillot Oct 16, 2023
eaabda7
FileCheck inline_shims.
cjgillot Oct 16, 2023
804aa6a
FileCheck transmute.
cjgillot Oct 16, 2023
c1c5a1d
Only check in a single place if a pass is enabled.
cjgillot Oct 18, 2023
0e17e5b
Rollup merge of #116037 - wesleywiser:stack_protector_test_windows, r…
fmease Oct 19, 2023
14da43e
Rollup merge of #116132 - darthunix:connect_poll, r=cuviper
fmease Oct 19, 2023
c3d0f11
Rollup merge of #116810 - cjgillot:mir-opt-check, r=oli-obk
fmease Oct 19, 2023
b6f4522
Rollup merge of #116896 - cjgillot:single-inline, r=oli-obk
fmease Oct 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
FileCheck lower_intrinsics.
  • Loading branch information
cjgillot committed Oct 18, 2023
commit f77a3ef19397b72e726856a5f8d891e24199e850
88 changes: 87 additions & 1 deletion tests/mir-opt/lower_intrinsics.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// skip-filecheck
// unit-test: LowerIntrinsics
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY

Expand All @@ -7,13 +6,25 @@

// EMIT_MIR lower_intrinsics.wrapping.LowerIntrinsics.diff
pub fn wrapping(a: i32, b: i32) {
// CHECK-LABEL: fn wrapping(
// CHECK: {{_.*}} = Add(
// CHECK: {{_.*}} = Sub(
// CHECK: {{_.*}} = Mul(
let _x = core::intrinsics::wrapping_add(a, b);
let _y = core::intrinsics::wrapping_sub(a, b);
let _z = core::intrinsics::wrapping_mul(a, b);
}

// EMIT_MIR lower_intrinsics.unchecked.LowerIntrinsics.diff
pub unsafe fn unchecked(a: i32, b: i32) {
// CHECK-LABEL: fn unchecked(
// CHECK: {{_.*}} = AddUnchecked(
// CHECK: {{_.*}} = SubUnchecked(
// CHECK: {{_.*}} = MulUnchecked(
// CHECK: {{_.*}} = Div(
// CHECK: {{_.*}} = Rem(
// CHECK: {{_.*}} = ShlUnchecked(
// CHECK: {{_.*}} = ShrUnchecked(
let _a = core::intrinsics::unchecked_add(a, b);
let _b = core::intrinsics::unchecked_sub(a, b);
let _c = core::intrinsics::unchecked_mul(a, b);
Expand All @@ -25,60 +36,95 @@ pub unsafe fn unchecked(a: i32, b: i32) {

// EMIT_MIR lower_intrinsics.size_of.LowerIntrinsics.diff
pub fn size_of<T>() -> usize {
// CHECK-LABEL: fn size_of(
// CHECK: {{_.*}} = SizeOf(T);
core::intrinsics::size_of::<T>()
}

// EMIT_MIR lower_intrinsics.align_of.LowerIntrinsics.diff
pub fn align_of<T>() -> usize {
// CHECK-LABEL: fn align_of(
// CHECK: {{_.*}} = AlignOf(T);
core::intrinsics::min_align_of::<T>()
}

// EMIT_MIR lower_intrinsics.forget.LowerIntrinsics.diff
pub fn forget<T>(t: T) {
// CHECK-LABEL: fn forget(
// CHECK-NOT: Drop(
// CHECK: return;
// CHECK-NOT: Drop(
core::intrinsics::forget(t)
}

// EMIT_MIR lower_intrinsics.unreachable.LowerIntrinsics.diff
pub fn unreachable() -> ! {
// CHECK-LABEL: fn unreachable(
// CHECK: unreachable;
unsafe { core::intrinsics::unreachable() };
}

// EMIT_MIR lower_intrinsics.non_const.LowerIntrinsics.diff
pub fn non_const<T>() -> usize {
// CHECK-LABEL: fn non_const(
// CHECK: SizeOf(T);

// Check that lowering works with non-const operand as a func.
let size_of_t = core::intrinsics::size_of::<T>;
size_of_t()
}

// EMIT_MIR lower_intrinsics.transmute_inhabited.LowerIntrinsics.diff
pub fn transmute_inhabited(c: std::cmp::Ordering) -> i8 {
// CHECK-LABEL: fn transmute_inhabited(
// CHECK: {{_.*}} = {{.*}} as i8 (Transmute);

unsafe { std::mem::transmute(c) }
}

// EMIT_MIR lower_intrinsics.transmute_uninhabited.LowerIntrinsics.diff
pub unsafe fn transmute_uninhabited(u: ()) -> Never {
// CHECK-LABEL: fn transmute_uninhabited(
// CHECK: {{_.*}} = {{.*}} as Never (Transmute);
// CHECK: unreachable;

unsafe { std::mem::transmute::<(), Never>(u) }
}

// EMIT_MIR lower_intrinsics.transmute_ref_dst.LowerIntrinsics.diff
pub unsafe fn transmute_ref_dst<T: ?Sized>(u: &T) -> *const T {
// CHECK-LABEL: fn transmute_ref_dst(
// CHECK: {{_.*}} = {{.*}} as *const T (Transmute);

unsafe { std::mem::transmute(u) }
}

// EMIT_MIR lower_intrinsics.transmute_to_ref_uninhabited.LowerIntrinsics.diff
pub unsafe fn transmute_to_ref_uninhabited() -> ! {
// CHECK-LABEL: fn transmute_to_ref_uninhabited(
// CHECK: {{_.*}} = {{.*}} as &Never (Transmute);
// CHECK: unreachable;

let x: &Never = std::mem::transmute(1usize);
match *x {}
}

// EMIT_MIR lower_intrinsics.transmute_to_mut_uninhabited.LowerIntrinsics.diff
pub unsafe fn transmute_to_mut_uninhabited() -> ! {
// CHECK-LABEL: fn transmute_to_mut_uninhabited(
// CHECK: {{_.*}} = {{.*}} as &mut Never (Transmute);
// CHECK: unreachable;

let x: &mut Never = std::mem::transmute(1usize);
match *x {}
}

// EMIT_MIR lower_intrinsics.transmute_to_box_uninhabited.LowerIntrinsics.diff
pub unsafe fn transmute_to_box_uninhabited() -> ! {
// CHECK-LABEL: fn transmute_to_box_uninhabited(
// CHECK: {{_.*}} = {{.*}} as std::boxed::Box<Never> (Transmute);
// CHECK: unreachable;

let x: Box<Never> = std::mem::transmute(1usize);
match *x {}
}
Expand All @@ -91,6 +137,12 @@ pub enum E {

// EMIT_MIR lower_intrinsics.discriminant.LowerIntrinsics.diff
pub fn discriminant<T>(t: T) {
// CHECK-LABEL: fn discriminant(
// CHECK: {{_.*}} = discriminant(
// CHECK: {{_.*}} = discriminant(
// CHECK: {{_.*}} = discriminant(
// CHECK: {{_.*}} = discriminant(

core::intrinsics::discriminant_value(&t);
core::intrinsics::discriminant_value(&0);
core::intrinsics::discriminant_value(&());
Expand All @@ -105,6 +157,9 @@ extern "rust-intrinsic" {

// EMIT_MIR lower_intrinsics.f_copy_nonoverlapping.LowerIntrinsics.diff
pub fn f_copy_nonoverlapping() {
// CHECK-LABEL: fn f_copy_nonoverlapping(
// CHECK: copy_nonoverlapping({{.*}});

let src = ();
let mut dst = ();
unsafe {
Expand All @@ -114,37 +169,65 @@ pub fn f_copy_nonoverlapping() {

// EMIT_MIR lower_intrinsics.assume.LowerIntrinsics.diff
pub fn assume() {
// CHECK-LABEL: fn assume(
// CHECK: assume({{.*}});

unsafe {
std::intrinsics::assume(true);
}
}

// EMIT_MIR lower_intrinsics.with_overflow.LowerIntrinsics.diff
pub fn with_overflow(a: i32, b: i32) {
// CHECK-LABEL: fn with_overflow(
// CHECK: CheckedAdd(
// CHECK: CheckedSub(
// CHECK: CheckedMul(

let _x = core::intrinsics::add_with_overflow(a, b);
let _y = core::intrinsics::sub_with_overflow(a, b);
let _z = core::intrinsics::mul_with_overflow(a, b);
}

// EMIT_MIR lower_intrinsics.read_via_copy_primitive.LowerIntrinsics.diff
pub fn read_via_copy_primitive(r: &i32) -> i32 {
// CHECK-LABEL: fn read_via_copy_primitive(
// CHECK: [[tmp:_.*]] = &raw const (*_1);
// CHECK: _0 = (*[[tmp]]);
// CHECK: return;

unsafe { core::intrinsics::read_via_copy(r) }
}

// EMIT_MIR lower_intrinsics.read_via_copy_uninhabited.LowerIntrinsics.diff
pub fn read_via_copy_uninhabited(r: &Never) -> Never {
// CHECK-LABEL: fn read_via_copy_uninhabited(
// CHECK: [[tmp:_.*]] = &raw const (*_1);
// CHECK: _0 = (*[[tmp]]);
// CHECK: unreachable;

unsafe { core::intrinsics::read_via_copy(r) }
}

// EMIT_MIR lower_intrinsics.write_via_move_string.LowerIntrinsics.diff
pub fn write_via_move_string(r: &mut String, v: String) {
// CHECK-LABEL: fn write_via_move_string(
// CHECK: [[ptr:_.*]] = &raw mut (*_1);
// CHECK: [[tmp:_.*]] = move _2;
// CHECK: (*[[ptr]]) = move [[tmp]];
// CHECK: return;

unsafe { core::intrinsics::write_via_move(r, v) }
}

pub enum Never {}

// EMIT_MIR lower_intrinsics.option_payload.LowerIntrinsics.diff
pub fn option_payload(o: &Option<usize>, p: &Option<String>) {
// CHECK-LABEL: fn option_payload(
// CHECK: {{_.*}} = &raw const (((*{{_.*}}) as Some).0: usize);
// CHECK: {{_.*}} = &raw const (((*{{_.*}}) as Some).0: std::string::String);

unsafe {
let _x = core::intrinsics::option_payload_ptr(o);
let _y = core::intrinsics::option_payload_ptr(p);
Expand All @@ -153,5 +236,8 @@ pub fn option_payload(o: &Option<usize>, p: &Option<String>) {

// EMIT_MIR lower_intrinsics.ptr_offset.LowerIntrinsics.diff
pub unsafe fn ptr_offset(p: *const i32, d: isize) -> *const i32 {
// CHECK-LABEL: fn ptr_offset(
// CHECK: _0 = Offset(

core::intrinsics::offset(p, d)
}