Skip to content

Commit 9d6ce61

Browse files
committed
Update MIR tests for offset_of
1 parent d995bd6 commit 9d6ce61

12 files changed

+48
-74
lines changed

compiler/rustc_abi/src/lib.rs

-26
Original file line numberDiff line numberDiff line change
@@ -1107,32 +1107,6 @@ impl Scalar {
11071107
}
11081108

11091109
// NOTE: This struct is generic over the FieldIdx for rust-analyzer usage.
1110-
rustc_index::newtype_index! {
1111-
/// The *source-order* index of a field in a variant.
1112-
///
1113-
/// This is how most code after type checking refers to fields, rather than
1114-
/// using names (as names have hygiene complications and more complex lookup).
1115-
///
1116-
/// Particularly for `repr(Rust)` types, this may not be the same as *layout* order.
1117-
/// (It is for `repr(C)` `struct`s, however.)
1118-
///
1119-
/// For example, in the following types,
1120-
/// ```rust
1121-
/// # enum Never {}
1122-
/// # #[repr(u16)]
1123-
/// enum Demo1 {
1124-
/// Variant0 { a: Never, b: i32 } = 100,
1125-
/// Variant1 { c: u8, d: u64 } = 10,
1126-
/// }
1127-
/// struct Demo2 { e: u8, f: u16, g: u8 }
1128-
/// ```
1129-
/// `b` is `FieldIdx(1)` in `VariantIdx(0)`,
1130-
/// `d` is `FieldIdx(1)` in `VariantIdx(1)`, and
1131-
/// `f` is `FieldIdx(1)` in `VariantIdx(0)`.
1132-
#[derive(HashStable_Generic)]
1133-
pub struct FieldIdx {}
1134-
}
1135-
11361110
/// Describes how the fields of a type are located in memory.
11371111
#[derive(PartialEq, Eq, Hash, Clone, Debug)]
11381112
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]

compiler/rustc_middle/src/thir.rs

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use rustc_middle::ty::{
2525
};
2626
use rustc_span::def_id::LocalDefId;
2727
use rustc_span::{sym, ErrorGuaranteed, Span, Symbol, DUMMY_SP};
28-
use rustc_span::{sym, Span, Symbol, DUMMY_SP};
2928
use rustc_target::abi::{FieldIdx, VariantIdx};
3029
use rustc_target::asm::InlineAsmRegOrRegClass;
3130
use std::fmt;

compiler/rustc_mir_transform/src/dataflow_const_prop.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,9 @@ impl<'tcx> ValueAnalysis<'tcx> for ConstAnalysis<'_, 'tcx> {
286286
let val = match null_op {
287287
NullOp::SizeOf if layout.is_sized() => layout.size.bytes(),
288288
NullOp::AlignOf if layout.is_sized() => layout.align.abi.bytes(),
289-
NullOp::OffsetOf(fields) => layout
290-
.offset_of_subfield(&self.ecx, fields.iter())
291-
.bytes(),
289+
NullOp::OffsetOf(fields) => {
290+
layout.offset_of_subfield(&self.ecx, fields.iter()).bytes()
291+
}
292292
_ => return ValueOrPlace::Value(FlatSet::Top),
293293
};
294294
FlatSet::Elem(Scalar::from_target_usize(val, &self.tcx))

library/core/src/mem/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1329,6 +1329,7 @@ impl<T> SizedTypeProperties for T {}
13291329
///
13301330
/// assert_eq!(mem::offset_of!(NestedA, b.0), 0);
13311331
///
1332+
/// # #[cfg(not(bootstrap))]
13321333
/// assert_eq!(mem::offset_of!(Option<&u8>, Some.0), 0);
13331334
/// ```
13341335
#[unstable(feature = "offset_of", issue = "106655")]

tests/mir-opt/const_prop/offset_of.concrete.ConstProp.panic-abort.diff

+7-7
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
bb0: {
4343
StorageLive(_1);
4444
StorageLive(_2);
45-
- _2 = OffsetOf(Alpha, [Field(0)]);
45+
- _2 = OffsetOf(Alpha, [(0, 0)]);
4646
- _1 = must_use::<usize>(move _2) -> [return: bb1, unwind unreachable];
4747
+ _2 = const 4_usize;
4848
+ _1 = must_use::<usize>(const 4_usize) -> [return: bb1, unwind unreachable];
@@ -52,7 +52,7 @@
5252
StorageDead(_2);
5353
StorageLive(_3);
5454
StorageLive(_4);
55-
- _4 = OffsetOf(Alpha, [Field(1)]);
55+
- _4 = OffsetOf(Alpha, [(0, 1)]);
5656
- _3 = must_use::<usize>(move _4) -> [return: bb2, unwind unreachable];
5757
+ _4 = const 0_usize;
5858
+ _3 = must_use::<usize>(const 0_usize) -> [return: bb2, unwind unreachable];
@@ -62,7 +62,7 @@
6262
StorageDead(_4);
6363
StorageLive(_5);
6464
StorageLive(_6);
65-
- _6 = OffsetOf(Alpha, [Field(2), Field(0)]);
65+
- _6 = OffsetOf(Alpha, [(0, 2), (0, 0)]);
6666
- _5 = must_use::<usize>(move _6) -> [return: bb3, unwind unreachable];
6767
+ _6 = const 2_usize;
6868
+ _5 = must_use::<usize>(const 2_usize) -> [return: bb3, unwind unreachable];
@@ -72,7 +72,7 @@
7272
StorageDead(_6);
7373
StorageLive(_7);
7474
StorageLive(_8);
75-
- _8 = OffsetOf(Alpha, [Field(2), Field(1)]);
75+
- _8 = OffsetOf(Alpha, [(0, 2), (0, 1)]);
7676
- _7 = must_use::<usize>(move _8) -> [return: bb4, unwind unreachable];
7777
+ _8 = const 3_usize;
7878
+ _7 = must_use::<usize>(const 3_usize) -> [return: bb4, unwind unreachable];
@@ -82,7 +82,7 @@
8282
StorageDead(_8);
8383
StorageLive(_9);
8484
StorageLive(_10);
85-
- _10 = OffsetOf(Epsilon, [Variant(0), Field(0)]);
85+
- _10 = OffsetOf(Epsilon, [(0, 0)]);
8686
- _9 = must_use::<usize>(move _10) -> [return: bb5, unwind unreachable];
8787
+ _10 = const 1_usize;
8888
+ _9 = must_use::<usize>(const 1_usize) -> [return: bb5, unwind unreachable];
@@ -92,7 +92,7 @@
9292
StorageDead(_10);
9393
StorageLive(_11);
9494
StorageLive(_12);
95-
- _12 = OffsetOf(Epsilon, [Variant(0), Field(1)]);
95+
- _12 = OffsetOf(Epsilon, [(0, 1)]);
9696
- _11 = must_use::<usize>(move _12) -> [return: bb6, unwind unreachable];
9797
+ _12 = const 2_usize;
9898
+ _11 = must_use::<usize>(const 2_usize) -> [return: bb6, unwind unreachable];
@@ -102,7 +102,7 @@
102102
StorageDead(_12);
103103
StorageLive(_13);
104104
StorageLive(_14);
105-
- _14 = OffsetOf(Epsilon, [Variant(2), Field(0)]);
105+
- _14 = OffsetOf(Epsilon, [(2, 0)]);
106106
- _13 = must_use::<usize>(move _14) -> [return: bb7, unwind unreachable];
107107
+ _14 = const 4_usize;
108108
+ _13 = must_use::<usize>(const 4_usize) -> [return: bb7, unwind unreachable];

tests/mir-opt/const_prop/offset_of.concrete.ConstProp.panic-unwind.diff

+7-7
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
bb0: {
4343
StorageLive(_1);
4444
StorageLive(_2);
45-
- _2 = OffsetOf(Alpha, [Field(0)]);
45+
- _2 = OffsetOf(Alpha, [(0, 0)]);
4646
- _1 = must_use::<usize>(move _2) -> [return: bb1, unwind continue];
4747
+ _2 = const 4_usize;
4848
+ _1 = must_use::<usize>(const 4_usize) -> [return: bb1, unwind continue];
@@ -52,7 +52,7 @@
5252
StorageDead(_2);
5353
StorageLive(_3);
5454
StorageLive(_4);
55-
- _4 = OffsetOf(Alpha, [Field(1)]);
55+
- _4 = OffsetOf(Alpha, [(0, 1)]);
5656
- _3 = must_use::<usize>(move _4) -> [return: bb2, unwind continue];
5757
+ _4 = const 0_usize;
5858
+ _3 = must_use::<usize>(const 0_usize) -> [return: bb2, unwind continue];
@@ -62,7 +62,7 @@
6262
StorageDead(_4);
6363
StorageLive(_5);
6464
StorageLive(_6);
65-
- _6 = OffsetOf(Alpha, [Field(2), Field(0)]);
65+
- _6 = OffsetOf(Alpha, [(0, 2), (0, 0)]);
6666
- _5 = must_use::<usize>(move _6) -> [return: bb3, unwind continue];
6767
+ _6 = const 2_usize;
6868
+ _5 = must_use::<usize>(const 2_usize) -> [return: bb3, unwind continue];
@@ -72,7 +72,7 @@
7272
StorageDead(_6);
7373
StorageLive(_7);
7474
StorageLive(_8);
75-
- _8 = OffsetOf(Alpha, [Field(2), Field(1)]);
75+
- _8 = OffsetOf(Alpha, [(0, 2), (0, 1)]);
7676
- _7 = must_use::<usize>(move _8) -> [return: bb4, unwind continue];
7777
+ _8 = const 3_usize;
7878
+ _7 = must_use::<usize>(const 3_usize) -> [return: bb4, unwind continue];
@@ -82,7 +82,7 @@
8282
StorageDead(_8);
8383
StorageLive(_9);
8484
StorageLive(_10);
85-
- _10 = OffsetOf(Epsilon, [Variant(0), Field(0)]);
85+
- _10 = OffsetOf(Epsilon, [(0, 0)]);
8686
- _9 = must_use::<usize>(move _10) -> [return: bb5, unwind continue];
8787
+ _10 = const 1_usize;
8888
+ _9 = must_use::<usize>(const 1_usize) -> [return: bb5, unwind continue];
@@ -92,7 +92,7 @@
9292
StorageDead(_10);
9393
StorageLive(_11);
9494
StorageLive(_12);
95-
- _12 = OffsetOf(Epsilon, [Variant(0), Field(1)]);
95+
- _12 = OffsetOf(Epsilon, [(0, 1)]);
9696
- _11 = must_use::<usize>(move _12) -> [return: bb6, unwind continue];
9797
+ _12 = const 2_usize;
9898
+ _11 = must_use::<usize>(const 2_usize) -> [return: bb6, unwind continue];
@@ -102,7 +102,7 @@
102102
StorageDead(_12);
103103
StorageLive(_13);
104104
StorageLive(_14);
105-
- _14 = OffsetOf(Epsilon, [Variant(2), Field(0)]);
105+
- _14 = OffsetOf(Epsilon, [(2, 0)]);
106106
- _13 = must_use::<usize>(move _14) -> [return: bb7, unwind continue];
107107
+ _14 = const 4_usize;
108108
+ _13 = must_use::<usize>(const 4_usize) -> [return: bb7, unwind continue];

tests/mir-opt/const_prop/offset_of.generic.ConstProp.panic-abort.diff

+7-7
Original file line numberDiff line numberDiff line change
@@ -42,55 +42,55 @@
4242
bb0: {
4343
StorageLive(_1);
4444
StorageLive(_2);
45-
_2 = OffsetOf(Gamma<T>, [Field(0)]);
45+
_2 = OffsetOf(Gamma<T>, [(0, 0)]);
4646
_1 = must_use::<usize>(move _2) -> [return: bb1, unwind unreachable];
4747
}
4848

4949
bb1: {
5050
StorageDead(_2);
5151
StorageLive(_3);
5252
StorageLive(_4);
53-
_4 = OffsetOf(Gamma<T>, [Field(1)]);
53+
_4 = OffsetOf(Gamma<T>, [(0, 1)]);
5454
_3 = must_use::<usize>(move _4) -> [return: bb2, unwind unreachable];
5555
}
5656

5757
bb2: {
5858
StorageDead(_4);
5959
StorageLive(_5);
6060
StorageLive(_6);
61-
_6 = OffsetOf(Delta<T>, [Field(1)]);
61+
_6 = OffsetOf(Delta<T>, [(0, 1)]);
6262
_5 = must_use::<usize>(move _6) -> [return: bb3, unwind unreachable];
6363
}
6464

6565
bb3: {
6666
StorageDead(_6);
6767
StorageLive(_7);
6868
StorageLive(_8);
69-
_8 = OffsetOf(Delta<T>, [Field(2)]);
69+
_8 = OffsetOf(Delta<T>, [(0, 2)]);
7070
_7 = must_use::<usize>(move _8) -> [return: bb4, unwind unreachable];
7171
}
7272

7373
bb4: {
7474
StorageDead(_8);
7575
StorageLive(_9);
7676
StorageLive(_10);
77-
_10 = OffsetOf(Zeta<T>, [Variant(0), Field(0)]);
77+
_10 = OffsetOf(Zeta<T>, [(0, 0)]);
7878
_9 = must_use::<usize>(move _10) -> [return: bb5, unwind unreachable];
7979
}
8080

8181
bb5: {
8282
StorageDead(_10);
8383
StorageLive(_11);
8484
StorageLive(_12);
85-
_12 = OffsetOf(Zeta<T>, [Variant(0), Field(1)]);
85+
_12 = OffsetOf(Zeta<T>, [(0, 1)]);
8686
_11 = must_use::<usize>(move _12) -> [return: bb6, unwind unreachable];
8787
}
8888

8989
bb6: {
9090
StorageDead(_12);
9191
StorageLive(_13);
9292
StorageLive(_14);
93-
_14 = OffsetOf(Zeta<T>, [Variant(1), Field(0)]);
93+
_14 = OffsetOf(Zeta<T>, [(1, 0)]);
9494
_13 = must_use::<usize>(move _14) -> [return: bb7, unwind unreachable];
9595
}
9696

tests/mir-opt/const_prop/offset_of.generic.ConstProp.panic-unwind.diff

+7-7
Original file line numberDiff line numberDiff line change
@@ -42,55 +42,55 @@
4242
bb0: {
4343
StorageLive(_1);
4444
StorageLive(_2);
45-
_2 = OffsetOf(Gamma<T>, [Field(0)]);
45+
_2 = OffsetOf(Gamma<T>, [(0, 0)]);
4646
_1 = must_use::<usize>(move _2) -> [return: bb1, unwind continue];
4747
}
4848

4949
bb1: {
5050
StorageDead(_2);
5151
StorageLive(_3);
5252
StorageLive(_4);
53-
_4 = OffsetOf(Gamma<T>, [Field(1)]);
53+
_4 = OffsetOf(Gamma<T>, [(0, 1)]);
5454
_3 = must_use::<usize>(move _4) -> [return: bb2, unwind continue];
5555
}
5656

5757
bb2: {
5858
StorageDead(_4);
5959
StorageLive(_5);
6060
StorageLive(_6);
61-
_6 = OffsetOf(Delta<T>, [Field(1)]);
61+
_6 = OffsetOf(Delta<T>, [(0, 1)]);
6262
_5 = must_use::<usize>(move _6) -> [return: bb3, unwind continue];
6363
}
6464

6565
bb3: {
6666
StorageDead(_6);
6767
StorageLive(_7);
6868
StorageLive(_8);
69-
_8 = OffsetOf(Delta<T>, [Field(2)]);
69+
_8 = OffsetOf(Delta<T>, [(0, 2)]);
7070
_7 = must_use::<usize>(move _8) -> [return: bb4, unwind continue];
7171
}
7272

7373
bb4: {
7474
StorageDead(_8);
7575
StorageLive(_9);
7676
StorageLive(_10);
77-
_10 = OffsetOf(Zeta<T>, [Variant(0), Field(0)]);
77+
_10 = OffsetOf(Zeta<T>, [(0, 0)]);
7878
_9 = must_use::<usize>(move _10) -> [return: bb5, unwind continue];
7979
}
8080

8181
bb5: {
8282
StorageDead(_10);
8383
StorageLive(_11);
8484
StorageLive(_12);
85-
_12 = OffsetOf(Zeta<T>, [Variant(0), Field(1)]);
85+
_12 = OffsetOf(Zeta<T>, [(0, 1)]);
8686
_11 = must_use::<usize>(move _12) -> [return: bb6, unwind continue];
8787
}
8888

8989
bb6: {
9090
StorageDead(_12);
9191
StorageLive(_13);
9292
StorageLive(_14);
93-
_14 = OffsetOf(Zeta<T>, [Variant(1), Field(0)]);
93+
_14 = OffsetOf(Zeta<T>, [(1, 0)]);
9494
_13 = must_use::<usize>(move _14) -> [return: bb7, unwind continue];
9595
}
9696

tests/mir-opt/dataflow-const-prop/offset_of.concrete.DataflowConstProp.panic-abort.diff

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
bb0: {
2828
StorageLive(_1);
2929
StorageLive(_2);
30-
- _2 = OffsetOf(Alpha, [0]);
30+
- _2 = OffsetOf(Alpha, [(0, 0)]);
3131
- _1 = must_use::<usize>(move _2) -> [return: bb1, unwind unreachable];
3232
+ _2 = const 4_usize;
3333
+ _1 = must_use::<usize>(const 4_usize) -> [return: bb1, unwind unreachable];
@@ -37,7 +37,7 @@
3737
StorageDead(_2);
3838
StorageLive(_3);
3939
StorageLive(_4);
40-
- _4 = OffsetOf(Alpha, [1]);
40+
- _4 = OffsetOf(Alpha, [(0, 1)]);
4141
- _3 = must_use::<usize>(move _4) -> [return: bb2, unwind unreachable];
4242
+ _4 = const 0_usize;
4343
+ _3 = must_use::<usize>(const 0_usize) -> [return: bb2, unwind unreachable];
@@ -47,7 +47,7 @@
4747
StorageDead(_4);
4848
StorageLive(_5);
4949
StorageLive(_6);
50-
- _6 = OffsetOf(Alpha, [2, 0]);
50+
- _6 = OffsetOf(Alpha, [(0, 2), (0, 0)]);
5151
- _5 = must_use::<usize>(move _6) -> [return: bb3, unwind unreachable];
5252
+ _6 = const 2_usize;
5353
+ _5 = must_use::<usize>(const 2_usize) -> [return: bb3, unwind unreachable];
@@ -57,7 +57,7 @@
5757
StorageDead(_6);
5858
StorageLive(_7);
5959
StorageLive(_8);
60-
- _8 = OffsetOf(Alpha, [2, 1]);
60+
- _8 = OffsetOf(Alpha, [(0, 2), (0, 1)]);
6161
- _7 = must_use::<usize>(move _8) -> [return: bb4, unwind unreachable];
6262
+ _8 = const 3_usize;
6363
+ _7 = must_use::<usize>(const 3_usize) -> [return: bb4, unwind unreachable];

tests/mir-opt/dataflow-const-prop/offset_of.concrete.DataflowConstProp.panic-unwind.diff

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
bb0: {
2828
StorageLive(_1);
2929
StorageLive(_2);
30-
- _2 = OffsetOf(Alpha, [0]);
30+
- _2 = OffsetOf(Alpha, [(0, 0)]);
3131
- _1 = must_use::<usize>(move _2) -> [return: bb1, unwind continue];
3232
+ _2 = const 4_usize;
3333
+ _1 = must_use::<usize>(const 4_usize) -> [return: bb1, unwind continue];
@@ -37,7 +37,7 @@
3737
StorageDead(_2);
3838
StorageLive(_3);
3939
StorageLive(_4);
40-
- _4 = OffsetOf(Alpha, [1]);
40+
- _4 = OffsetOf(Alpha, [(0, 1)]);
4141
- _3 = must_use::<usize>(move _4) -> [return: bb2, unwind continue];
4242
+ _4 = const 0_usize;
4343
+ _3 = must_use::<usize>(const 0_usize) -> [return: bb2, unwind continue];
@@ -47,7 +47,7 @@
4747
StorageDead(_4);
4848
StorageLive(_5);
4949
StorageLive(_6);
50-
- _6 = OffsetOf(Alpha, [2, 0]);
50+
- _6 = OffsetOf(Alpha, [(0, 2), (0, 0)]);
5151
- _5 = must_use::<usize>(move _6) -> [return: bb3, unwind continue];
5252
+ _6 = const 2_usize;
5353
+ _5 = must_use::<usize>(const 2_usize) -> [return: bb3, unwind continue];
@@ -57,7 +57,7 @@
5757
StorageDead(_6);
5858
StorageLive(_7);
5959
StorageLive(_8);
60-
- _8 = OffsetOf(Alpha, [2, 1]);
60+
- _8 = OffsetOf(Alpha, [(0, 2), (0, 1)]);
6161
- _7 = must_use::<usize>(move _8) -> [return: bb4, unwind continue];
6262
+ _8 = const 3_usize;
6363
+ _7 = must_use::<usize>(const 3_usize) -> [return: bb4, unwind continue];

0 commit comments

Comments
 (0)