Skip to content

Stop checking for the absence of something that doesn't exist #111525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion tests/codegen/binary-search-index-no-bound-check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
#[no_mangle]
pub fn binary_search_index_no_bounds_check(s: &[u8]) -> u8 {
// CHECK-NOT: panic
// CHECK-NOT: slice_index_len_fail
// CHECK-NOT: slice_start_index_len_fail
// CHECK-NOT: slice_end_index_len_fail
// CHECK-NOT: panic_bounds_check
if let Ok(idx) = s.binary_search(&b'\\') {
s[idx]
} else {
Expand Down
30 changes: 24 additions & 6 deletions tests/codegen/issues/issue-73396-bounds-check-after-position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
#[no_mangle]
pub fn position_slice_to_no_bounds_check(s: &[u8]) -> &[u8] {
// CHECK-NOT: panic
// CHECK-NOT: slice_index_len_fail
// CHECK-NOT: slice_start_index_len_fail
// CHECK-NOT: slice_end_index_len_fail
// CHECK-NOT: panic_bounds_check
// CHECK-NOT: unreachable
if let Some(idx) = s.iter().position(|b| *b == b'\\') {
&s[..idx]
} else {
Expand All @@ -21,7 +24,10 @@ pub fn position_slice_to_no_bounds_check(s: &[u8]) -> &[u8] {
#[no_mangle]
pub fn position_slice_from_no_bounds_check(s: &[u8]) -> &[u8] {
// CHECK-NOT: panic
// CHECK-NOT: slice_index_len_fail
// CHECK-NOT: slice_start_index_len_fail
// CHECK-NOT: slice_end_index_len_fail
// CHECK-NOT: panic_bounds_check
// CHECK-NOT: unreachable
if let Some(idx) = s.iter().position(|b| *b == b'\\') {
&s[idx..]
} else {
Expand All @@ -33,7 +39,10 @@ pub fn position_slice_from_no_bounds_check(s: &[u8]) -> &[u8] {
#[no_mangle]
pub fn position_index_no_bounds_check(s: &[u8]) -> u8 {
// CHECK-NOT: panic
// CHECK-NOT: slice_index_len_fail
// CHECK-NOT: slice_start_index_len_fail
// CHECK-NOT: slice_end_index_len_fail
// CHECK-NOT: panic_bounds_check
// CHECK-NOT: unreachable
if let Some(idx) = s.iter().position(|b| *b == b'\\') {
s[idx]
} else {
Expand All @@ -44,7 +53,10 @@ pub fn position_index_no_bounds_check(s: &[u8]) -> u8 {
#[no_mangle]
pub fn rposition_slice_to_no_bounds_check(s: &[u8]) -> &[u8] {
// CHECK-NOT: panic
// CHECK-NOT: slice_index_len_fail
// CHECK-NOT: slice_start_index_len_fail
// CHECK-NOT: slice_end_index_len_fail
// CHECK-NOT: panic_bounds_check
// CHECK-NOT: unreachable
if let Some(idx) = s.iter().rposition(|b| *b == b'\\') {
&s[..idx]
} else {
Expand All @@ -56,7 +68,10 @@ pub fn rposition_slice_to_no_bounds_check(s: &[u8]) -> &[u8] {
#[no_mangle]
pub fn rposition_slice_from_no_bounds_check(s: &[u8]) -> &[u8] {
// CHECK-NOT: panic
// CHECK-NOT: slice_index_len_fail
// CHECK-NOT: slice_start_index_len_fail
// CHECK-NOT: slice_end_index_len_fail
// CHECK-NOT: panic_bounds_check
// CHECK-NOT: unreachable
if let Some(idx) = s.iter().rposition(|b| *b == b'\\') {
&s[idx..]
} else {
Expand All @@ -68,7 +83,10 @@ pub fn rposition_slice_from_no_bounds_check(s: &[u8]) -> &[u8] {
#[no_mangle]
pub fn rposition_index_no_bounds_check(s: &[u8]) -> u8 {
// CHECK-NOT: panic
// CHECK-NOT: slice_index_len_fail
// CHECK-NOT: slice_start_index_len_fail
// CHECK-NOT: slice_end_index_len_fail
// CHECK-NOT: panic_bounds_check
// CHECK-NOT: unreachable
if let Some(idx) = s.iter().rposition(|b| *b == b'\\') {
s[idx]
} else {
Expand Down