Skip to content

Commit a7103a0

Browse files
tesujinikic
andcommitted
Apply suggestions from code review
Co-authored-by: Nikita Popov <github@npopov.com>
1 parent 95740fb commit a7103a0

11 files changed

+33
-52
lines changed

tests/assembly/issue-83585-small-pod-struct-equality.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,25 @@
44

55
#![crate_type = "lib"]
66

7-
#[no_mangle]
87
type T = u8;
98
type T1 = (T, T, T, T, T, T, T, T);
109
type T2 = [T; 8];
1110

12-
#[no_mangle]
1311
// CHECK-LABEL: foo1a
1412
// CHECK: cmp
15-
// CHECK-NEXT: set
13+
// CHECK-NEXT: sete
1614
// CHECK-NEXT: ret
15+
#[no_mangle]
1716
pub fn foo1a(a: T1, b: T1) -> bool {
1817
a == b
1918
}
2019

21-
#[no_mangle]
2220
// CHECK-LABEL: foo1b
2321
// CHECK: mov
2422
// CHECK-NEXT: cmp
25-
// CHECK-NEXT: set
23+
// CHECK-NEXT: sete
2624
// CHECK-NEXT: ret
25+
#[no_mangle]
2726
pub fn foo1b(a: &T1, b: &T1) -> bool {
2827
a == b
2928
}
30-

tests/codegen/issues/issue-109328-split_first.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
//@ compile-flags: -O
2-
//@ min-llvm-version: 17
32

43
#![crate_type = "lib"]
54

6-
#[no_mangle]
75
// CHECK-LABEL: @foo
86
// CHECK: getelementptr inbounds
97
// CHECK-NEXT: load i64
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
//@ compile-flags: -O
2-
// XXX: The x86-64 assembly get optimized correclty. But llvm-ir output is not until llvm 18?
32
//@ min-llvm-version: 18
43

54
#![crate_type = "lib"]
65

7-
pub enum K{
6+
pub enum K {
87
A(Box<[i32]>),
98
B(Box<[u8]>),
109
C(Box<[String]>),
1110
D(Box<[u16]>),
1211
}
1312

14-
#[no_mangle]
1513
// CHECK-LABEL: @get_len
16-
// CHECK: getelementptr inbounds
14+
// CHECK-NEXT: {{.*}}:
15+
// CHECK-NEXT: getelementptr inbounds
1716
// CHECK-NEXT: load
1817
// CHECK-NEXT: ret i64
19-
// CHECK-NOT: switch
20-
pub fn get_len(arg: &K)->usize{
18+
#[no_mangle]
19+
pub fn get_len(arg: &K) -> usize {
2120
match arg {
22-
K::A(ref lst)=>lst.len(),
23-
K::B(ref lst)=>lst.len(),
24-
K::C(ref lst)=>lst.len(),
25-
K::D(ref lst)=>lst.len(),
21+
K::A(ref lst) => lst.len(),
22+
K::B(ref lst) => lst.len(),
23+
K::C(ref lst) => lst.len(),
24+
K::D(ref lst) => lst.len(),
2625
}
2726
}

tests/codegen/issues/issue-111508-vec-tryinto-array.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ use std::convert::TryInto;
88

99
const N: usize = 24;
1010

11-
#[no_mangle]
1211
// CHECK-LABEL: @example
1312
// CHECK-NOT: unwrap_failed
13+
#[no_mangle]
1414
pub fn example(a: Vec<u8>) -> u8 {
1515
if a.len() != 32 {
1616
return 0;

tests/codegen/issues/issue-112509-slice-get-andthen-get.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,7 @@
66
// CHECK: getelementptr
77
// CHECK-NEXT: icmp ugt
88
#[no_mangle]
9-
pub fn write_u8_variant_a(
10-
bytes: &mut [u8],
11-
buf: u8,
12-
offset: usize,
13-
) -> Option<&mut [u8]> {
9+
pub fn write_u8_variant_a(bytes: &mut [u8], buf: u8, offset: usize) -> Option<&mut [u8]> {
1410
let buf = buf.to_le_bytes();
15-
bytes
16-
.get_mut(offset..).and_then(|bytes| bytes.get_mut(..buf.len()))
11+
bytes.get_mut(offset..).and_then(|bytes| bytes.get_mut(..buf.len()))
1712
}

tests/codegen/issues/issue-113757-bounds-check-after-cmp-max.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
// in Rust 1.73, -O and opt-level=3 optimizes differently
22
//@ compile-flags: -C opt-level=3
3-
//@ min-llvm-version: 17
43
#![crate_type = "lib"]
54

65
use std::cmp::max;
76

8-
#[no_mangle]
97
// CHECK-LABEL: @foo
108
// CHECK-NOT: slice_start_index_len_fail
119
// CHECK-NOT: unreachable
12-
pub fn foo(v: &mut Vec<u8>, size: usize)-> Option<&mut [u8]> {
10+
#[no_mangle]
11+
pub fn foo(v: &mut Vec<u8>, size: usize) -> Option<&mut [u8]> {
1312
if v.len() > max(1, size) {
1413
let start = v.len() - size;
1514
Some(&mut v[start..])

tests/codegen/issues/issue-36010-some-box-is_some.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,21 @@ fn foo<T>(a: &mut T, b: T) -> bool {
88
let b = Some(mem::replace(a, b));
99
let ret = b.is_some();
1010
mem::forget(b);
11-
return ret
11+
return ret;
1212
}
1313

1414
// CHECK-LABEL: @foo_u32
1515
// CHECK: store i32
16-
// CHECK-NEXT: ret i1
16+
// CHECK-NEXT: ret i1 true
1717
#[no_mangle]
1818
pub fn foo_u32(a: &mut u32, b: u32) -> bool {
1919
foo(a, b)
2020
}
2121

2222
// CHECK-LABEL: @foo_box
2323
// CHECK: store ptr
24-
// CHECK-NEXT: ret i1
24+
// CHECK-NEXT: ret i1 true
2525
#[no_mangle]
2626
pub fn foo_box(a: &mut Box<u32>, b: Box<u32>) -> bool {
2727
foo(a, b)
2828
}
29-

tests/codegen/issues/issue-68667-unwrap-combinators.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,5 @@
1111
// CHECK-NEXT: ret i1
1212
#[no_mangle]
1313
pub fn unwrap_combinators(a: Option<i32>, b: i32) -> bool {
14-
a.map(|t| t >= b)
15-
.unwrap_or(false)
14+
a.map(|t| t >= b).unwrap_or(false)
1615
}
17-

tests/codegen/issues/issue-74938-array-split-at.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
const N: usize = 3;
66
pub type T = u8;
77

8-
#[no_mangle]
9-
// CHECK-LABEL: @split_mutiple
8+
// CHECK-LABEL: @split_multiple
109
// CHECK-NOT: unreachable
11-
pub fn split_mutiple(slice: &[T]) -> (&[T], &[T]) {
10+
#[no_mangle]
11+
pub fn split_multiple(slice: &[T]) -> (&[T], &[T]) {
1212
let len = slice.len() / N;
1313
slice.split_at(len * N)
1414
}
15-
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
//@ compile-flags: -O
2-
//@ min-llvm-version: 17
32

43
#![crate_type = "lib"]
54

65
#[no_mangle]
76
// CHECK-LABEL: @foo
8-
// CHECK: {{.*}}:
9-
// CHECK: ret
107
// CHECK-NOT: unreachable
118
pub fn foo(arr: &mut [u32]) {
129
for i in 0..arr.len() {
@@ -15,4 +12,3 @@ pub fn foo(arr: &mut [u32]) {
1512
}
1613
}
1714
}
18-

tests/codegen/slice-pointer-nonnull-unwrap.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
use std::ptr::NonNull;
66

77
// CHECK-LABEL: @slice_ptr_len_1
8-
// CHECK: {{.*}}:
8+
// CHECK-NEXT: {{.*}}:
99
// CHECK-NEXT: ret i64 %ptr.1
1010
#[no_mangle]
1111
pub fn slice_ptr_len_1(ptr: *const [u8]) -> usize {
12-
let ptr = ptr.cast_mut();
13-
if let Some(ptr) = NonNull::new(ptr) {
14-
ptr.len()
15-
} else {
16-
// We know ptr is null, so we know ptr.wrapping_byte_add(1) is not null.
17-
NonNull::new(ptr.wrapping_byte_add(1)).unwrap().len()
18-
}
12+
let ptr = ptr.cast_mut();
13+
if let Some(ptr) = NonNull::new(ptr) {
14+
ptr.len()
15+
} else {
16+
// We know ptr is null, so we know ptr.wrapping_byte_add(1) is not null.
17+
NonNull::new(ptr.wrapping_byte_add(1)).unwrap().len()
18+
}
1919
}

0 commit comments

Comments
 (0)