|
1 | 1 | // compile-flags: --crate-type=lib
|
2 |
| -// normalize-stderr-32bit: "8 bytes" -> "$$TWO_WORDS bytes" |
3 |
| -// normalize-stderr-64bit: "16 bytes" -> "$$TWO_WORDS bytes" |
4 |
| -// normalize-stderr-32bit: "size 4" -> "size $$WORD" |
5 |
| -// normalize-stderr-64bit: "size 8" -> "size $$WORD" |
| 2 | +// check-pass |
6 | 3 |
|
7 | 4 | #![feature(
|
8 | 5 | core_intrinsics,
|
@@ -34,30 +31,13 @@ check!(ne, unsafe { (FOO as *const usize as *const u8).offset(3) }, 0);
|
34 | 31 |
|
35 | 32 | // We want pointers to be equal to themselves, but aren't checking this yet because
|
36 | 33 | // there are some open questions (e.g. whether function pointers to the same function
|
37 |
| -// compare equal, they don't necessarily at runtime). |
38 |
| -// The case tested here should work eventually, but does not work yet. |
| 34 | +// compare equal: they don't necessarily do at runtime). |
39 | 35 | check!(!, FOO as *const _, FOO as *const _);
|
40 | 36 |
|
| 37 | +// aside from 0, these pointers might end up pretty much anywhere. |
| 38 | +check!(!, FOO as *const _, 1); // this one could be `ne` by taking into account alignment |
| 39 | +check!(!, FOO as *const _, 1024); |
41 | 40 |
|
42 |
| -/////////////////////////////////////////////////////////////////////////////// |
43 |
| -// If any of the below start compiling, make sure to add a `check` test for it. |
44 |
| -// These invocations exist as canaries so we don't forget to check that the |
45 |
| -// behaviour of `guaranteed_eq` and `guaranteed_ne` is still correct. |
46 |
| -// All of these try to obtain an out of bounds pointer in some manner. If we |
47 |
| -// can create out of bounds pointers, we can offset a pointer far enough that |
48 |
| -// at runtime it would be zero and at compile-time it would not be zero. |
49 |
| - |
50 |
| -const _: *const usize = unsafe { (FOO as *const usize).offset(2) }; |
51 |
| - |
52 |
| -const _: *const u8 = |
53 |
| - unsafe { std::ptr::addr_of!((*(FOO as *const usize as *const [u8; 1000]))[999]) }; |
54 |
| -//~^ ERROR evaluation of constant value failed |
55 |
| -//~| out-of-bounds |
56 |
| - |
57 |
| -const _: usize = unsafe { std::mem::transmute::<*const usize, usize>(FOO) + 4 }; |
58 |
| -//~^ ERROR evaluation of constant value failed |
59 |
| -//~| unable to turn pointer into raw bytes |
60 |
| - |
61 |
| -const _: usize = unsafe { *std::mem::transmute::<&&usize, &usize>(&FOO) + 4 }; |
62 |
| -//~^ ERROR evaluation of constant value failed |
63 |
| -//~| unable to turn pointer into raw bytes |
| 41 | +// When pointers go out-of-bounds, they *might* become null, so these comparions cannot work. |
| 42 | +check!(!, unsafe { (FOO as *const usize).wrapping_add(2) }, 0); |
| 43 | +check!(!, unsafe { (FOO as *const usize).wrapping_sub(1) }, 0); |
0 commit comments