Update MIR tests for offset_of

This commit is contained in:
George Bateman 2023-10-31 21:25:45 +00:00
parent d995bd61e7
commit 9d6ce61376
No known key found for this signature in database
GPG Key ID: C417AA9C4039EFCF
12 changed files with 48 additions and 74 deletions

View File

@ -1107,32 +1107,6 @@ impl Scalar {
}
// NOTE: This struct is generic over the FieldIdx for rust-analyzer usage.
rustc_index::newtype_index! {
/// The *source-order* index of a field in a variant.
///
/// This is how most code after type checking refers to fields, rather than
/// using names (as names have hygiene complications and more complex lookup).
///
/// Particularly for `repr(Rust)` types, this may not be the same as *layout* order.
/// (It is for `repr(C)` `struct`s, however.)
///
/// For example, in the following types,
/// ```rust
/// # enum Never {}
/// # #[repr(u16)]
/// enum Demo1 {
/// Variant0 { a: Never, b: i32 } = 100,
/// Variant1 { c: u8, d: u64 } = 10,
/// }
/// struct Demo2 { e: u8, f: u16, g: u8 }
/// ```
/// `b` is `FieldIdx(1)` in `VariantIdx(0)`,
/// `d` is `FieldIdx(1)` in `VariantIdx(1)`, and
/// `f` is `FieldIdx(1)` in `VariantIdx(0)`.
#[derive(HashStable_Generic)]
pub struct FieldIdx {}
}
/// Describes how the fields of a type are located in memory.
#[derive(PartialEq, Eq, Hash, Clone, Debug)]
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]

View File

@ -25,7 +25,6 @@ use rustc_middle::ty::{
};
use rustc_span::def_id::LocalDefId;
use rustc_span::{sym, ErrorGuaranteed, Span, Symbol, DUMMY_SP};
use rustc_span::{sym, Span, Symbol, DUMMY_SP};
use rustc_target::abi::{FieldIdx, VariantIdx};
use rustc_target::asm::InlineAsmRegOrRegClass;
use std::fmt;

View File

@ -286,9 +286,9 @@ impl<'tcx> ValueAnalysis<'tcx> for ConstAnalysis<'_, 'tcx> {
let val = match null_op {
NullOp::SizeOf if layout.is_sized() => layout.size.bytes(),
NullOp::AlignOf if layout.is_sized() => layout.align.abi.bytes(),
NullOp::OffsetOf(fields) => layout
.offset_of_subfield(&self.ecx, fields.iter())
.bytes(),
NullOp::OffsetOf(fields) => {
layout.offset_of_subfield(&self.ecx, fields.iter()).bytes()
}
_ => return ValueOrPlace::Value(FlatSet::Top),
};
FlatSet::Elem(Scalar::from_target_usize(val, &self.tcx))

View File

@ -1329,6 +1329,7 @@ impl<T> SizedTypeProperties for T {}
///
/// assert_eq!(mem::offset_of!(NestedA, b.0), 0);
///
/// # #[cfg(not(bootstrap))]
/// assert_eq!(mem::offset_of!(Option<&u8>, Some.0), 0);
/// ```
#[unstable(feature = "offset_of", issue = "106655")]

View File

@ -42,7 +42,7 @@
bb0: {
StorageLive(_1);
StorageLive(_2);
- _2 = OffsetOf(Alpha, [Field(0)]);
- _2 = OffsetOf(Alpha, [(0, 0)]);
- _1 = must_use::<usize>(move _2) -> [return: bb1, unwind unreachable];
+ _2 = const 4_usize;
+ _1 = must_use::<usize>(const 4_usize) -> [return: bb1, unwind unreachable];
@ -52,7 +52,7 @@
StorageDead(_2);
StorageLive(_3);
StorageLive(_4);
- _4 = OffsetOf(Alpha, [Field(1)]);
- _4 = OffsetOf(Alpha, [(0, 1)]);
- _3 = must_use::<usize>(move _4) -> [return: bb2, unwind unreachable];
+ _4 = const 0_usize;
+ _3 = must_use::<usize>(const 0_usize) -> [return: bb2, unwind unreachable];
@ -62,7 +62,7 @@
StorageDead(_4);
StorageLive(_5);
StorageLive(_6);
- _6 = OffsetOf(Alpha, [Field(2), Field(0)]);
- _6 = OffsetOf(Alpha, [(0, 2), (0, 0)]);
- _5 = must_use::<usize>(move _6) -> [return: bb3, unwind unreachable];
+ _6 = const 2_usize;
+ _5 = must_use::<usize>(const 2_usize) -> [return: bb3, unwind unreachable];
@ -72,7 +72,7 @@
StorageDead(_6);
StorageLive(_7);
StorageLive(_8);
- _8 = OffsetOf(Alpha, [Field(2), Field(1)]);
- _8 = OffsetOf(Alpha, [(0, 2), (0, 1)]);
- _7 = must_use::<usize>(move _8) -> [return: bb4, unwind unreachable];
+ _8 = const 3_usize;
+ _7 = must_use::<usize>(const 3_usize) -> [return: bb4, unwind unreachable];
@ -82,7 +82,7 @@
StorageDead(_8);
StorageLive(_9);
StorageLive(_10);
- _10 = OffsetOf(Epsilon, [Variant(0), Field(0)]);
- _10 = OffsetOf(Epsilon, [(0, 0)]);
- _9 = must_use::<usize>(move _10) -> [return: bb5, unwind unreachable];
+ _10 = const 1_usize;
+ _9 = must_use::<usize>(const 1_usize) -> [return: bb5, unwind unreachable];
@ -92,7 +92,7 @@
StorageDead(_10);
StorageLive(_11);
StorageLive(_12);
- _12 = OffsetOf(Epsilon, [Variant(0), Field(1)]);
- _12 = OffsetOf(Epsilon, [(0, 1)]);
- _11 = must_use::<usize>(move _12) -> [return: bb6, unwind unreachable];
+ _12 = const 2_usize;
+ _11 = must_use::<usize>(const 2_usize) -> [return: bb6, unwind unreachable];
@ -102,7 +102,7 @@
StorageDead(_12);
StorageLive(_13);
StorageLive(_14);
- _14 = OffsetOf(Epsilon, [Variant(2), Field(0)]);
- _14 = OffsetOf(Epsilon, [(2, 0)]);
- _13 = must_use::<usize>(move _14) -> [return: bb7, unwind unreachable];
+ _14 = const 4_usize;
+ _13 = must_use::<usize>(const 4_usize) -> [return: bb7, unwind unreachable];

View File

@ -42,7 +42,7 @@
bb0: {
StorageLive(_1);
StorageLive(_2);
- _2 = OffsetOf(Alpha, [Field(0)]);
- _2 = OffsetOf(Alpha, [(0, 0)]);
- _1 = must_use::<usize>(move _2) -> [return: bb1, unwind continue];
+ _2 = const 4_usize;
+ _1 = must_use::<usize>(const 4_usize) -> [return: bb1, unwind continue];
@ -52,7 +52,7 @@
StorageDead(_2);
StorageLive(_3);
StorageLive(_4);
- _4 = OffsetOf(Alpha, [Field(1)]);
- _4 = OffsetOf(Alpha, [(0, 1)]);
- _3 = must_use::<usize>(move _4) -> [return: bb2, unwind continue];
+ _4 = const 0_usize;
+ _3 = must_use::<usize>(const 0_usize) -> [return: bb2, unwind continue];
@ -62,7 +62,7 @@
StorageDead(_4);
StorageLive(_5);
StorageLive(_6);
- _6 = OffsetOf(Alpha, [Field(2), Field(0)]);
- _6 = OffsetOf(Alpha, [(0, 2), (0, 0)]);
- _5 = must_use::<usize>(move _6) -> [return: bb3, unwind continue];
+ _6 = const 2_usize;
+ _5 = must_use::<usize>(const 2_usize) -> [return: bb3, unwind continue];
@ -72,7 +72,7 @@
StorageDead(_6);
StorageLive(_7);
StorageLive(_8);
- _8 = OffsetOf(Alpha, [Field(2), Field(1)]);
- _8 = OffsetOf(Alpha, [(0, 2), (0, 1)]);
- _7 = must_use::<usize>(move _8) -> [return: bb4, unwind continue];
+ _8 = const 3_usize;
+ _7 = must_use::<usize>(const 3_usize) -> [return: bb4, unwind continue];
@ -82,7 +82,7 @@
StorageDead(_8);
StorageLive(_9);
StorageLive(_10);
- _10 = OffsetOf(Epsilon, [Variant(0), Field(0)]);
- _10 = OffsetOf(Epsilon, [(0, 0)]);
- _9 = must_use::<usize>(move _10) -> [return: bb5, unwind continue];
+ _10 = const 1_usize;
+ _9 = must_use::<usize>(const 1_usize) -> [return: bb5, unwind continue];
@ -92,7 +92,7 @@
StorageDead(_10);
StorageLive(_11);
StorageLive(_12);
- _12 = OffsetOf(Epsilon, [Variant(0), Field(1)]);
- _12 = OffsetOf(Epsilon, [(0, 1)]);
- _11 = must_use::<usize>(move _12) -> [return: bb6, unwind continue];
+ _12 = const 2_usize;
+ _11 = must_use::<usize>(const 2_usize) -> [return: bb6, unwind continue];
@ -102,7 +102,7 @@
StorageDead(_12);
StorageLive(_13);
StorageLive(_14);
- _14 = OffsetOf(Epsilon, [Variant(2), Field(0)]);
- _14 = OffsetOf(Epsilon, [(2, 0)]);
- _13 = must_use::<usize>(move _14) -> [return: bb7, unwind continue];
+ _14 = const 4_usize;
+ _13 = must_use::<usize>(const 4_usize) -> [return: bb7, unwind continue];

View File

@ -42,7 +42,7 @@
bb0: {
StorageLive(_1);
StorageLive(_2);
_2 = OffsetOf(Gamma<T>, [Field(0)]);
_2 = OffsetOf(Gamma<T>, [(0, 0)]);
_1 = must_use::<usize>(move _2) -> [return: bb1, unwind unreachable];
}
@ -50,7 +50,7 @@
StorageDead(_2);
StorageLive(_3);
StorageLive(_4);
_4 = OffsetOf(Gamma<T>, [Field(1)]);
_4 = OffsetOf(Gamma<T>, [(0, 1)]);
_3 = must_use::<usize>(move _4) -> [return: bb2, unwind unreachable];
}
@ -58,7 +58,7 @@
StorageDead(_4);
StorageLive(_5);
StorageLive(_6);
_6 = OffsetOf(Delta<T>, [Field(1)]);
_6 = OffsetOf(Delta<T>, [(0, 1)]);
_5 = must_use::<usize>(move _6) -> [return: bb3, unwind unreachable];
}
@ -66,7 +66,7 @@
StorageDead(_6);
StorageLive(_7);
StorageLive(_8);
_8 = OffsetOf(Delta<T>, [Field(2)]);
_8 = OffsetOf(Delta<T>, [(0, 2)]);
_7 = must_use::<usize>(move _8) -> [return: bb4, unwind unreachable];
}
@ -74,7 +74,7 @@
StorageDead(_8);
StorageLive(_9);
StorageLive(_10);
_10 = OffsetOf(Zeta<T>, [Variant(0), Field(0)]);
_10 = OffsetOf(Zeta<T>, [(0, 0)]);
_9 = must_use::<usize>(move _10) -> [return: bb5, unwind unreachable];
}
@ -82,7 +82,7 @@
StorageDead(_10);
StorageLive(_11);
StorageLive(_12);
_12 = OffsetOf(Zeta<T>, [Variant(0), Field(1)]);
_12 = OffsetOf(Zeta<T>, [(0, 1)]);
_11 = must_use::<usize>(move _12) -> [return: bb6, unwind unreachable];
}
@ -90,7 +90,7 @@
StorageDead(_12);
StorageLive(_13);
StorageLive(_14);
_14 = OffsetOf(Zeta<T>, [Variant(1), Field(0)]);
_14 = OffsetOf(Zeta<T>, [(1, 0)]);
_13 = must_use::<usize>(move _14) -> [return: bb7, unwind unreachable];
}

View File

@ -42,7 +42,7 @@
bb0: {
StorageLive(_1);
StorageLive(_2);
_2 = OffsetOf(Gamma<T>, [Field(0)]);
_2 = OffsetOf(Gamma<T>, [(0, 0)]);
_1 = must_use::<usize>(move _2) -> [return: bb1, unwind continue];
}
@ -50,7 +50,7 @@
StorageDead(_2);
StorageLive(_3);
StorageLive(_4);
_4 = OffsetOf(Gamma<T>, [Field(1)]);
_4 = OffsetOf(Gamma<T>, [(0, 1)]);
_3 = must_use::<usize>(move _4) -> [return: bb2, unwind continue];
}
@ -58,7 +58,7 @@
StorageDead(_4);
StorageLive(_5);
StorageLive(_6);
_6 = OffsetOf(Delta<T>, [Field(1)]);
_6 = OffsetOf(Delta<T>, [(0, 1)]);
_5 = must_use::<usize>(move _6) -> [return: bb3, unwind continue];
}
@ -66,7 +66,7 @@
StorageDead(_6);
StorageLive(_7);
StorageLive(_8);
_8 = OffsetOf(Delta<T>, [Field(2)]);
_8 = OffsetOf(Delta<T>, [(0, 2)]);
_7 = must_use::<usize>(move _8) -> [return: bb4, unwind continue];
}
@ -74,7 +74,7 @@
StorageDead(_8);
StorageLive(_9);
StorageLive(_10);
_10 = OffsetOf(Zeta<T>, [Variant(0), Field(0)]);
_10 = OffsetOf(Zeta<T>, [(0, 0)]);
_9 = must_use::<usize>(move _10) -> [return: bb5, unwind continue];
}
@ -82,7 +82,7 @@
StorageDead(_10);
StorageLive(_11);
StorageLive(_12);
_12 = OffsetOf(Zeta<T>, [Variant(0), Field(1)]);
_12 = OffsetOf(Zeta<T>, [(0, 1)]);
_11 = must_use::<usize>(move _12) -> [return: bb6, unwind continue];
}
@ -90,7 +90,7 @@
StorageDead(_12);
StorageLive(_13);
StorageLive(_14);
_14 = OffsetOf(Zeta<T>, [Variant(1), Field(0)]);
_14 = OffsetOf(Zeta<T>, [(1, 0)]);
_13 = must_use::<usize>(move _14) -> [return: bb7, unwind continue];
}

View File

@ -27,7 +27,7 @@
bb0: {
StorageLive(_1);
StorageLive(_2);
- _2 = OffsetOf(Alpha, [0]);
- _2 = OffsetOf(Alpha, [(0, 0)]);
- _1 = must_use::<usize>(move _2) -> [return: bb1, unwind unreachable];
+ _2 = const 4_usize;
+ _1 = must_use::<usize>(const 4_usize) -> [return: bb1, unwind unreachable];
@ -37,7 +37,7 @@
StorageDead(_2);
StorageLive(_3);
StorageLive(_4);
- _4 = OffsetOf(Alpha, [1]);
- _4 = OffsetOf(Alpha, [(0, 1)]);
- _3 = must_use::<usize>(move _4) -> [return: bb2, unwind unreachable];
+ _4 = const 0_usize;
+ _3 = must_use::<usize>(const 0_usize) -> [return: bb2, unwind unreachable];
@ -47,7 +47,7 @@
StorageDead(_4);
StorageLive(_5);
StorageLive(_6);
- _6 = OffsetOf(Alpha, [2, 0]);
- _6 = OffsetOf(Alpha, [(0, 2), (0, 0)]);
- _5 = must_use::<usize>(move _6) -> [return: bb3, unwind unreachable];
+ _6 = const 2_usize;
+ _5 = must_use::<usize>(const 2_usize) -> [return: bb3, unwind unreachable];
@ -57,7 +57,7 @@
StorageDead(_6);
StorageLive(_7);
StorageLive(_8);
- _8 = OffsetOf(Alpha, [2, 1]);
- _8 = OffsetOf(Alpha, [(0, 2), (0, 1)]);
- _7 = must_use::<usize>(move _8) -> [return: bb4, unwind unreachable];
+ _8 = const 3_usize;
+ _7 = must_use::<usize>(const 3_usize) -> [return: bb4, unwind unreachable];

View File

@ -27,7 +27,7 @@
bb0: {
StorageLive(_1);
StorageLive(_2);
- _2 = OffsetOf(Alpha, [0]);
- _2 = OffsetOf(Alpha, [(0, 0)]);
- _1 = must_use::<usize>(move _2) -> [return: bb1, unwind continue];
+ _2 = const 4_usize;
+ _1 = must_use::<usize>(const 4_usize) -> [return: bb1, unwind continue];
@ -37,7 +37,7 @@
StorageDead(_2);
StorageLive(_3);
StorageLive(_4);
- _4 = OffsetOf(Alpha, [1]);
- _4 = OffsetOf(Alpha, [(0, 1)]);
- _3 = must_use::<usize>(move _4) -> [return: bb2, unwind continue];
+ _4 = const 0_usize;
+ _3 = must_use::<usize>(const 0_usize) -> [return: bb2, unwind continue];
@ -47,7 +47,7 @@
StorageDead(_4);
StorageLive(_5);
StorageLive(_6);
- _6 = OffsetOf(Alpha, [2, 0]);
- _6 = OffsetOf(Alpha, [(0, 2), (0, 0)]);
- _5 = must_use::<usize>(move _6) -> [return: bb3, unwind continue];
+ _6 = const 2_usize;
+ _5 = must_use::<usize>(const 2_usize) -> [return: bb3, unwind continue];
@ -57,7 +57,7 @@
StorageDead(_6);
StorageLive(_7);
StorageLive(_8);
- _8 = OffsetOf(Alpha, [2, 1]);
- _8 = OffsetOf(Alpha, [(0, 2), (0, 1)]);
- _7 = must_use::<usize>(move _8) -> [return: bb4, unwind continue];
+ _8 = const 3_usize;
+ _7 = must_use::<usize>(const 3_usize) -> [return: bb4, unwind continue];

View File

@ -27,7 +27,7 @@
bb0: {
StorageLive(_1);
StorageLive(_2);
_2 = OffsetOf(Gamma<T>, [0]);
_2 = OffsetOf(Gamma<T>, [(0, 0)]);
_1 = must_use::<usize>(move _2) -> [return: bb1, unwind unreachable];
}
@ -35,7 +35,7 @@
StorageDead(_2);
StorageLive(_3);
StorageLive(_4);
_4 = OffsetOf(Gamma<T>, [1]);
_4 = OffsetOf(Gamma<T>, [(0, 1)]);
_3 = must_use::<usize>(move _4) -> [return: bb2, unwind unreachable];
}
@ -43,7 +43,7 @@
StorageDead(_4);
StorageLive(_5);
StorageLive(_6);
- _6 = OffsetOf(Delta<T>, [1]);
- _6 = OffsetOf(Delta<T>, [(0, 1)]);
- _5 = must_use::<usize>(move _6) -> [return: bb3, unwind unreachable];
+ _6 = const 0_usize;
+ _5 = must_use::<usize>(const 0_usize) -> [return: bb3, unwind unreachable];
@ -53,7 +53,7 @@
StorageDead(_6);
StorageLive(_7);
StorageLive(_8);
- _8 = OffsetOf(Delta<T>, [2]);
- _8 = OffsetOf(Delta<T>, [(0, 2)]);
- _7 = must_use::<usize>(move _8) -> [return: bb4, unwind unreachable];
+ _8 = const 2_usize;
+ _7 = must_use::<usize>(const 2_usize) -> [return: bb4, unwind unreachable];

View File

@ -27,7 +27,7 @@
bb0: {
StorageLive(_1);
StorageLive(_2);
_2 = OffsetOf(Gamma<T>, [0]);
_2 = OffsetOf(Gamma<T>, [(0, 0)]);
_1 = must_use::<usize>(move _2) -> [return: bb1, unwind continue];
}
@ -35,7 +35,7 @@
StorageDead(_2);
StorageLive(_3);
StorageLive(_4);
_4 = OffsetOf(Gamma<T>, [1]);
_4 = OffsetOf(Gamma<T>, [(0, 1)]);
_3 = must_use::<usize>(move _4) -> [return: bb2, unwind continue];
}
@ -43,7 +43,7 @@
StorageDead(_4);
StorageLive(_5);
StorageLive(_6);
- _6 = OffsetOf(Delta<T>, [1]);
- _6 = OffsetOf(Delta<T>, [(0, 1)]);
- _5 = must_use::<usize>(move _6) -> [return: bb3, unwind continue];
+ _6 = const 0_usize;
+ _5 = must_use::<usize>(const 0_usize) -> [return: bb3, unwind continue];
@ -53,7 +53,7 @@
StorageDead(_6);
StorageLive(_7);
StorageLive(_8);
- _8 = OffsetOf(Delta<T>, [2]);
- _8 = OffsetOf(Delta<T>, [(0, 2)]);
- _7 = must_use::<usize>(move _8) -> [return: bb4, unwind continue];
+ _8 = const 2_usize;
+ _7 = must_use::<usize>(const 2_usize) -> [return: bb4, unwind continue];