Skip to content

Commit

Permalink
add oversized-ref test back
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Oct 16, 2023
1 parent 28b0c87 commit 1ac153f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 8 additions & 0 deletions tests/ui/consts/extra-const-ub/detect-extra-ub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,12 @@ const VALID_ENUM2: Result<&'static [u8], ()> = { let e = Err(()); e };
// Htting the (non-integer) array code in validation with an immediate local.
const VALID_ARRAY: [Option<i32>; 0] = { let e = [None; 0]; e };

// Detecting oversized references.
const OVERSIZED_REF: () = { unsafe {
let slice: *const [u8] = transmute((1usize, usize::MAX));
let _val = &*slice;
//[with_flag]~^ ERROR: evaluation of constant value failed
//[with_flag]~| slice is bigger than largest supported object
} };

fn main() {}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ LL | let _val = *(&mem as *const Align as *const [*const u8; 2]);
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported

error: aborting due to 7 previous errors
error[E0080]: evaluation of constant value failed
--> $DIR/detect-extra-ub.rs:97:16
|
LL | let _val = &*slice;
| ^^^^^^^ constructing invalid value: encountered invalid reference metadata: slice is bigger than largest supported object

error: aborting due to 8 previous errors

For more information about this error, try `rustc --explain E0080`.

0 comments on commit 1ac153f

Please sign in to comment.