Skip to content

Commit cecfe72

Browse files
committed
Use generic NonZero in tests.
1 parent 21033f6 commit cecfe72

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+520
-517
lines changed

tests/codegen/array-equality.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@ compile-flags: -O -Z merge-functions=disabled
22
//@ only-x86_64
3-
43
#![crate_type = "lib"]
4+
#![feature(generic_nonzero)]
55

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

6464
// CHECK-LABEL: @array_eq_none_short(i40
6565
#[no_mangle]
66-
pub fn array_eq_none_short(x: [Option<std::num::NonZeroU8>; 5]) -> bool {
66+
pub fn array_eq_none_short(x: [Option<std::num::NonZero<u8>>; 5]) -> bool {
6767
// CHECK-NEXT: start:
6868
// CHECK-NEXT: %[[EQ:.+]] = icmp eq i40 %0, 0
6969
// CHECK-NEXT: ret i1 %[[EQ]]

tests/codegen/enum/enum-debug-niche-2.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1-
// This tests that optimized enum debug info accurately reflects the enum layout.
2-
// This is ignored for the fallback mode on MSVC due to problems with PDB.
3-
4-
//
5-
//@ ignore-msvc
6-
1+
//! This tests that optimized enum debug info accurately reflects the enum layout.
2+
//! This is ignored for the fallback mode on MSVC due to problems with PDB.
3+
//!
74
//@ compile-flags: -g -C no-prepopulate-passes
8-
5+
//@ ignore-msvc
6+
//
97
// CHECK: {{.*}}DICompositeType{{.*}}tag: DW_TAG_variant_part,{{.*}}size: 32,{{.*}}
108
// CHECK: {{.*}}DIDerivedType{{.*}}tag: DW_TAG_member,{{.*}}name: "Placeholder",{{.*}}extraData: i128 4294967295{{[,)].*}}
119
// CHECK: {{.*}}DIDerivedType{{.*}}tag: DW_TAG_member,{{.*}}name: "Error",{{.*}}extraData: i128 0{{[,)].*}}
12-
13-
#![feature(never_type)]
10+
#![feature(generic_nonzero, never_type)]
1411

1512
#[derive(Copy, Clone)]
1613
pub struct Entity {
17-
private: std::num::NonZeroU32,
14+
private: std::num::NonZero<u32>,
1815
}
1916

2017
#[derive(Copy, Clone, PartialEq, Eq)]

tests/codegen/function-arguments.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//@ compile-flags: -O -C no-prepopulate-passes
2-
32
#![crate_type = "lib"]
43
#![feature(dyn_star)]
4+
#![feature(generic_nonzero)]
55

66
use std::mem::MaybeUninit;
7-
use std::num::NonZeroU64;
7+
use std::num::NonZero;
88
use std::marker::PhantomPinned;
99
use std::ptr::NonNull;
1010

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

7171
// CHECK: noundef i64 @nonzero_int(i64 noundef %x)
7272
#[no_mangle]
73-
pub fn nonzero_int(x: NonZeroU64) -> NonZeroU64 {
73+
pub fn nonzero_int(x: NonZero<u64>) -> NonZero<u64> {
7474
x
7575
}
7676

7777
// CHECK: noundef i64 @option_nonzero_int(i64 noundef %x)
7878
#[no_mangle]
79-
pub fn option_nonzero_int(x: Option<NonZeroU64>) -> Option<NonZeroU64> {
79+
pub fn option_nonzero_int(x: Option<NonZero<u64>>) -> Option<NonZero<u64>> {
8080
x
8181
}
8282

tests/codegen/intrinsics/transmute-niched.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
//@ [OPT] compile-flags: -C opt-level=3 -C no-prepopulate-passes
33
//@ [DBG] compile-flags: -C opt-level=0 -C no-prepopulate-passes
44
//@ only-64bit (so I don't need to worry about usize)
5-
65
#![crate_type = "lib"]
6+
#![feature(generic_nonzero)]
77

88
use std::mem::transmute;
9-
use std::num::NonZeroU32;
9+
use std::num::NonZero;
1010

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

131131
// CHECK-LABEL: @check_swap_pair(
132132
#[no_mangle]
133-
pub unsafe fn check_swap_pair(x: (char, NonZeroU32)) -> (NonZeroU32, char) {
133+
pub unsafe fn check_swap_pair(x: (char, NonZero<u32>)) -> (NonZero<u32>, char) {
134134
// OPT: %0 = icmp ule i32 %x.0, 1114111
135135
// OPT: call void @llvm.assume(i1 %0)
136136
// OPT: %1 = icmp uge i32 %x.0, 1

tests/codegen/issues/issue-119422.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
//! This test checks that compiler don't generate useless compares to zeros
2-
//! for NonZero integer types.
3-
2+
//! for `NonZero` integer types.
3+
//!
44
//@ compile-flags: -O --edition=2021 -Zmerge-functions=disabled
55
//@ only-64bit (because the LLVM type of i64 for usize shows up)
6-
76
#![crate_type = "lib"]
7+
#![feature(generic_nonzero)]
88

9-
use core::num::*;
109
use core::ptr::NonNull;
10+
use core::num::NonZero;
1111

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

1919
// CHECK-LABEL: @equals_zero_is_false_u8
2020
#[no_mangle]
21-
pub fn equals_zero_is_false_u8(x: NonZeroU8) -> bool {
21+
pub fn equals_zero_is_false_u8(x: NonZero<u8>) -> bool {
2222
// CHECK-NOT: br
2323
// CHECK: ret i1 false
2424
// CHECK-NOT: br
@@ -27,7 +27,7 @@ pub fn equals_zero_is_false_u8(x: NonZeroU8) -> bool {
2727

2828
// CHECK-LABEL: @not_equals_zero_is_true_u8
2929
#[no_mangle]
30-
pub fn not_equals_zero_is_true_u8(x: NonZeroU8) -> bool {
30+
pub fn not_equals_zero_is_true_u8(x: NonZero<u8>) -> bool {
3131
// CHECK-NOT: br
3232
// CHECK: ret i1 true
3333
// CHECK-NOT: br
@@ -36,7 +36,7 @@ pub fn not_equals_zero_is_true_u8(x: NonZeroU8) -> bool {
3636

3737
// CHECK-LABEL: @equals_zero_is_false_i8
3838
#[no_mangle]
39-
pub fn equals_zero_is_false_i8(x: NonZeroI8) -> bool {
39+
pub fn equals_zero_is_false_i8(x: NonZero<i8>) -> bool {
4040
// CHECK-NOT: br
4141
// CHECK: ret i1 false
4242
// CHECK-NOT: br
@@ -45,7 +45,7 @@ pub fn equals_zero_is_false_i8(x: NonZeroI8) -> bool {
4545

4646
// CHECK-LABEL: @not_equals_zero_is_true_i8
4747
#[no_mangle]
48-
pub fn not_equals_zero_is_true_i8(x: NonZeroI8) -> bool {
48+
pub fn not_equals_zero_is_true_i8(x: NonZero<i8>) -> bool {
4949
// CHECK-NOT: br
5050
// CHECK: ret i1 true
5151
// CHECK-NOT: br
@@ -54,7 +54,7 @@ pub fn not_equals_zero_is_true_i8(x: NonZeroI8) -> bool {
5454

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

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

7575
// CHECK-LABEL: @u64_from_nonzero_is_not_zero
7676
#[no_mangle]
77-
pub fn u64_from_nonzero_is_not_zero(x: NonZeroU64)->bool {
77+
pub fn u64_from_nonzero_is_not_zero(x: NonZero<u64>)->bool {
7878
// CHECK-NOT: br
7979
// CHECK: ret i1 false
8080
// CHECK-NOT: br

tests/codegen/loads.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
//@ compile-flags: -C no-prepopulate-passes -Zmir-opt-level=0
2-
32
#![crate_type = "lib"]
3+
#![feature(generic_nonzero)]
44

55
use std::mem::MaybeUninit;
6-
use std::num::NonZeroU16;
6+
use std::num::NonZero;
77

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

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

107107
// CHECK-LABEL: @load_option_nonzero_int
108108
#[no_mangle]
109-
pub fn load_option_nonzero_int(x: &Option<NonZeroU16>) -> Option<NonZeroU16> {
109+
pub fn load_option_nonzero_int(x: &Option<NonZero<u16>>) -> Option<NonZero<u16>> {
110110
// CHECK: load i16, ptr %x, align 2, !noundef ![[NOUNDEF]]{{$}}
111111
*x
112112
}

tests/codegen/option-as-slice.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
//@ compile-flags: -O -Z randomize-layout=no
22
//@ only-x86_64
33
//@ ignore-llvm-version: 16.0.0
4-
// ^ needs https://reviews.llvm.org/D146149 in 16.0.1
5-
4+
// ^-- needs https://reviews.llvm.org/D146149 in 16.0.1
65
#![crate_type = "lib"]
7-
#![feature(option_as_slice)]
6+
#![feature(generic_nonzero)]
87

98
extern crate core;
109

11-
use core::num::NonZeroU64;
10+
use core::num::NonZero;
1211
use core::option::Option;
1312

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

2423
// CHECK-LABEL: @nonzero_u64_opt_as_slice
2524
#[no_mangle]
26-
pub fn nonzero_u64_opt_as_slice(o: &Option<NonZeroU64>) -> &[NonZeroU64] {
25+
pub fn nonzero_u64_opt_as_slice(o: &Option<NonZero<u64>>) -> &[NonZero<u64>] {
2726
// CHECK-NOT: select
2827
// CHECK-NOT: br
2928
// CHECK-NOT: switch

tests/codegen/option-nonzero-eq.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
//@ compile-flags: -O -Zmerge-functions=disabled
2-
32
#![crate_type = "lib"]
3+
#![feature(generic_nonzero)]
44

55
extern crate core;
66
use core::cmp::Ordering;
7-
use core::num::{NonZeroU32, NonZeroI64};
87
use core::ptr::NonNull;
8+
use core::num::NonZero;
99

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

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

2222
// CHECK-lABEL: @non_zero_signed_eq
2323
#[no_mangle]
24-
pub fn non_zero_signed_eq(l: Option<NonZeroI64>, r: Option<NonZeroI64>) -> bool {
24+
pub fn non_zero_signed_eq(l: Option<NonZero<i64>>, r: Option<NonZero<i64>>) -> bool {
2525
// CHECK: start:
2626
// CHECK-NEXT: icmp eq i64
2727
// CHECK-NEXT: ret i1

tests/codegen/slice-ref-equality.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
//@ compile-flags: -O -Zmerge-functions=disabled
22
//@ ignore-debug (the extra assertions get in the way)
3-
43
#![crate_type = "lib"]
4+
#![feature(generic_nonzero)]
55

6-
use std::num::{NonZeroI16, NonZeroU32};
6+
use std::num::NonZero;
77

88
// #71602 reported a simple array comparison just generating a loop.
99
// This was originally fixed by ensuring it generates a single bcmp,
@@ -71,7 +71,7 @@ fn eq_slice_of_i32(x: &[i32], y: &[i32]) -> bool {
7171
// CHECK-SAME: [[USIZE:i16|i32|i64]] noundef %1
7272
// CHECK-SAME: [[USIZE]] noundef %3
7373
#[no_mangle]
74-
fn eq_slice_of_nonzero(x: &[NonZeroU32], y: &[NonZeroU32]) -> bool {
74+
fn eq_slice_of_nonzero(x: &[NonZero<i32>], y: &[NonZero<i32>]) -> bool {
7575
// CHECK: icmp eq [[USIZE]] %1, %3
7676
// CHECK: %[[BYTES:.+]] = shl nsw [[USIZE]] %1, 2
7777
// CHECK: tail call{{( noundef)?}} i32 @{{bcmp|memcmp}}(ptr
@@ -83,7 +83,7 @@ fn eq_slice_of_nonzero(x: &[NonZeroU32], y: &[NonZeroU32]) -> bool {
8383
// CHECK-SAME: [[USIZE:i16|i32|i64]] noundef %1
8484
// CHECK-SAME: [[USIZE]] noundef %3
8585
#[no_mangle]
86-
fn eq_slice_of_option_of_nonzero(x: &[Option<NonZeroI16>], y: &[Option<NonZeroI16>]) -> bool {
86+
fn eq_slice_of_option_of_nonzero(x: &[Option<NonZero<i16>>], y: &[Option<NonZero<i16>>]) -> bool {
8787
// CHECK: icmp eq [[USIZE]] %1, %3
8888
// CHECK: %[[BYTES:.+]] = shl nsw [[USIZE]] %1, 1
8989
// CHECK: tail call{{( noundef)?}} i32 @{{bcmp|memcmp}}(ptr

tests/codegen/transmute-optimized.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@ compile-flags: -O -Z merge-functions=disabled
22
//@ ignore-debug
3-
43
#![crate_type = "lib"]
4+
#![feature(generic_nonzero)]
55

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

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

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

0 commit comments

Comments
 (0)