Skip to content

Commit d2ba571

Browse files
authoredAug 29, 2019
Rollup merge of rust-lang#63880 - RalfJung:miri-meta, r=oli-obk
Validation: check raw wide pointer metadata While I was at it, I also added a missing check for slices not to be too big. r? @oli-obk Fixes rust-lang/miri#918
2 parents e4e6b01 + 04580b6 commit d2ba571

File tree

3 files changed

+177
-101
lines changed

3 files changed

+177
-101
lines changed
 

‎src/librustc_mir/interpret/validity.rs

+54-35
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::hash::Hash;
1111

1212
use super::{
1313
GlobalAlloc, InterpResult,
14-
OpTy, Machine, InterpCx, ValueVisitor, MPlaceTy,
14+
Scalar, OpTy, Machine, InterpCx, ValueVisitor, MPlaceTy,
1515
};
1616

1717
macro_rules! throw_validation_failure {
@@ -250,6 +250,47 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, 'tcx, M
250250
self.path.truncate(path_len);
251251
Ok(())
252252
}
253+
254+
fn check_wide_ptr_meta(
255+
&mut self,
256+
meta: Option<Scalar<M::PointerTag>>,
257+
pointee: TyLayout<'tcx>,
258+
) -> InterpResult<'tcx> {
259+
let tail = self.ecx.tcx.struct_tail_erasing_lifetimes(pointee.ty, self.ecx.param_env);
260+
match tail.sty {
261+
ty::Dynamic(..) => {
262+
let vtable = meta.unwrap();
263+
try_validation!(
264+
self.ecx.memory.check_ptr_access(
265+
vtable,
266+
3*self.ecx.tcx.data_layout.pointer_size, // drop, size, align
267+
self.ecx.tcx.data_layout.pointer_align.abi,
268+
),
269+
"dangling or unaligned vtable pointer in wide pointer or too small vtable",
270+
self.path
271+
);
272+
try_validation!(self.ecx.read_drop_type_from_vtable(vtable),
273+
"invalid drop fn in vtable", self.path);
274+
try_validation!(self.ecx.read_size_and_align_from_vtable(vtable),
275+
"invalid size or align in vtable", self.path);
276+
// FIXME: More checks for the vtable.
277+
}
278+
ty::Slice(..) | ty::Str => {
279+
let _len = try_validation!(meta.unwrap().to_usize(self.ecx),
280+
"non-integer slice length in wide pointer", self.path);
281+
// We do not check that `len * elem_size <= isize::MAX`:
282+
// that is only required for references, and there it falls out of the
283+
// "dereferencable" check performed by Stacked Borrows.
284+
}
285+
ty::Foreign(..) => {
286+
// Unsized, but not wide.
287+
}
288+
_ =>
289+
bug!("Unexpected unsized type tail: {:?}", tail),
290+
}
291+
292+
Ok(())
293+
}
253294
}
254295

255296
impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
@@ -341,56 +382,34 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
341382
}
342383
}
343384
ty::RawPtr(..) => {
385+
// Check pointer part.
344386
if self.ref_tracking_for_consts.is_some() {
345387
// Integers/floats in CTFE: For consistency with integers, we do not
346388
// accept undef.
347389
let _ptr = try_validation!(value.to_scalar_ptr(),
348390
"undefined address in raw pointer", self.path);
349-
let _meta = try_validation!(value.to_meta(),
350-
"uninitialized data in raw fat pointer metadata", self.path);
351391
} else {
352392
// Remain consistent with `usize`: Accept anything.
353393
}
394+
395+
// Check metadata.
396+
let meta = try_validation!(value.to_meta(),
397+
"uninitialized data in wide pointer metadata", self.path);
398+
let layout = self.ecx.layout_of(value.layout.ty.builtin_deref(true).unwrap().ty)?;
399+
if layout.is_unsized() {
400+
self.check_wide_ptr_meta(meta, layout)?;
401+
}
354402
}
355403
_ if ty.is_box() || ty.is_region_ptr() => {
356-
// Handle fat pointers.
404+
// Handle wide pointers.
357405
// Check metadata early, for better diagnostics
358406
let ptr = try_validation!(value.to_scalar_ptr(),
359407
"undefined address in pointer", self.path);
360408
let meta = try_validation!(value.to_meta(),
361-
"uninitialized data in fat pointer metadata", self.path);
409+
"uninitialized data in wide pointer metadata", self.path);
362410
let layout = self.ecx.layout_of(value.layout.ty.builtin_deref(true).unwrap().ty)?;
363411
if layout.is_unsized() {
364-
let tail = self.ecx.tcx.struct_tail_erasing_lifetimes(layout.ty,
365-
self.ecx.param_env);
366-
match tail.sty {
367-
ty::Dynamic(..) => {
368-
let vtable = meta.unwrap();
369-
try_validation!(
370-
self.ecx.memory.check_ptr_access(
371-
vtable,
372-
3*self.ecx.tcx.data_layout.pointer_size, // drop, size, align
373-
self.ecx.tcx.data_layout.pointer_align.abi,
374-
),
375-
"dangling or unaligned vtable pointer or too small vtable",
376-
self.path
377-
);
378-
try_validation!(self.ecx.read_drop_type_from_vtable(vtable),
379-
"invalid drop fn in vtable", self.path);
380-
try_validation!(self.ecx.read_size_and_align_from_vtable(vtable),
381-
"invalid size or align in vtable", self.path);
382-
// FIXME: More checks for the vtable.
383-
}
384-
ty::Slice(..) | ty::Str => {
385-
try_validation!(meta.unwrap().to_usize(self.ecx),
386-
"non-integer slice length in fat pointer", self.path);
387-
}
388-
ty::Foreign(..) => {
389-
// Unsized, but not fat.
390-
}
391-
_ =>
392-
bug!("Unexpected unsized type tail: {:?}", tail),
393-
}
412+
self.check_wide_ptr_meta(meta, layout)?;
394413
}
395414
// Make sure this is dereferencable and all.
396415
let (size, align) = self.ecx.size_and_align_of(meta, layout)?

‎src/test/ui/consts/const-eval/union-ub-fat-ptr.rs ‎src/test/ui/consts/const-eval/ub-wide-ptr.rs

+49-24
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// ignore-tidy-linelength
12
#![allow(unused)]
23
#![allow(const_err)] // make sure we cannot allow away the errors tested here
34

@@ -28,7 +29,9 @@ struct BadSliceRepr {
2829
union SliceTransmute {
2930
repr: SliceRepr,
3031
bad: BadSliceRepr,
32+
addr: usize,
3133
slice: &'static [u8],
34+
raw_slice: *const [u8],
3235
str: &'static str,
3336
my_str: &'static MyStr,
3437
my_slice: &'static MySliceBool,
@@ -59,7 +62,9 @@ union DynTransmute {
5962
repr: DynRepr,
6063
repr2: DynRepr2,
6164
bad: BadDynRepr,
65+
addr: usize,
6266
rust: &'static dyn Trait,
67+
raw_rust: *const dyn Trait,
6368
}
6469

6570
trait Trait {}
@@ -72,39 +77,37 @@ struct MyStr(str);
7277
struct MySlice<T: ?Sized>(bool, T);
7378
type MySliceBool = MySlice<[bool]>;
7479

80+
// # str
7581
// OK
76-
const A: &str = unsafe { SliceTransmute { repr: SliceRepr { ptr: &42, len: 1 } }.str};
82+
const STR_VALID: &str = unsafe { SliceTransmute { repr: SliceRepr { ptr: &42, len: 1 } }.str};
7783
// bad str
78-
const B: &str = unsafe { SliceTransmute { repr: SliceRepr { ptr: &42, len: 999 } }.str};
84+
const STR_TOO_LONG: &str = unsafe { SliceTransmute { repr: SliceRepr { ptr: &42, len: 999 } }.str};
7985
//~^ ERROR it is undefined behavior to use this value
8086
// bad str
81-
const C: &str = unsafe { SliceTransmute { bad: BadSliceRepr { ptr: &42, len: &3 } }.str};
87+
const STR_LENGTH_PTR: &str = unsafe { SliceTransmute { bad: BadSliceRepr { ptr: &42, len: &3 } }.str};
8288
//~^ ERROR it is undefined behavior to use this value
8389
// bad str in user-defined unsized type
84-
const C2: &MyStr = unsafe { SliceTransmute { bad: BadSliceRepr { ptr: &42, len: &3 } }.my_str};
90+
const MY_STR_LENGTH_PTR: &MyStr = unsafe { SliceTransmute { bad: BadSliceRepr { ptr: &42, len: &3 } }.my_str};
8591
//~^ ERROR it is undefined behavior to use this value
8692

87-
// OK
88-
const A2: &[u8] = unsafe { SliceTransmute { repr: SliceRepr { ptr: &42, len: 1 } }.slice};
89-
// bad slice
90-
const B2: &[u8] = unsafe { SliceTransmute { repr: SliceRepr { ptr: &42, len: 999 } }.slice};
93+
// invalid UTF-8
94+
const J1: &str = unsafe { SliceTransmute { slice: &[0xFF] }.str };
9195
//~^ ERROR it is undefined behavior to use this value
92-
// bad slice
93-
const C3: &[u8] = unsafe { SliceTransmute { bad: BadSliceRepr { ptr: &42, len: &3 } }.slice};
96+
// invalid UTF-8 in user-defined str-like
97+
const J2: &MyStr = unsafe { SliceTransmute { slice: &[0xFF] }.my_str };
9498
//~^ ERROR it is undefined behavior to use this value
9599

96-
// bad trait object
97-
const D: &dyn Trait = unsafe { DynTransmute { repr: DynRepr { ptr: &92, vtable: &3 } }.rust};
98-
//~^ ERROR it is undefined behavior to use this value
99-
// bad trait object
100-
const E: &dyn Trait = unsafe { DynTransmute { repr2: DynRepr2 { ptr: &92, vtable: &3 } }.rust};
100+
// # slice
101+
// OK
102+
const SLICE_VALID: &[u8] = unsafe { SliceTransmute { repr: SliceRepr { ptr: &42, len: 1 } }.slice};
103+
// bad slice: length uninit
104+
const SLICE_LENGTH_UNINIT: &[u8] = unsafe { SliceTransmute { addr: 42 }.slice};
101105
//~^ ERROR it is undefined behavior to use this value
102-
// bad trait object
103-
const F: &dyn Trait = unsafe { DynTransmute { bad: BadDynRepr { ptr: &92, vtable: 3 } }.rust};
106+
// bad slice: length too big
107+
const SLICE_TOO_LONG: &[u8] = unsafe { SliceTransmute { repr: SliceRepr { ptr: &42, len: 999 } }.slice};
104108
//~^ ERROR it is undefined behavior to use this value
105-
106-
// bad data *inside* the trait object
107-
const G: &dyn Trait = &unsafe { BoolTransmute { val: 3 }.bl };
109+
// bad slice: length not an int
110+
const SLICE_LENGTH_PTR: &[u8] = unsafe { SliceTransmute { bad: BadSliceRepr { ptr: &42, len: &3 } }.slice};
108111
//~^ ERROR it is undefined behavior to use this value
109112

110113
// bad data *inside* the slice
@@ -120,12 +123,34 @@ const I2: &MySliceBool = &MySlice(unsafe { BoolTransmute { val: 3 }.bl }, [false
120123
const I3: &MySliceBool = &MySlice(true, [unsafe { BoolTransmute { val: 3 }.bl }]);
121124
//~^ ERROR it is undefined behavior to use this value
122125

123-
// invalid UTF-8
124-
const J1: &str = unsafe { SliceTransmute { slice: &[0xFF] }.str };
126+
// # raw slice
127+
const RAW_SLICE_VALID: *const [u8] = unsafe { SliceTransmute { repr: SliceRepr { ptr: &42, len: 1 } }.raw_slice}; // ok
128+
const RAW_SLICE_TOO_LONG: *const [u8] = unsafe { SliceTransmute { repr: SliceRepr { ptr: &42, len: 999 } }.raw_slice}; // ok because raw
129+
const RAW_SLICE_MUCH_TOO_LONG: *const [u8] = unsafe { SliceTransmute { repr: SliceRepr { ptr: &42, len: usize::max_value() } }.raw_slice}; // ok because raw
130+
const RAW_SLICE_LENGTH_UNINIT: *const [u8] = unsafe { SliceTransmute { addr: 42 }.raw_slice};
125131
//~^ ERROR it is undefined behavior to use this value
126-
// invalid UTF-8 in user-defined str-like
127-
const J2: &MyStr = unsafe { SliceTransmute { slice: &[0xFF] }.my_str };
132+
133+
// # trait object
134+
// bad trait object
135+
const D: &dyn Trait = unsafe { DynTransmute { repr: DynRepr { ptr: &92, vtable: &3 } }.rust};
136+
//~^ ERROR it is undefined behavior to use this value
137+
// bad trait object
138+
const E: &dyn Trait = unsafe { DynTransmute { repr2: DynRepr2 { ptr: &92, vtable: &3 } }.rust};
139+
//~^ ERROR it is undefined behavior to use this value
140+
// bad trait object
141+
const F: &dyn Trait = unsafe { DynTransmute { bad: BadDynRepr { ptr: &92, vtable: 3 } }.rust};
142+
//~^ ERROR it is undefined behavior to use this value
143+
144+
// bad data *inside* the trait object
145+
const G: &dyn Trait = &unsafe { BoolTransmute { val: 3 }.bl };
146+
//~^ ERROR it is undefined behavior to use this value
147+
148+
// # raw trait object
149+
const RAW_TRAIT_OBJ_VTABLE_NULL: *const dyn Trait = unsafe { DynTransmute { bad: BadDynRepr { ptr: &92, vtable: 0 } }.rust};
150+
//~^ ERROR it is undefined behavior to use this value
151+
const RAW_TRAIT_OBJ_VTABLE_INVALID: *const dyn Trait = unsafe { DynTransmute { repr2: DynRepr2 { ptr: &92, vtable: &3 } }.raw_rust};
128152
//~^ ERROR it is undefined behavior to use this value
153+
const RAW_TRAIT_OBJ_CONTENT_INVALID: *const dyn Trait = &unsafe { BoolTransmute { val: 3 }.bl } as *const _; // ok because raw
129154

130155
fn main() {
131156
}
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,147 @@
11
error[E0080]: it is undefined behavior to use this value
2-
--> $DIR/union-ub-fat-ptr.rs:78:1
2+
--> $DIR/ub-wide-ptr.rs:84:1
33
|
4-
LL | const B: &str = unsafe { SliceTransmute { repr: SliceRepr { ptr: &42, len: 999 } }.str};
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered dangling reference (not entirely in bounds)
4+
LL | const STR_TOO_LONG: &str = unsafe { SliceTransmute { repr: SliceRepr { ptr: &42, len: 999 } }.str};
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered dangling reference (not entirely in bounds)
66
|
77
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
88

99
error[E0080]: it is undefined behavior to use this value
10-
--> $DIR/union-ub-fat-ptr.rs:81:1
10+
--> $DIR/ub-wide-ptr.rs:87:1
1111
|
12-
LL | const C: &str = unsafe { SliceTransmute { bad: BadSliceRepr { ptr: &42, len: &3 } }.str};
13-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered non-integer slice length in fat pointer
12+
LL | const STR_LENGTH_PTR: &str = unsafe { SliceTransmute { bad: BadSliceRepr { ptr: &42, len: &3 } }.str};
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered non-integer slice length in wide pointer
1414
|
1515
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
1616

1717
error[E0080]: it is undefined behavior to use this value
18-
--> $DIR/union-ub-fat-ptr.rs:84:1
18+
--> $DIR/ub-wide-ptr.rs:90:1
1919
|
20-
LL | const C2: &MyStr = unsafe { SliceTransmute { bad: BadSliceRepr { ptr: &42, len: &3 } }.my_str};
21-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered non-integer slice length in fat pointer
20+
LL | const MY_STR_LENGTH_PTR: &MyStr = unsafe { SliceTransmute { bad: BadSliceRepr { ptr: &42, len: &3 } }.my_str};
21+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered non-integer slice length in wide pointer
2222
|
2323
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
2424

2525
error[E0080]: it is undefined behavior to use this value
26-
--> $DIR/union-ub-fat-ptr.rs:90:1
26+
--> $DIR/ub-wide-ptr.rs:94:1
2727
|
28-
LL | const B2: &[u8] = unsafe { SliceTransmute { repr: SliceRepr { ptr: &42, len: 999 } }.slice};
29-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered dangling reference (not entirely in bounds)
30-
|
31-
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
32-
33-
error[E0080]: it is undefined behavior to use this value
34-
--> $DIR/union-ub-fat-ptr.rs:93:1
35-
|
36-
LL | const C3: &[u8] = unsafe { SliceTransmute { bad: BadSliceRepr { ptr: &42, len: &3 } }.slice};
37-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered non-integer slice length in fat pointer
28+
LL | const J1: &str = unsafe { SliceTransmute { slice: &[0xFF] }.str };
29+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered uninitialized or non-UTF-8 data in str at .<deref>
3830
|
3931
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
4032

4133
error[E0080]: it is undefined behavior to use this value
42-
--> $DIR/union-ub-fat-ptr.rs:97:1
34+
--> $DIR/ub-wide-ptr.rs:97:1
4335
|
44-
LL | const D: &dyn Trait = unsafe { DynTransmute { repr: DynRepr { ptr: &92, vtable: &3 } }.rust};
45-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered dangling or unaligned vtable pointer or too small vtable
36+
LL | const J2: &MyStr = unsafe { SliceTransmute { slice: &[0xFF] }.my_str };
37+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered uninitialized or non-UTF-8 data in str at .<deref>.0
4638
|
4739
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
4840

4941
error[E0080]: it is undefined behavior to use this value
50-
--> $DIR/union-ub-fat-ptr.rs:100:1
42+
--> $DIR/ub-wide-ptr.rs:104:1
5143
|
52-
LL | const E: &dyn Trait = unsafe { DynTransmute { repr2: DynRepr2 { ptr: &92, vtable: &3 } }.rust};
53-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered dangling or unaligned vtable pointer or too small vtable
44+
LL | const SLICE_LENGTH_UNINIT: &[u8] = unsafe { SliceTransmute { addr: 42 }.slice};
45+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered uninitialized data in wide pointer metadata
5446
|
5547
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
5648

5749
error[E0080]: it is undefined behavior to use this value
58-
--> $DIR/union-ub-fat-ptr.rs:103:1
50+
--> $DIR/ub-wide-ptr.rs:107:1
5951
|
60-
LL | const F: &dyn Trait = unsafe { DynTransmute { bad: BadDynRepr { ptr: &92, vtable: 3 } }.rust};
61-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered dangling or unaligned vtable pointer or too small vtable
52+
LL | const SLICE_TOO_LONG: &[u8] = unsafe { SliceTransmute { repr: SliceRepr { ptr: &42, len: 999 } }.slice};
53+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered dangling reference (not entirely in bounds)
6254
|
6355
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
6456

6557
error[E0080]: it is undefined behavior to use this value
66-
--> $DIR/union-ub-fat-ptr.rs:107:1
58+
--> $DIR/ub-wide-ptr.rs:110:1
6759
|
68-
LL | const G: &dyn Trait = &unsafe { BoolTransmute { val: 3 }.bl };
69-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 3 at .<deref>.<dyn-downcast>, but expected something less or equal to 1
60+
LL | const SLICE_LENGTH_PTR: &[u8] = unsafe { SliceTransmute { bad: BadSliceRepr { ptr: &42, len: &3 } }.slice};
61+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered non-integer slice length in wide pointer
7062
|
7163
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
7264

7365
error[E0080]: it is undefined behavior to use this value
74-
--> $DIR/union-ub-fat-ptr.rs:111:1
66+
--> $DIR/ub-wide-ptr.rs:114:1
7567
|
7668
LL | const H: &[bool] = &[unsafe { BoolTransmute { val: 3 }.bl }];
7769
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 3 at .<deref>[0], but expected something less or equal to 1
7870
|
7971
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
8072

8173
error[E0080]: it is undefined behavior to use this value
82-
--> $DIR/union-ub-fat-ptr.rs:117:1
74+
--> $DIR/ub-wide-ptr.rs:120:1
8375
|
8476
LL | const I2: &MySliceBool = &MySlice(unsafe { BoolTransmute { val: 3 }.bl }, [false]);
8577
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 3 at .<deref>.0, but expected something less or equal to 1
8678
|
8779
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
8880

8981
error[E0080]: it is undefined behavior to use this value
90-
--> $DIR/union-ub-fat-ptr.rs:120:1
82+
--> $DIR/ub-wide-ptr.rs:123:1
9183
|
9284
LL | const I3: &MySliceBool = &MySlice(true, [unsafe { BoolTransmute { val: 3 }.bl }]);
9385
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 3 at .<deref>.1[0], but expected something less or equal to 1
9486
|
9587
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
9688

9789
error[E0080]: it is undefined behavior to use this value
98-
--> $DIR/union-ub-fat-ptr.rs:124:1
90+
--> $DIR/ub-wide-ptr.rs:130:1
9991
|
100-
LL | const J1: &str = unsafe { SliceTransmute { slice: &[0xFF] }.str };
101-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered uninitialized or non-UTF-8 data in str at .<deref>
92+
LL | const RAW_SLICE_LENGTH_UNINIT: *const [u8] = unsafe { SliceTransmute { addr: 42 }.raw_slice};
93+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered uninitialized data in wide pointer metadata
10294
|
10395
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
10496

10597
error[E0080]: it is undefined behavior to use this value
106-
--> $DIR/union-ub-fat-ptr.rs:127:1
98+
--> $DIR/ub-wide-ptr.rs:135:1
10799
|
108-
LL | const J2: &MyStr = unsafe { SliceTransmute { slice: &[0xFF] }.my_str };
109-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered uninitialized or non-UTF-8 data in str at .<deref>.0
100+
LL | const D: &dyn Trait = unsafe { DynTransmute { repr: DynRepr { ptr: &92, vtable: &3 } }.rust};
101+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered dangling or unaligned vtable pointer in wide pointer or too small vtable
102+
|
103+
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
104+
105+
error[E0080]: it is undefined behavior to use this value
106+
--> $DIR/ub-wide-ptr.rs:138:1
107+
|
108+
LL | const E: &dyn Trait = unsafe { DynTransmute { repr2: DynRepr2 { ptr: &92, vtable: &3 } }.rust};
109+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered dangling or unaligned vtable pointer in wide pointer or too small vtable
110+
|
111+
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
112+
113+
error[E0080]: it is undefined behavior to use this value
114+
--> $DIR/ub-wide-ptr.rs:141:1
115+
|
116+
LL | const F: &dyn Trait = unsafe { DynTransmute { bad: BadDynRepr { ptr: &92, vtable: 3 } }.rust};
117+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered dangling or unaligned vtable pointer in wide pointer or too small vtable
118+
|
119+
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
120+
121+
error[E0080]: it is undefined behavior to use this value
122+
--> $DIR/ub-wide-ptr.rs:145:1
123+
|
124+
LL | const G: &dyn Trait = &unsafe { BoolTransmute { val: 3 }.bl };
125+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 3 at .<deref>.<dyn-downcast>, but expected something less or equal to 1
126+
|
127+
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
128+
129+
error[E0080]: it is undefined behavior to use this value
130+
--> $DIR/ub-wide-ptr.rs:149:1
131+
|
132+
LL | const RAW_TRAIT_OBJ_VTABLE_NULL: *const dyn Trait = unsafe { DynTransmute { bad: BadDynRepr { ptr: &92, vtable: 0 } }.rust};
133+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered dangling or unaligned vtable pointer in wide pointer or too small vtable
134+
|
135+
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
136+
137+
error[E0080]: it is undefined behavior to use this value
138+
--> $DIR/ub-wide-ptr.rs:151:1
139+
|
140+
LL | const RAW_TRAIT_OBJ_VTABLE_INVALID: *const dyn Trait = unsafe { DynTransmute { repr2: DynRepr2 { ptr: &92, vtable: &3 } }.raw_rust};
141+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered dangling or unaligned vtable pointer in wide pointer or too small vtable
110142
|
111143
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
112144

113-
error: aborting due to 14 previous errors
145+
error: aborting due to 18 previous errors
114146

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

0 commit comments

Comments
 (0)
Please sign in to comment.