Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Nikita Popov <github@npopov.com>
  • Loading branch information
tesuji and nikic committed Jun 9, 2024
1 parent 95740fb commit a7103a0
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 52 deletions.
10 changes: 4 additions & 6 deletions tests/assembly/issue-83585-small-pod-struct-equality.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

2 changes: 0 additions & 2 deletions tests/codegen/issues/issue-109328-split_first.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
//@ compile-flags: -O
//@ min-llvm-version: 17

#![crate_type = "lib"]

#[no_mangle]
// CHECK-LABEL: @foo
// CHECK: getelementptr inbounds
// CHECK-NEXT: load i64
Expand Down
19 changes: 9 additions & 10 deletions tests/codegen/issues/issue-110797-enum-jump-same.rs
Original file line number Diff line number Diff line change
@@ -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(),
}
}
2 changes: 1 addition & 1 deletion tests/codegen/issues/issue-111508-vec-tryinto-array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>) -> u8 {
if a.len() != 32 {
return 0;
Expand Down
9 changes: 2 additions & 7 deletions tests/codegen/issues/issue-112509-slice-get-andthen-get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@
// CHECK: 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()))
}
Original file line number Diff line number Diff line change
@@ -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<u8>, size: usize)-> Option<&mut [u8]> {
#[no_mangle]
pub fn foo(v: &mut Vec<u8>, size: usize) -> Option<&mut [u8]> {
if v.len() > max(1, size) {
let start = v.len() - size;
Some(&mut v[start..])
Expand Down
7 changes: 3 additions & 4 deletions tests/codegen/issues/issue-36010-some-box-is_some.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,21 @@ fn foo<T>(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)
}

// 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<u32>, b: Box<u32>) -> bool {
foo(a, b)
}

4 changes: 1 addition & 3 deletions tests/codegen/issues/issue-68667-unwrap-combinators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@
// CHECK-NEXT: ret i1
#[no_mangle]
pub fn unwrap_combinators(a: Option<i32>, b: i32) -> bool {
a.map(|t| t >= b)
.unwrap_or(false)
a.map(|t| t >= b).unwrap_or(false)
}

7 changes: 3 additions & 4 deletions tests/codegen/issues/issue-74938-array-split-at.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

4 changes: 0 additions & 4 deletions tests/codegen/issues/issue-93036-assert-index.rs
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -15,4 +12,3 @@ pub fn foo(arr: &mut [u32]) {
}
}
}

16 changes: 8 additions & 8 deletions tests/codegen/slice-pointer-nonnull-unwrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

0 comments on commit a7103a0

Please sign in to comment.