Skip to content

Commit

Permalink
Use generic NonZero in tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
reitermarkus committed Feb 23, 2024
1 parent 21033f6 commit 26719f0
Show file tree
Hide file tree
Showing 43 changed files with 514 additions and 514 deletions.
4 changes: 2 additions & 2 deletions tests/codegen/array-equality.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//@ compile-flags: -O -Z merge-functions=disabled
//@ only-x86_64

#![crate_type = "lib"]
#![feature(generic_nonzero)]

// CHECK-LABEL: @array_eq_value
#[no_mangle]
Expand Down Expand Up @@ -63,7 +63,7 @@ pub fn array_eq_zero_short(x: [u16; 3]) -> bool {

// CHECK-LABEL: @array_eq_none_short(i40
#[no_mangle]
pub fn array_eq_none_short(x: [Option<std::num::NonZeroU8>; 5]) -> bool {
pub fn array_eq_none_short(x: [Option<std::num::NonZero<u8>>; 5]) -> bool {
// CHECK-NEXT: start:
// CHECK-NEXT: %[[EQ:.+]] = icmp eq i40 %0, 0
// CHECK-NEXT: ret i1 %[[EQ]]
Expand Down
17 changes: 7 additions & 10 deletions tests/codegen/enum/enum-debug-niche-2.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
// This tests that optimized enum debug info accurately reflects the enum layout.
// This is ignored for the fallback mode on MSVC due to problems with PDB.

//
//@ ignore-msvc

//! This tests that optimized enum debug info accurately reflects the enum layout.
//! This is ignored for the fallback mode on MSVC due to problems with PDB.
//!
//@ compile-flags: -g -C no-prepopulate-passes

//@ ignore-msvc
//
// CHECK: {{.*}}DICompositeType{{.*}}tag: DW_TAG_variant_part,{{.*}}size: 32,{{.*}}
// CHECK: {{.*}}DIDerivedType{{.*}}tag: DW_TAG_member,{{.*}}name: "Placeholder",{{.*}}extraData: i128 4294967295{{[,)].*}}
// CHECK: {{.*}}DIDerivedType{{.*}}tag: DW_TAG_member,{{.*}}name: "Error",{{.*}}extraData: i128 0{{[,)].*}}

#![feature(never_type)]
#![feature(generic_nonzero, never_type)]

#[derive(Copy, Clone)]
pub struct Entity {
private: std::num::NonZeroU32,
private: std::num::NonZero<u32>,
}

#[derive(Copy, Clone, PartialEq, Eq)]
Expand Down
8 changes: 4 additions & 4 deletions tests/codegen/function-arguments.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//@ compile-flags: -O -C no-prepopulate-passes

#![crate_type = "lib"]
#![feature(dyn_star)]
#![feature(generic_nonzero)]

use std::mem::MaybeUninit;
use std::num::NonZeroU64;
use std::num::NonZero;
use std::marker::PhantomPinned;
use std::ptr::NonNull;

Expand Down Expand Up @@ -70,13 +70,13 @@ pub fn int(x: u64) -> u64 {

// CHECK: noundef i64 @nonzero_int(i64 noundef %x)
#[no_mangle]
pub fn nonzero_int(x: NonZeroU64) -> NonZeroU64 {
pub fn nonzero_int(x: NonZero<u64>) -> NonZero<u64> {
x
}

// CHECK: noundef i64 @option_nonzero_int(i64 noundef %x)
#[no_mangle]
pub fn option_nonzero_int(x: Option<NonZeroU64>) -> Option<NonZeroU64> {
pub fn option_nonzero_int(x: Option<NonZero<u64>>) -> Option<NonZero<u64>> {
x
}

Expand Down
6 changes: 3 additions & 3 deletions tests/codegen/intrinsics/transmute-niched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
//@ [OPT] compile-flags: -C opt-level=3 -C no-prepopulate-passes
//@ [DBG] compile-flags: -C opt-level=0 -C no-prepopulate-passes
//@ only-64bit (so I don't need to worry about usize)

#![crate_type = "lib"]
#![feature(generic_nonzero)]

use std::mem::transmute;
use std::num::NonZeroU32;
use std::num::NonZero;

#[repr(u8)]
pub enum SmallEnum {
Expand Down Expand Up @@ -130,7 +130,7 @@ pub unsafe fn check_enum_to_char(x: Minus100ToPlus100) -> char {

// CHECK-LABEL: @check_swap_pair(
#[no_mangle]
pub unsafe fn check_swap_pair(x: (char, NonZeroU32)) -> (NonZeroU32, char) {
pub unsafe fn check_swap_pair(x: (char, NonZero<u32>)) -> (NonZero<u32>, char) {
// OPT: %0 = icmp ule i32 %x.0, 1114111
// OPT: call void @llvm.assume(i1 %0)
// OPT: %1 = icmp uge i32 %x.0, 1
Expand Down
22 changes: 11 additions & 11 deletions tests/codegen/issues/issue-119422.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//! This test checks that compiler don't generate useless compares to zeros
//! for NonZero integer types.

//! for `NonZero` integer types.
//!
//@ compile-flags: -O --edition=2021 -Zmerge-functions=disabled
//@ only-64bit (because the LLVM type of i64 for usize shows up)

#![crate_type = "lib"]
#![feature(generic_nonzero)]

use core::num::*;
use core::ptr::NonNull;
use core::num::NonZero;

// CHECK-LABEL: @check_non_null
#[no_mangle]
Expand All @@ -18,7 +18,7 @@ pub fn check_non_null(x: NonNull<u8>) -> bool {

// CHECK-LABEL: @equals_zero_is_false_u8
#[no_mangle]
pub fn equals_zero_is_false_u8(x: NonZeroU8) -> bool {
pub fn equals_zero_is_false_u8(x: NonZero<u8>) -> bool {
// CHECK-NOT: br
// CHECK: ret i1 false
// CHECK-NOT: br
Expand All @@ -27,7 +27,7 @@ pub fn equals_zero_is_false_u8(x: NonZeroU8) -> bool {

// CHECK-LABEL: @not_equals_zero_is_true_u8
#[no_mangle]
pub fn not_equals_zero_is_true_u8(x: NonZeroU8) -> bool {
pub fn not_equals_zero_is_true_u8(x: NonZero<u8>) -> bool {
// CHECK-NOT: br
// CHECK: ret i1 true
// CHECK-NOT: br
Expand All @@ -36,7 +36,7 @@ pub fn not_equals_zero_is_true_u8(x: NonZeroU8) -> bool {

// CHECK-LABEL: @equals_zero_is_false_i8
#[no_mangle]
pub fn equals_zero_is_false_i8(x: NonZeroI8) -> bool {
pub fn equals_zero_is_false_i8(x: NonZero<i8>) -> bool {
// CHECK-NOT: br
// CHECK: ret i1 false
// CHECK-NOT: br
Expand All @@ -45,7 +45,7 @@ pub fn equals_zero_is_false_i8(x: NonZeroI8) -> bool {

// CHECK-LABEL: @not_equals_zero_is_true_i8
#[no_mangle]
pub fn not_equals_zero_is_true_i8(x: NonZeroI8) -> bool {
pub fn not_equals_zero_is_true_i8(x: NonZero<i8>) -> bool {
// CHECK-NOT: br
// CHECK: ret i1 true
// CHECK-NOT: br
Expand All @@ -54,7 +54,7 @@ pub fn not_equals_zero_is_true_i8(x: NonZeroI8) -> bool {

// CHECK-LABEL: @usize_try_from_u32
#[no_mangle]
pub fn usize_try_from_u32(x: NonZeroU32) -> NonZeroUsize {
pub fn usize_try_from_u32(x: NonZero<u32>) -> NonZero<usize> {
// CHECK-NOT: br
// CHECK: zext i32 %{{.*}} to i64
// CHECK-NOT: br
Expand All @@ -64,7 +64,7 @@ pub fn usize_try_from_u32(x: NonZeroU32) -> NonZeroUsize {

// CHECK-LABEL: @isize_try_from_i32
#[no_mangle]
pub fn isize_try_from_i32(x: NonZeroI32) -> NonZeroIsize {
pub fn isize_try_from_i32(x: NonZero<i32>) -> NonZero<isize> {
// CHECK-NOT: br
// CHECK: sext i32 %{{.*}} to i64
// CHECK-NOT: br
Expand All @@ -74,7 +74,7 @@ pub fn isize_try_from_i32(x: NonZeroI32) -> NonZeroIsize {

// CHECK-LABEL: @u64_from_nonzero_is_not_zero
#[no_mangle]
pub fn u64_from_nonzero_is_not_zero(x: NonZeroU64)->bool {
pub fn u64_from_nonzero_is_not_zero(x: NonZero<u64>)->bool {
// CHECK-NOT: br
// CHECK: ret i1 false
// CHECK-NOT: br
Expand Down
8 changes: 4 additions & 4 deletions tests/codegen/loads.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//@ compile-flags: -C no-prepopulate-passes -Zmir-opt-level=0

#![crate_type = "lib"]
#![feature(generic_nonzero)]

use std::mem::MaybeUninit;
use std::num::NonZeroU16;
use std::num::NonZero;

pub struct Bytes {
a: u8,
Expand Down Expand Up @@ -99,14 +99,14 @@ pub fn load_int(x: &u16) -> u16 {

// CHECK-LABEL: @load_nonzero_int
#[no_mangle]
pub fn load_nonzero_int(x: &NonZeroU16) -> NonZeroU16 {
pub fn load_nonzero_int(x: &NonZero<u16>) -> NonZero<u16> {
// CHECK: load i16, ptr %x, align 2, !range ![[NONZEROU16_RANGE:[0-9]+]], !noundef !{{[0-9]+}}
*x
}

// CHECK-LABEL: @load_option_nonzero_int
#[no_mangle]
pub fn load_option_nonzero_int(x: &Option<NonZeroU16>) -> Option<NonZeroU16> {
pub fn load_option_nonzero_int(x: &Option<NonZero<u16>>) -> Option<NonZero<u16>> {
// CHECK: load i16, ptr %x, align 2, !noundef ![[NOUNDEF]]{{$}}
*x
}
Expand Down
9 changes: 4 additions & 5 deletions tests/codegen/option-as-slice.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
//@ compile-flags: -O -Z randomize-layout=no
//@ only-x86_64
//@ ignore-llvm-version: 16.0.0
// ^ needs https://reviews.llvm.org/D146149 in 16.0.1

// ^-- needs https://reviews.llvm.org/D146149 in 16.0.1
#![crate_type = "lib"]
#![feature(option_as_slice)]
#![feature(generic_nonzero)]

extern crate core;

use core::num::NonZeroU64;
use core::num::NonZero;
use core::option::Option;

// CHECK-LABEL: @u64_opt_as_slice
Expand All @@ -23,7 +22,7 @@ pub fn u64_opt_as_slice(o: &Option<u64>) -> &[u64] {

// CHECK-LABEL: @nonzero_u64_opt_as_slice
#[no_mangle]
pub fn nonzero_u64_opt_as_slice(o: &Option<NonZeroU64>) -> &[NonZeroU64] {
pub fn nonzero_u64_opt_as_slice(o: &Option<NonZero<u64>>) -> &[NonZero<u64>] {
// CHECK-NOT: select
// CHECK-NOT: br
// CHECK-NOT: switch
Expand Down
8 changes: 4 additions & 4 deletions tests/codegen/option-nonzero-eq.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
//@ compile-flags: -O -Zmerge-functions=disabled

#![crate_type = "lib"]
#![feature(generic_nonzero)]

extern crate core;
use core::cmp::Ordering;
use core::num::{NonZeroU32, NonZeroI64};
use core::ptr::NonNull;
use core::num::NonZero;

// See also tests/assembly/option-nonzero-eq.rs, for cases with `assume`s in the
// LLVM and thus don't optimize down clearly here, but do in assembly.

// CHECK-lABEL: @non_zero_eq
#[no_mangle]
pub fn non_zero_eq(l: Option<NonZeroU32>, r: Option<NonZeroU32>) -> bool {
pub fn non_zero_eq(l: Option<NonZero<u32>>, r: Option<NonZero<u32>>) -> bool {
// CHECK: start:
// CHECK-NEXT: icmp eq i32
// CHECK-NEXT: ret i1
Expand All @@ -21,7 +21,7 @@ pub fn non_zero_eq(l: Option<NonZeroU32>, r: Option<NonZeroU32>) -> bool {

// CHECK-lABEL: @non_zero_signed_eq
#[no_mangle]
pub fn non_zero_signed_eq(l: Option<NonZeroI64>, r: Option<NonZeroI64>) -> bool {
pub fn non_zero_signed_eq(l: Option<NonZero<i64>>, r: Option<NonZero<i64>>) -> bool {
// CHECK: start:
// CHECK-NEXT: icmp eq i64
// CHECK-NEXT: ret i1
Expand Down
8 changes: 4 additions & 4 deletions tests/codegen/slice-ref-equality.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//@ compile-flags: -O -Zmerge-functions=disabled
//@ ignore-debug (the extra assertions get in the way)

#![crate_type = "lib"]
#![feature(generic_nonzero)]

use std::num::{NonZeroI16, NonZeroU32};
use std::num::NonZero;

// #71602 reported a simple array comparison just generating a loop.
// This was originally fixed by ensuring it generates a single bcmp,
Expand Down Expand Up @@ -71,7 +71,7 @@ fn eq_slice_of_i32(x: &[i32], y: &[i32]) -> bool {
// CHECK-SAME: [[USIZE:i16|i32|i64]] noundef %1
// CHECK-SAME: [[USIZE]] noundef %3
#[no_mangle]
fn eq_slice_of_nonzero(x: &[NonZeroU32], y: &[NonZeroU32]) -> bool {
fn eq_slice_of_nonzero(x: &[NonZero<i32>], y: &[NonZero<i32>]) -> bool {
// CHECK: icmp eq [[USIZE]] %1, %3
// CHECK: %[[BYTES:.+]] = shl nsw [[USIZE]] %1, 2
// CHECK: tail call{{( noundef)?}} i32 @{{bcmp|memcmp}}(ptr
Expand All @@ -83,7 +83,7 @@ fn eq_slice_of_nonzero(x: &[NonZeroU32], y: &[NonZeroU32]) -> bool {
// CHECK-SAME: [[USIZE:i16|i32|i64]] noundef %1
// CHECK-SAME: [[USIZE]] noundef %3
#[no_mangle]
fn eq_slice_of_option_of_nonzero(x: &[Option<NonZeroI16>], y: &[Option<NonZeroI16>]) -> bool {
fn eq_slice_of_option_of_nonzero(x: &[Option<NonZero<i16>>], y: &[Option<NonZero<i16>>]) -> bool {
// CHECK: icmp eq [[USIZE]] %1, %3
// CHECK: %[[BYTES:.+]] = shl nsw [[USIZE]] %1, 1
// CHECK: tail call{{( noundef)?}} i32 @{{bcmp|memcmp}}(ptr
Expand Down
6 changes: 3 additions & 3 deletions tests/codegen/transmute-optimized.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//@ compile-flags: -O -Z merge-functions=disabled
//@ ignore-debug

#![crate_type = "lib"]
#![feature(generic_nonzero)]

// This tests that LLVM can optimize based on the niches in the source or
// destination types for transmutes.
Expand Down Expand Up @@ -34,7 +34,7 @@ pub fn non_null_is_null(x: std::ptr::NonNull<i32>) -> bool {

// CHECK-LABEL: i1 @non_zero_is_null(
#[no_mangle]
pub fn non_zero_is_null(x: std::num::NonZeroUsize) -> bool {
pub fn non_zero_is_null(x: std::num::NonZero<usize>) -> bool {
// CHECK: ret i1 false
let p: *const i32 = unsafe { std::mem::transmute(x) };
p.is_null()
Expand Down Expand Up @@ -73,7 +73,7 @@ pub fn normal_div(a: u32, b: u32) -> u32 {

// CHECK-LABEL: i32 @div_transmute_nonzero(i32
#[no_mangle]
pub fn div_transmute_nonzero(a: u32, b: std::num::NonZeroI32) -> u32 {
pub fn div_transmute_nonzero(a: u32, b: std::num::NonZero<i32>) -> u32 {
// CHECK-NOT: call core::panicking::panic
// CHECK: %[[R:.+]] = udiv i32 %a, %b
// CHECK-NEXT: ret i32 %[[R]]
Expand Down
Loading

0 comments on commit 26719f0

Please sign in to comment.