From 36e1414b10af7ca487d6f84165e1f23a80375fd4 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Mon, 20 May 2024 17:53:07 +0000 Subject: [PATCH 01/14] add codegen test for #120440 --- tests/codegen/slice-pointer-nonnull-unwrap.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 tests/codegen/slice-pointer-nonnull-unwrap.rs diff --git a/tests/codegen/slice-pointer-nonnull-unwrap.rs b/tests/codegen/slice-pointer-nonnull-unwrap.rs new file mode 100644 index 0000000000000..51ea4a1f943d6 --- /dev/null +++ b/tests/codegen/slice-pointer-nonnull-unwrap.rs @@ -0,0 +1,19 @@ +//@ compile-flags: -O +//@ min-llvm-version: 18 +#![crate_type = "lib"] + +use std::ptr::NonNull; + +// CHECK-LABEL: @slice_ptr_len_1 +// CHECK: {{.*}}: +// CHECK-NEXT: ret i64 %ptr.1 +#[no_mangle] +pub fn slice_ptr_len_1(ptr: *const [u8]) -> usize { + let ptr = ptr.cast_mut(); + if let Some(ptr) = NonNull::new(ptr) { + ptr.len() + } else { + // We know ptr is null, so we know ptr.wrapping_byte_add(1) is not null. + NonNull::new(ptr.wrapping_byte_add(1)).unwrap().len() + } +} From f3c89f1751217f8ad2267d5acaed9b665392e9cc Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Mon, 20 May 2024 18:17:42 +0000 Subject: [PATCH 02/14] add codegen test for issue-118392, 71096 --- tests/codegen/issues/issue-118392.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 tests/codegen/issues/issue-118392.rs diff --git a/tests/codegen/issues/issue-118392.rs b/tests/codegen/issues/issue-118392.rs new file mode 100644 index 0000000000000..2cbb1f8b2043e --- /dev/null +++ b/tests/codegen/issues/issue-118392.rs @@ -0,0 +1,11 @@ +//@ compile-flags: -O +//@ min-llvm-version: 18 +#![crate_type = "lib"] + +// CHECK-LABEL: @div2 +// CHECK: ashr i32 %a, 1 +// CHECK-NEXT: ret i32 +#[no_mangle] +pub fn div2(a: i32) -> i32 { + a.div_euclid(2) +} From f37c576dbd350adf0644ca9a2b83e28d9d57a076 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Mon, 20 May 2024 18:18:52 +0000 Subject: [PATCH 03/14] add codegen test for #113757 --- ...issue-113757-bounds-check-after-cmp-max.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 tests/codegen/issues/issue-113757-bounds-check-after-cmp-max.rs diff --git a/tests/codegen/issues/issue-113757-bounds-check-after-cmp-max.rs b/tests/codegen/issues/issue-113757-bounds-check-after-cmp-max.rs new file mode 100644 index 0000000000000..5dedefc43d114 --- /dev/null +++ b/tests/codegen/issues/issue-113757-bounds-check-after-cmp-max.rs @@ -0,0 +1,19 @@ +// in Rust 1.73, -O and opt-level=3 optimizes differently +//@ compile-flags: -C opt-level=3 +//@ min-llvm-version: 17 +#![crate_type = "lib"] + +use std::cmp::max; + +#[no_mangle] +// CHECK-LABEL: @foo +// CHECK-NOT: slice_start_index_len_fail +// CHECK-NOT: unreachable +pub fn foo(v: &mut Vec, size: usize)-> Option<&mut [u8]> { + if v.len() > max(1, size) { + let start = v.len() - size; + Some(&mut v[start..]) + } else { + None + } +} From beabc5647bc81d62cebbe1d4a71a3666f8ade9d7 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Mon, 20 May 2024 18:38:45 +0000 Subject: [PATCH 04/14] add codegen test for #112509 --- .../issue-112509-slice-get-andthen-get.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 tests/codegen/issues/issue-112509-slice-get-andthen-get.rs diff --git a/tests/codegen/issues/issue-112509-slice-get-andthen-get.rs b/tests/codegen/issues/issue-112509-slice-get-andthen-get.rs new file mode 100644 index 0000000000000..fc04a6cc41abb --- /dev/null +++ b/tests/codegen/issues/issue-112509-slice-get-andthen-get.rs @@ -0,0 +1,17 @@ +//@ compile-flags: -O +//@ min-llvm-version: 17 +#![crate_type = "lib"] + +// CHECK-LABEL: @write_u8_variant_a +// CHECK: getelementptr +// CHECK-NEXT: icmp ugt +#[no_mangle] +pub fn write_u8_variant_a( + bytes: &mut [u8], + buf: u8, + offset: usize, +) -> Option<&mut [u8]> { + let buf = buf.to_le_bytes(); + bytes + .get_mut(offset..).and_then(|bytes| bytes.get_mut(..buf.len())) +} From 15d07fb2cbb48ba85d69aa043c1d77909a565ea8 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Mon, 20 May 2024 19:22:49 +0000 Subject: [PATCH 05/14] Add codegen test for #111508 --- .../issues/issue-111508-vec-tryinto-array.rs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/codegen/issues/issue-111508-vec-tryinto-array.rs diff --git a/tests/codegen/issues/issue-111508-vec-tryinto-array.rs b/tests/codegen/issues/issue-111508-vec-tryinto-array.rs new file mode 100644 index 0000000000000..2e7244e971307 --- /dev/null +++ b/tests/codegen/issues/issue-111508-vec-tryinto-array.rs @@ -0,0 +1,22 @@ +//@ compile-flags: -O +// This regress since Rust version 1.72. +//@ min-llvm-version: 18.1.4 + +#![crate_type = "lib"] + +use std::convert::TryInto; + +const N: usize = 24; + +#[no_mangle] +// CHECK-LABEL: @example +// CHECK-NOT: unwrap_failed +pub fn example(a: Vec) -> u8 { + if a.len() != 32 { + return 0; + } + + let a: [u8; 32] = a.try_into().unwrap(); + + a[15] + a[N] +} From ddb94dbd16760d6de5e3a9cbbffb66e161691786 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Mon, 20 May 2024 19:40:50 +0000 Subject: [PATCH 06/14] add codegen test for #110797 --- .../issues/issue-110797-enum-jump-same.rs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tests/codegen/issues/issue-110797-enum-jump-same.rs diff --git a/tests/codegen/issues/issue-110797-enum-jump-same.rs b/tests/codegen/issues/issue-110797-enum-jump-same.rs new file mode 100644 index 0000000000000..bfd10c0a5820d --- /dev/null +++ b/tests/codegen/issues/issue-110797-enum-jump-same.rs @@ -0,0 +1,27 @@ +//@ compile-flags: -O +// XXX: The x86-64 assembly get optimized correclty. But llvm-ir output is not until llvm 18? +//@ min-llvm-version: 18 + +#![crate_type = "lib"] + +pub enum K{ + A(Box<[i32]>), + B(Box<[u8]>), + C(Box<[String]>), + D(Box<[u16]>), +} + +#[no_mangle] +// CHECK-LABEL: @get_len +// CHECK: getelementptr inbounds +// CHECK-NEXT: load +// CHECK-NEXT: ret i64 +// CHECK-NOT: switch +pub fn get_len(arg: &K)->usize{ + match arg { + K::A(ref lst)=>lst.len(), + K::B(ref lst)=>lst.len(), + K::C(ref lst)=>lst.len(), + K::D(ref lst)=>lst.len(), + } +} From 7d967ffa8df2ae74e4cff5d5ed7b53adedac00a2 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Mon, 20 May 2024 19:52:30 +0000 Subject: [PATCH 07/14] add codegen test for #109328 --- .../codegen/issues/issue-109328-split_first.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 tests/codegen/issues/issue-109328-split_first.rs diff --git a/tests/codegen/issues/issue-109328-split_first.rs b/tests/codegen/issues/issue-109328-split_first.rs new file mode 100644 index 0000000000000..a43e653e1a264 --- /dev/null +++ b/tests/codegen/issues/issue-109328-split_first.rs @@ -0,0 +1,17 @@ +//@ compile-flags: -O +//@ min-llvm-version: 17 + +#![crate_type = "lib"] + +#[no_mangle] +// CHECK-LABEL: @foo +// CHECK: getelementptr inbounds +// CHECK-NEXT: load i64 +// CHECK-NEXT: icmp eq i64 +// CHECK-NEXT: br i1 +#[no_mangle] +pub fn foo(input: &mut &[u64]) -> Option { + let (first, rest) = input.split_first()?; + *input = rest; + Some(*first) +} From 8bd6c04cfc41e9952408fb8bed2db9c7e12a0ee6 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Mon, 20 May 2024 20:15:31 +0000 Subject: [PATCH 08/14] add codegen test for #93036 --- .../codegen/issues/issue-93036-assert-index.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 tests/codegen/issues/issue-93036-assert-index.rs diff --git a/tests/codegen/issues/issue-93036-assert-index.rs b/tests/codegen/issues/issue-93036-assert-index.rs new file mode 100644 index 0000000000000..9e4437cc65616 --- /dev/null +++ b/tests/codegen/issues/issue-93036-assert-index.rs @@ -0,0 +1,18 @@ +//@ compile-flags: -O +//@ min-llvm-version: 17 + +#![crate_type = "lib"] + +#[no_mangle] +// CHECK-LABEL: @foo +// CHECK: {{.*}}: +// CHECK: ret +// CHECK-NOT: unreachable +pub fn foo(arr: &mut [u32]) { + for i in 0..arr.len() { + for j in 0..i { + assert!(j < arr.len()); + } + } +} + From 2120ea5a913e6a0ea4137c43471f4d060629c6a8 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Mon, 20 May 2024 20:39:26 +0000 Subject: [PATCH 09/14] add assembly test for #83585 --- .../issue-83585-small-pod-struct-equality.rs | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/assembly/issue-83585-small-pod-struct-equality.rs diff --git a/tests/assembly/issue-83585-small-pod-struct-equality.rs b/tests/assembly/issue-83585-small-pod-struct-equality.rs new file mode 100644 index 0000000000000..56d458d851436 --- /dev/null +++ b/tests/assembly/issue-83585-small-pod-struct-equality.rs @@ -0,0 +1,30 @@ +//@ assembly-output: emit-asm +//@ compile-flags:-Copt-level=3 +//@ only-x86_64 + +#![crate_type = "lib"] + +#[no_mangle] +type T = u8; +type T1 = (T, T, T, T, T, T, T, T); +type T2 = [T; 8]; + +#[no_mangle] +// CHECK-LABEL: foo1a +// CHECK: cmp +// CHECK-NEXT: set +// CHECK-NEXT: ret +pub fn foo1a(a: T1, b: T1) -> bool { + a == b +} + +#[no_mangle] +// CHECK-LABEL: foo1b +// CHECK: mov +// CHECK-NEXT: cmp +// CHECK-NEXT: set +// CHECK-NEXT: ret +pub fn foo1b(a: &T1, b: &T1) -> bool { + a == b +} + From bf178187c7d7f671d233b012e6ebcd53e3d60a62 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Mon, 20 May 2024 21:20:33 +0000 Subject: [PATCH 10/14] add codegen test for #74938 --- .../codegen/issues/issue-74938-array-split-at.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 tests/codegen/issues/issue-74938-array-split-at.rs diff --git a/tests/codegen/issues/issue-74938-array-split-at.rs b/tests/codegen/issues/issue-74938-array-split-at.rs new file mode 100644 index 0000000000000..1f8aa3868d75f --- /dev/null +++ b/tests/codegen/issues/issue-74938-array-split-at.rs @@ -0,0 +1,15 @@ +//@ compile-flags: -O + +#![crate_type = "lib"] + +const N: usize = 3; +pub type T = u8; + +#[no_mangle] +// CHECK-LABEL: @split_mutiple +// CHECK-NOT: unreachable +pub fn split_mutiple(slice: &[T]) -> (&[T], &[T]) { + let len = slice.len() / N; + slice.split_at(len * N) +} + From 5f527eb562ff670cf9545817575ff6a7f6088bc7 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Mon, 20 May 2024 21:33:53 +0000 Subject: [PATCH 11/14] add codegen test for #68667 --- .../issues/issue-68667-unwrap-combinators.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 tests/codegen/issues/issue-68667-unwrap-combinators.rs diff --git a/tests/codegen/issues/issue-68667-unwrap-combinators.rs b/tests/codegen/issues/issue-68667-unwrap-combinators.rs new file mode 100644 index 0000000000000..05760dc9b5566 --- /dev/null +++ b/tests/codegen/issues/issue-68667-unwrap-combinators.rs @@ -0,0 +1,17 @@ +#![crate_type = "lib"] + +//@ compile-flags: -O + +// MIR inlining now optimizes this code. + +// CHECK-LABEL: @unwrap_combinators +// CHECK: icmp +// CHECK-NEXT: icmp +// CHECK-NEXT: select i1 +// CHECK-NEXT: ret i1 +#[no_mangle] +pub fn unwrap_combinators(a: Option, b: i32) -> bool { + a.map(|t| t >= b) + .unwrap_or(false) +} + From 95740fbfeddbc3e09a0a94cde4c3694cd5af17db Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Mon, 20 May 2024 21:50:31 +0000 Subject: [PATCH 12/14] add codegen test for #36010 --- .../issues/issue-36010-some-box-is_some.rs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tests/codegen/issues/issue-36010-some-box-is_some.rs diff --git a/tests/codegen/issues/issue-36010-some-box-is_some.rs b/tests/codegen/issues/issue-36010-some-box-is_some.rs new file mode 100644 index 0000000000000..b7179987e7d01 --- /dev/null +++ b/tests/codegen/issues/issue-36010-some-box-is_some.rs @@ -0,0 +1,29 @@ +#![crate_type = "lib"] + +//@ compile-flags: -O + +use std::mem; + +fn foo(a: &mut T, b: T) -> bool { + let b = Some(mem::replace(a, b)); + let ret = b.is_some(); + mem::forget(b); + return ret +} + +// CHECK-LABEL: @foo_u32 +// CHECK: store i32 +// CHECK-NEXT: ret i1 +#[no_mangle] +pub fn foo_u32(a: &mut u32, b: u32) -> bool { + foo(a, b) +} + +// CHECK-LABEL: @foo_box +// CHECK: store ptr +// CHECK-NEXT: ret i1 +#[no_mangle] +pub fn foo_box(a: &mut Box, b: Box) -> bool { + foo(a, b) +} + From f9edd864df9f85a9a6a2969fa74e0966f6565c36 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Sun, 9 Jun 2024 13:25:12 +0000 Subject: [PATCH 13/14] Apply suggestions from code review Co-authored-by: Nikita Popov --- .../issue-83585-small-pod-struct-equality.rs | 10 ++++------ .../issues/issue-109328-split_first.rs | 5 ++--- .../issues/issue-110797-enum-jump-same.rs | 19 +++++++++---------- .../issues/issue-111508-vec-tryinto-array.rs | 2 +- .../issue-112509-slice-get-andthen-get.rs | 13 ++++--------- ...issue-113757-bounds-check-after-cmp-max.rs | 5 ++--- .../issues/issue-36010-some-box-is_some.rs | 7 +++---- .../issues/issue-68667-unwrap-combinators.rs | 4 +--- .../issues/issue-74938-array-split-at.rs | 7 +++---- .../issues/issue-93036-assert-index.rs | 4 ---- tests/codegen/slice-pointer-nonnull-unwrap.rs | 16 ++++++++-------- 11 files changed, 37 insertions(+), 55 deletions(-) diff --git a/tests/assembly/issue-83585-small-pod-struct-equality.rs b/tests/assembly/issue-83585-small-pod-struct-equality.rs index 56d458d851436..9b0d605666d6e 100644 --- a/tests/assembly/issue-83585-small-pod-struct-equality.rs +++ b/tests/assembly/issue-83585-small-pod-struct-equality.rs @@ -4,27 +4,25 @@ #![crate_type = "lib"] -#[no_mangle] type T = u8; type T1 = (T, T, T, T, T, T, T, T); type T2 = [T; 8]; -#[no_mangle] // CHECK-LABEL: foo1a // CHECK: cmp -// CHECK-NEXT: set +// CHECK-NEXT: sete // CHECK-NEXT: ret +#[no_mangle] pub fn foo1a(a: T1, b: T1) -> bool { a == b } -#[no_mangle] // CHECK-LABEL: foo1b // CHECK: mov // CHECK-NEXT: cmp -// CHECK-NEXT: set +// CHECK-NEXT: sete // CHECK-NEXT: ret +#[no_mangle] pub fn foo1b(a: &T1, b: &T1) -> bool { a == b } - diff --git a/tests/codegen/issues/issue-109328-split_first.rs b/tests/codegen/issues/issue-109328-split_first.rs index a43e653e1a264..d3844c3ec20cc 100644 --- a/tests/codegen/issues/issue-109328-split_first.rs +++ b/tests/codegen/issues/issue-109328-split_first.rs @@ -1,11 +1,10 @@ //@ compile-flags: -O -//@ min-llvm-version: 17 #![crate_type = "lib"] -#[no_mangle] // CHECK-LABEL: @foo -// CHECK: getelementptr inbounds +// CHECK-NEXT: {{.*}}: +// CHECK-NEXT: getelementptr inbounds // CHECK-NEXT: load i64 // CHECK-NEXT: icmp eq i64 // CHECK-NEXT: br i1 diff --git a/tests/codegen/issues/issue-110797-enum-jump-same.rs b/tests/codegen/issues/issue-110797-enum-jump-same.rs index bfd10c0a5820d..d52faef23ad8d 100644 --- a/tests/codegen/issues/issue-110797-enum-jump-same.rs +++ b/tests/codegen/issues/issue-110797-enum-jump-same.rs @@ -1,27 +1,26 @@ //@ compile-flags: -O -// XXX: The x86-64 assembly get optimized correclty. But llvm-ir output is not until llvm 18? //@ min-llvm-version: 18 #![crate_type = "lib"] -pub enum K{ +pub enum K { A(Box<[i32]>), B(Box<[u8]>), C(Box<[String]>), D(Box<[u16]>), } -#[no_mangle] // CHECK-LABEL: @get_len -// CHECK: getelementptr inbounds +// CHECK-NEXT: {{.*}}: +// CHECK-NEXT: getelementptr inbounds // CHECK-NEXT: load // CHECK-NEXT: ret i64 -// CHECK-NOT: switch -pub fn get_len(arg: &K)->usize{ +#[no_mangle] +pub fn get_len(arg: &K) -> usize { match arg { - K::A(ref lst)=>lst.len(), - K::B(ref lst)=>lst.len(), - K::C(ref lst)=>lst.len(), - K::D(ref lst)=>lst.len(), + K::A(ref lst) => lst.len(), + K::B(ref lst) => lst.len(), + K::C(ref lst) => lst.len(), + K::D(ref lst) => lst.len(), } } diff --git a/tests/codegen/issues/issue-111508-vec-tryinto-array.rs b/tests/codegen/issues/issue-111508-vec-tryinto-array.rs index 2e7244e971307..6415724b40ad5 100644 --- a/tests/codegen/issues/issue-111508-vec-tryinto-array.rs +++ b/tests/codegen/issues/issue-111508-vec-tryinto-array.rs @@ -8,9 +8,9 @@ use std::convert::TryInto; const N: usize = 24; -#[no_mangle] // CHECK-LABEL: @example // CHECK-NOT: unwrap_failed +#[no_mangle] pub fn example(a: Vec) -> u8 { if a.len() != 32 { return 0; diff --git a/tests/codegen/issues/issue-112509-slice-get-andthen-get.rs b/tests/codegen/issues/issue-112509-slice-get-andthen-get.rs index fc04a6cc41abb..ae02c3fb79e72 100644 --- a/tests/codegen/issues/issue-112509-slice-get-andthen-get.rs +++ b/tests/codegen/issues/issue-112509-slice-get-andthen-get.rs @@ -1,17 +1,12 @@ //@ compile-flags: -O -//@ min-llvm-version: 17 #![crate_type = "lib"] // CHECK-LABEL: @write_u8_variant_a -// CHECK: getelementptr +// CHECK-NEXT: {{.*}}: +// CHECK-NEXT: getelementptr // CHECK-NEXT: icmp ugt #[no_mangle] -pub fn write_u8_variant_a( - bytes: &mut [u8], - buf: u8, - offset: usize, -) -> Option<&mut [u8]> { +pub fn write_u8_variant_a(bytes: &mut [u8], buf: u8, offset: usize) -> Option<&mut [u8]> { let buf = buf.to_le_bytes(); - bytes - .get_mut(offset..).and_then(|bytes| bytes.get_mut(..buf.len())) + bytes.get_mut(offset..).and_then(|bytes| bytes.get_mut(..buf.len())) } diff --git a/tests/codegen/issues/issue-113757-bounds-check-after-cmp-max.rs b/tests/codegen/issues/issue-113757-bounds-check-after-cmp-max.rs index 5dedefc43d114..d495adf99804c 100644 --- a/tests/codegen/issues/issue-113757-bounds-check-after-cmp-max.rs +++ b/tests/codegen/issues/issue-113757-bounds-check-after-cmp-max.rs @@ -1,15 +1,14 @@ // in Rust 1.73, -O and opt-level=3 optimizes differently //@ compile-flags: -C opt-level=3 -//@ min-llvm-version: 17 #![crate_type = "lib"] use std::cmp::max; -#[no_mangle] // CHECK-LABEL: @foo // CHECK-NOT: slice_start_index_len_fail // CHECK-NOT: unreachable -pub fn foo(v: &mut Vec, size: usize)-> Option<&mut [u8]> { +#[no_mangle] +pub fn foo(v: &mut Vec, size: usize) -> Option<&mut [u8]> { if v.len() > max(1, size) { let start = v.len() - size; Some(&mut v[start..]) diff --git a/tests/codegen/issues/issue-36010-some-box-is_some.rs b/tests/codegen/issues/issue-36010-some-box-is_some.rs index b7179987e7d01..44c01096f15ae 100644 --- a/tests/codegen/issues/issue-36010-some-box-is_some.rs +++ b/tests/codegen/issues/issue-36010-some-box-is_some.rs @@ -8,12 +8,12 @@ fn foo(a: &mut T, b: T) -> bool { let b = Some(mem::replace(a, b)); let ret = b.is_some(); mem::forget(b); - return ret + return ret; } // CHECK-LABEL: @foo_u32 // CHECK: store i32 -// CHECK-NEXT: ret i1 +// CHECK-NEXT: ret i1 true #[no_mangle] pub fn foo_u32(a: &mut u32, b: u32) -> bool { foo(a, b) @@ -21,9 +21,8 @@ pub fn foo_u32(a: &mut u32, b: u32) -> bool { // CHECK-LABEL: @foo_box // CHECK: store ptr -// CHECK-NEXT: ret i1 +// CHECK-NEXT: ret i1 true #[no_mangle] pub fn foo_box(a: &mut Box, b: Box) -> bool { foo(a, b) } - diff --git a/tests/codegen/issues/issue-68667-unwrap-combinators.rs b/tests/codegen/issues/issue-68667-unwrap-combinators.rs index 05760dc9b5566..6bd4c566a0c28 100644 --- a/tests/codegen/issues/issue-68667-unwrap-combinators.rs +++ b/tests/codegen/issues/issue-68667-unwrap-combinators.rs @@ -11,7 +11,5 @@ // CHECK-NEXT: ret i1 #[no_mangle] pub fn unwrap_combinators(a: Option, b: i32) -> bool { - a.map(|t| t >= b) - .unwrap_or(false) + a.map(|t| t >= b).unwrap_or(false) } - diff --git a/tests/codegen/issues/issue-74938-array-split-at.rs b/tests/codegen/issues/issue-74938-array-split-at.rs index 1f8aa3868d75f..2675e404ced3b 100644 --- a/tests/codegen/issues/issue-74938-array-split-at.rs +++ b/tests/codegen/issues/issue-74938-array-split-at.rs @@ -5,11 +5,10 @@ const N: usize = 3; pub type T = u8; -#[no_mangle] -// CHECK-LABEL: @split_mutiple +// CHECK-LABEL: @split_multiple // CHECK-NOT: unreachable -pub fn split_mutiple(slice: &[T]) -> (&[T], &[T]) { +#[no_mangle] +pub fn split_multiple(slice: &[T]) -> (&[T], &[T]) { let len = slice.len() / N; slice.split_at(len * N) } - diff --git a/tests/codegen/issues/issue-93036-assert-index.rs b/tests/codegen/issues/issue-93036-assert-index.rs index 9e4437cc65616..7a2ea08726688 100644 --- a/tests/codegen/issues/issue-93036-assert-index.rs +++ b/tests/codegen/issues/issue-93036-assert-index.rs @@ -1,12 +1,9 @@ //@ compile-flags: -O -//@ min-llvm-version: 17 #![crate_type = "lib"] #[no_mangle] // CHECK-LABEL: @foo -// CHECK: {{.*}}: -// CHECK: ret // CHECK-NOT: unreachable pub fn foo(arr: &mut [u32]) { for i in 0..arr.len() { @@ -15,4 +12,3 @@ pub fn foo(arr: &mut [u32]) { } } } - diff --git a/tests/codegen/slice-pointer-nonnull-unwrap.rs b/tests/codegen/slice-pointer-nonnull-unwrap.rs index 51ea4a1f943d6..48bf8fa88a06d 100644 --- a/tests/codegen/slice-pointer-nonnull-unwrap.rs +++ b/tests/codegen/slice-pointer-nonnull-unwrap.rs @@ -5,15 +5,15 @@ use std::ptr::NonNull; // CHECK-LABEL: @slice_ptr_len_1 -// CHECK: {{.*}}: +// CHECK-NEXT: {{.*}}: // CHECK-NEXT: ret i64 %ptr.1 #[no_mangle] pub fn slice_ptr_len_1(ptr: *const [u8]) -> usize { - let ptr = ptr.cast_mut(); - if let Some(ptr) = NonNull::new(ptr) { - ptr.len() - } else { - // We know ptr is null, so we know ptr.wrapping_byte_add(1) is not null. - NonNull::new(ptr.wrapping_byte_add(1)).unwrap().len() - } + let ptr = ptr.cast_mut(); + if let Some(ptr) = NonNull::new(ptr) { + ptr.len() + } else { + // We know ptr is null, so we know ptr.wrapping_byte_add(1) is not null. + NonNull::new(ptr.wrapping_byte_add(1)).unwrap().len() + } } From ab0f87ec66f104c300f0a2dfd95a8e30a770155d Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Tue, 11 Jun 2024 07:45:16 +0000 Subject: [PATCH 14/14] Fix tests for 32 bits targets --- .../issue-83585-small-pod-struct-equality.rs | 13 ++++++------- tests/codegen/issues/issue-109328-split_first.rs | 4 ++-- tests/codegen/issues/issue-110797-enum-jump-same.rs | 4 ++-- tests/codegen/slice-pointer-nonnull-unwrap.rs | 2 +- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/tests/assembly/issue-83585-small-pod-struct-equality.rs b/tests/assembly/issue-83585-small-pod-struct-equality.rs index 9b0d605666d6e..14bec1337f0bf 100644 --- a/tests/assembly/issue-83585-small-pod-struct-equality.rs +++ b/tests/assembly/issue-83585-small-pod-struct-equality.rs @@ -1,27 +1,26 @@ //@ assembly-output: emit-asm -//@ compile-flags:-Copt-level=3 +//@ compile-flags: -Copt-level=3 //@ only-x86_64 #![crate_type = "lib"] type T = u8; type T1 = (T, T, T, T, T, T, T, T); -type T2 = [T; 8]; // CHECK-LABEL: foo1a -// CHECK: cmp +// CHECK: cmpq // CHECK-NEXT: sete -// CHECK-NEXT: ret +// CHECK-NEXT: {{retq|popq}} #[no_mangle] pub fn foo1a(a: T1, b: T1) -> bool { a == b } // CHECK-LABEL: foo1b -// CHECK: mov -// CHECK-NEXT: cmp +// CHECK: movq +// CHECK: cmpq // CHECK-NEXT: sete -// CHECK-NEXT: ret +// CHECK-NEXT: {{retq|popq}} #[no_mangle] pub fn foo1b(a: &T1, b: &T1) -> bool { a == b diff --git a/tests/codegen/issues/issue-109328-split_first.rs b/tests/codegen/issues/issue-109328-split_first.rs index d3844c3ec20cc..7f7957593d2de 100644 --- a/tests/codegen/issues/issue-109328-split_first.rs +++ b/tests/codegen/issues/issue-109328-split_first.rs @@ -5,8 +5,8 @@ // CHECK-LABEL: @foo // CHECK-NEXT: {{.*}}: // CHECK-NEXT: getelementptr inbounds -// CHECK-NEXT: load i64 -// CHECK-NEXT: icmp eq i64 +// CHECK-NEXT: load [[TYPE:i(32|64)]] +// CHECK-NEXT: icmp eq [[TYPE]] // CHECK-NEXT: br i1 #[no_mangle] pub fn foo(input: &mut &[u64]) -> Option { diff --git a/tests/codegen/issues/issue-110797-enum-jump-same.rs b/tests/codegen/issues/issue-110797-enum-jump-same.rs index d52faef23ad8d..f34b191ac709e 100644 --- a/tests/codegen/issues/issue-110797-enum-jump-same.rs +++ b/tests/codegen/issues/issue-110797-enum-jump-same.rs @@ -13,8 +13,8 @@ pub enum K { // CHECK-LABEL: @get_len // CHECK-NEXT: {{.*}}: // CHECK-NEXT: getelementptr inbounds -// CHECK-NEXT: load -// CHECK-NEXT: ret i64 +// CHECK-NEXT: load [[TYPE:i(32|64)]] +// CHECK-NEXT: ret [[TYPE]] #[no_mangle] pub fn get_len(arg: &K) -> usize { match arg { diff --git a/tests/codegen/slice-pointer-nonnull-unwrap.rs b/tests/codegen/slice-pointer-nonnull-unwrap.rs index 48bf8fa88a06d..2c4a959685f96 100644 --- a/tests/codegen/slice-pointer-nonnull-unwrap.rs +++ b/tests/codegen/slice-pointer-nonnull-unwrap.rs @@ -6,7 +6,7 @@ use std::ptr::NonNull; // CHECK-LABEL: @slice_ptr_len_1 // CHECK-NEXT: {{.*}}: -// CHECK-NEXT: ret i64 %ptr.1 +// CHECK-NEXT: ret {{i(32|64)}} %ptr.1 #[no_mangle] pub fn slice_ptr_len_1(ptr: *const [u8]) -> usize { let ptr = ptr.cast_mut();