Skip to content

Commit 56c78b2

Browse files
committed
Fix the test copy-intrinsic
1 parent 3a894e3 commit 56c78b2

File tree

2 files changed

+31
-50
lines changed

2 files changed

+31
-50
lines changed

src/test/ui/consts/copy-intrinsic.rs

+17-6
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,53 @@
1+
#![stable(feature = "dummy", since = "1.0.0")]
2+
13
// ignore-tidy-linelength
4+
#![feature(intrinsics, staged_api)]
25
#![feature(const_mut_refs, const_intrinsic_copy, const_ptr_offset)]
3-
use std::{ptr, mem};
6+
use std::mem;
7+
8+
extern "rust-intrinsic" {
9+
#[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")]
10+
fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
11+
12+
#[rustc_const_unstable(feature = "const_intrinsic_copy", issue = "80697")]
13+
fn copy<T>(src: *const T, dst: *mut T, count: usize);
14+
}
415

516
const COPY_ZERO: () = unsafe {
617
// Since we are not copying anything, this should be allowed.
718
let src = ();
819
let mut dst = ();
9-
ptr::copy_nonoverlapping(&src as *const _ as *const i32, &mut dst as *mut _ as *mut i32, 0);
20+
copy_nonoverlapping(&src as *const _ as *const i32, &mut dst as *mut _ as *mut i32, 0);
1021
};
1122

1223
const COPY_OOB_1: () = unsafe {
1324
let mut x = 0i32;
1425
let dangle = (&mut x as *mut i32).wrapping_add(10);
1526
// Even if the first ptr is an int ptr and this is a ZST copy, we should detect dangling 2nd ptrs.
16-
ptr::copy_nonoverlapping(0x100 as *const i32, dangle, 0); //~ ERROR any use of this value will cause an error
27+
copy_nonoverlapping(0x100 as *const i32, dangle, 0); //~ ERROR any use of this value will cause an error
1728
//~| memory access failed: pointer must be in-bounds
1829
//~| previously accepted
1930
};
2031
const COPY_OOB_2: () = unsafe {
2132
let x = 0i32;
2233
let dangle = (&x as *const i32).wrapping_add(10);
2334
// Even if the second ptr is an int ptr and this is a ZST copy, we should detect dangling 1st ptrs.
24-
ptr::copy_nonoverlapping(dangle, 0x100 as *mut i32, 0); //~ ERROR any use of this value will cause an error
35+
copy_nonoverlapping(dangle, 0x100 as *mut i32, 0); //~ ERROR any use of this value will cause an error
2536
//~| memory access failed: pointer must be in-bounds
2637
//~| previously accepted
2738
};
2839

2940
const COPY_SIZE_OVERFLOW: () = unsafe {
3041
let x = 0;
3142
let mut y = 0;
32-
ptr::copy(&x, &mut y, 1usize << (mem::size_of::<usize>() * 8 - 1)); //~ ERROR any use of this value will cause an error
43+
copy(&x, &mut y, 1usize << (mem::size_of::<usize>() * 8 - 1)); //~ ERROR any use of this value will cause an error
3344
//~| overflow computing total size of `copy`
3445
//~| previously accepted
3546
};
3647
const COPY_NONOVERLAPPING_SIZE_OVERFLOW: () = unsafe {
3748
let x = 0;
3849
let mut y = 0;
39-
ptr::copy_nonoverlapping(&x, &mut y, 1usize << (mem::size_of::<usize>() * 8 - 1)); //~ ERROR any use of this value will cause an error
50+
copy_nonoverlapping(&x, &mut y, 1usize << (mem::size_of::<usize>() * 8 - 1)); //~ ERROR any use of this value will cause an error
4051
//~| overflow computing total size of `copy_nonoverlapping`
4152
//~| previously accepted
4253
};

src/test/ui/consts/copy-intrinsic.stderr

+14-44
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
error: any use of this value will cause an error
2-
--> $SRC_DIR/core/src/intrinsics.rs:LL:COL
3-
|
4-
LL | unsafe { copy_nonoverlapping(src, dst, count) }
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6-
| |
7-
| memory access failed: pointer must be in-bounds at offset 40, but is outside bounds of alloc4 which has size 4
8-
| inside `copy_nonoverlapping::<i32>` at $SRC_DIR/core/src/intrinsics.rs:LL:COL
9-
| inside `COPY_OOB_1` at $DIR/copy-intrinsic.rs:16:5
10-
|
11-
::: $DIR/copy-intrinsic.rs:12:1
2+
--> $DIR/copy-intrinsic.rs:27:5
123
|
134
LL | / const COPY_OOB_1: () = unsafe {
145
LL | | let mut x = 0i32;
156
LL | | let dangle = (&mut x as *mut i32).wrapping_add(10);
167
LL | | // Even if the first ptr is an int ptr and this is a ZST copy, we should detect dangling 2nd ptrs.
17-
... |
8+
LL | | copy_nonoverlapping(0x100 as *const i32, dangle, 0);
9+
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: pointer must be in-bounds at offset 40, but is outside bounds of alloc4 which has size 4
10+
LL | |
1811
LL | |
1912
LL | | };
2013
| |__-
@@ -24,22 +17,15 @@ LL | | };
2417
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
2518

2619
error: any use of this value will cause an error
27-
--> $SRC_DIR/core/src/intrinsics.rs:LL:COL
28-
|
29-
LL | unsafe { copy_nonoverlapping(src, dst, count) }
30-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
31-
| |
32-
| memory access failed: pointer must be in-bounds at offset 40, but is outside bounds of alloc6 which has size 4
33-
| inside `copy_nonoverlapping::<i32>` at $SRC_DIR/core/src/intrinsics.rs:LL:COL
34-
| inside `COPY_OOB_2` at $DIR/copy-intrinsic.rs:24:5
35-
|
36-
::: $DIR/copy-intrinsic.rs:20:1
20+
--> $DIR/copy-intrinsic.rs:35:5
3721
|
3822
LL | / const COPY_OOB_2: () = unsafe {
3923
LL | | let x = 0i32;
4024
LL | | let dangle = (&x as *const i32).wrapping_add(10);
4125
LL | | // Even if the second ptr is an int ptr and this is a ZST copy, we should detect dangling 1st ptrs.
42-
... |
26+
LL | | copy_nonoverlapping(dangle, 0x100 as *mut i32, 0);
27+
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ memory access failed: pointer must be in-bounds at offset 40, but is outside bounds of alloc6 which has size 4
28+
LL | |
4329
LL | |
4430
LL | | };
4531
| |__-
@@ -48,21 +34,13 @@ LL | | };
4834
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
4935

5036
error: any use of this value will cause an error
51-
--> $SRC_DIR/core/src/intrinsics.rs:LL:COL
52-
|
53-
LL | unsafe { copy(src, dst, count) }
54-
| ^^^^^^^^^^^^^^^^^^^^^
55-
| |
56-
| overflow computing total size of `copy`
57-
| inside `std::intrinsics::copy::<i32>` at $SRC_DIR/core/src/intrinsics.rs:LL:COL
58-
| inside `COPY_SIZE_OVERFLOW` at $DIR/copy-intrinsic.rs:32:5
59-
|
60-
::: $DIR/copy-intrinsic.rs:29:1
37+
--> $DIR/copy-intrinsic.rs:43:5
6138
|
6239
LL | / const COPY_SIZE_OVERFLOW: () = unsafe {
6340
LL | | let x = 0;
6441
LL | | let mut y = 0;
65-
LL | | ptr::copy(&x, &mut y, 1usize << (mem::size_of::<usize>() * 8 - 1));
42+
LL | | copy(&x, &mut y, 1usize << (mem::size_of::<usize>() * 8 - 1));
43+
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ overflow computing total size of `copy`
6644
LL | |
6745
LL | |
6846
LL | | };
@@ -72,21 +50,13 @@ LL | | };
7250
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
7351

7452
error: any use of this value will cause an error
75-
--> $SRC_DIR/core/src/intrinsics.rs:LL:COL
76-
|
77-
LL | unsafe { copy_nonoverlapping(src, dst, count) }
78-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
79-
| |
80-
| overflow computing total size of `copy_nonoverlapping`
81-
| inside `copy_nonoverlapping::<i32>` at $SRC_DIR/core/src/intrinsics.rs:LL:COL
82-
| inside `COPY_NONOVERLAPPING_SIZE_OVERFLOW` at $DIR/copy-intrinsic.rs:39:5
83-
|
84-
::: $DIR/copy-intrinsic.rs:36:1
53+
--> $DIR/copy-intrinsic.rs:50:5
8554
|
8655
LL | / const COPY_NONOVERLAPPING_SIZE_OVERFLOW: () = unsafe {
8756
LL | | let x = 0;
8857
LL | | let mut y = 0;
89-
LL | | ptr::copy_nonoverlapping(&x, &mut y, 1usize << (mem::size_of::<usize>() * 8 - 1));
58+
LL | | copy_nonoverlapping(&x, &mut y, 1usize << (mem::size_of::<usize>() * 8 - 1));
59+
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ overflow computing total size of `copy_nonoverlapping`
9060
LL | |
9161
LL | |
9262
LL | | };

0 commit comments

Comments
 (0)