Rollup merge of #133088 - the8472:randomize-me-harder, r=workingjubilee

`-Zrandomize-layout` harder. `Foo<T> != Foo<U>`

Tracking issue: #106764

Previously randomize-layout only used a deterministic shuffle based on the seed stored in an Adt's ReprOptions, meaning that `Foo<T>`  and `Foo<U>` were shuffled by the same seed. This change adds a similar seed to each calculated LayoutData so that a struct can be randomized both based on the layout of its fields and its per-type seed.
Primitives start with simple seed derived from some of their properties. Though some types can no longer be distinguished at that point, e.g. usize and u64 will still be treated the same.
This commit is contained in:
Matthias Krüger 2025-01-10 06:28:37 +01:00 committed by GitHub
commit eaf420638e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
39 changed files with 400 additions and 78 deletions

View File

@ -119,6 +119,8 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
.chain(Niche::from_scalar(dl, Size::ZERO, a))
.max_by_key(|niche| niche.available(dl));
let combined_seed = a.size(&self.cx).bytes().wrapping_add(b.size(&self.cx).bytes());
LayoutData {
variants: Variants::Single { index: VariantIdx::new(0) },
fields: FieldsShape::Arbitrary {
@ -131,6 +133,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
size,
max_repr_align: None,
unadjusted_abi_align: align.abi,
randomization_seed: combined_seed,
}
}
@ -223,6 +226,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
size: Size::ZERO,
max_repr_align: None,
unadjusted_abi_align: dl.i8_align.abi,
randomization_seed: 0,
}
}
@ -385,6 +389,11 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
return Err(LayoutCalculatorError::EmptyUnion);
};
let combined_seed = only_variant
.iter()
.map(|v| v.randomization_seed)
.fold(repr.field_shuffle_seed, |acc, seed| acc.wrapping_add(seed));
Ok(LayoutData {
variants: Variants::Single { index: only_variant_idx },
fields: FieldsShape::Union(union_field_count),
@ -394,6 +403,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
size: size.align_to(align.abi),
max_repr_align,
unadjusted_abi_align,
randomization_seed: combined_seed,
})
}
@ -650,6 +660,11 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
BackendRepr::Memory { sized: true }
};
let combined_seed = variant_layouts
.iter()
.map(|v| v.randomization_seed)
.fold(repr.field_shuffle_seed, |acc, seed| acc.wrapping_add(seed));
let layout = LayoutData {
variants: Variants::Multiple {
tag: niche_scalar,
@ -671,6 +686,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
align,
max_repr_align,
unadjusted_abi_align,
randomization_seed: combined_seed,
};
Some(TmpLayout { layout, variants: variant_layouts })
@ -961,6 +977,11 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
let largest_niche = Niche::from_scalar(dl, Size::ZERO, tag);
let combined_seed = layout_variants
.iter()
.map(|v| v.randomization_seed)
.fold(repr.field_shuffle_seed, |acc, seed| acc.wrapping_add(seed));
let tagged_layout = LayoutData {
variants: Variants::Multiple {
tag,
@ -978,6 +999,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
size,
max_repr_align,
unadjusted_abi_align,
randomization_seed: combined_seed,
};
let tagged_layout = TmpLayout { layout: tagged_layout, variants: layout_variants };
@ -1030,12 +1052,15 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
let mut max_repr_align = repr.align;
let mut inverse_memory_index: IndexVec<u32, FieldIdx> = fields.indices().collect();
let optimize_field_order = !repr.inhibit_struct_field_reordering();
if optimize_field_order && fields.len() > 1 {
let end =
if let StructKind::MaybeUnsized = kind { fields.len() - 1 } else { fields.len() };
let optimizing = &mut inverse_memory_index.raw[..end];
let fields_excluding_tail = &fields.raw[..end];
let end = if let StructKind::MaybeUnsized = kind { fields.len() - 1 } else { fields.len() };
let optimizing = &mut inverse_memory_index.raw[..end];
let fields_excluding_tail = &fields.raw[..end];
// unsizable tail fields are excluded so that we use the same seed for the sized and unsized layouts.
let field_seed = fields_excluding_tail
.iter()
.fold(0u64, |acc, f| acc.wrapping_add(f.randomization_seed));
if optimize_field_order && fields.len() > 1 {
// If `-Z randomize-layout` was enabled for the type definition we can shuffle
// the field ordering to try and catch some code making assumptions about layouts
// we don't guarantee.
@ -1046,8 +1071,9 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
use rand::seq::SliceRandom;
// `ReprOptions.field_shuffle_seed` is a deterministic seed we can use to randomize field
// ordering.
let mut rng =
rand_xoshiro::Xoshiro128StarStar::seed_from_u64(repr.field_shuffle_seed);
let mut rng = rand_xoshiro::Xoshiro128StarStar::seed_from_u64(
field_seed.wrapping_add(repr.field_shuffle_seed),
);
// Shuffle the ordering of the fields.
optimizing.shuffle(&mut rng);
@ -1344,6 +1370,8 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
unadjusted_abi_align
};
let seed = field_seed.wrapping_add(repr.field_shuffle_seed);
Ok(LayoutData {
variants: Variants::Single { index: VariantIdx::new(0) },
fields: FieldsShape::Arbitrary { offsets, memory_index },
@ -1353,6 +1381,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
size,
max_repr_align,
unadjusted_abi_align,
randomization_seed: seed,
})
}

View File

@ -1719,6 +1719,18 @@ pub struct LayoutData<FieldIdx: Idx, VariantIdx: Idx> {
/// Only used on aarch64-linux, where the argument passing ABI ignores the requested alignment
/// in some cases.
pub unadjusted_abi_align: Align,
/// The randomization seed based on this type's own repr and its fields.
///
/// Since randomization is toggled on a per-crate basis even crates that do not have randomization
/// enabled should still calculate a seed so that downstream uses can use it to distinguish different
/// types.
///
/// For every T and U for which we do not guarantee that a repr(Rust) `Foo<T>` can be coerced or
/// transmuted to `Foo<U>` we aim to create probalistically distinct seeds so that Foo can choose
/// to reorder its fields based on that information. The current implementation is a conservative
/// approximation of this goal.
pub randomization_seed: u64,
}
impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {
@ -1739,6 +1751,30 @@ impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {
let largest_niche = Niche::from_scalar(cx, Size::ZERO, scalar);
let size = scalar.size(cx);
let align = scalar.align(cx);
let range = scalar.valid_range(cx);
// All primitive types for which we don't have subtype coercions should get a distinct seed,
// so that types wrapping them can use randomization to arrive at distinct layouts.
//
// Some type information is already lost at this point, so as an approximation we derive
// the seed from what remains. For example on 64-bit targets usize and u64 can no longer
// be distinguished.
let randomization_seed = size
.bytes()
.wrapping_add(
match scalar.primitive() {
Primitive::Int(_, true) => 1,
Primitive::Int(_, false) => 2,
Primitive::Float(_) => 3,
Primitive::Pointer(_) => 4,
} << 32,
)
// distinguishes references from pointers
.wrapping_add((range.start as u64).rotate_right(16))
// distinguishes char from u32 and bool from u8
.wrapping_add((range.end as u64).rotate_right(16));
LayoutData {
variants: Variants::Single { index: VariantIdx::new(0) },
fields: FieldsShape::Primitive,
@ -1748,6 +1784,7 @@ impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {
align,
max_repr_align: None,
unadjusted_abi_align: align.abi,
randomization_seed,
}
}
}
@ -1770,6 +1807,7 @@ where
variants,
max_repr_align,
unadjusted_abi_align,
ref randomization_seed,
} = self;
f.debug_struct("Layout")
.field("size", size)
@ -1780,6 +1818,7 @@ where
.field("variants", variants)
.field("max_repr_align", max_repr_align)
.field("unadjusted_abi_align", unadjusted_abi_align)
.field("randomization_seed", randomization_seed)
.finish()
}
}

View File

@ -770,6 +770,7 @@ where
size: Size::ZERO,
max_repr_align: None,
unadjusted_abi_align: tcx.data_layout.i8_align.abi,
randomization_seed: 0,
})
}

View File

@ -347,6 +347,7 @@ fn layout_of_uncached<'tcx>(
size,
max_repr_align: None,
unadjusted_abi_align: element.align.abi,
randomization_seed: element.randomization_seed.wrapping_add(count),
})
}
ty::Slice(element) => {
@ -360,6 +361,8 @@ fn layout_of_uncached<'tcx>(
size: Size::ZERO,
max_repr_align: None,
unadjusted_abi_align: element.align.abi,
// adding a randomly chosen value to distinguish slices
randomization_seed: element.randomization_seed.wrapping_add(0x2dcba99c39784102),
})
}
ty::Str => tcx.mk_layout(LayoutData {
@ -371,6 +374,8 @@ fn layout_of_uncached<'tcx>(
size: Size::ZERO,
max_repr_align: None,
unadjusted_abi_align: dl.i8_align.abi,
// another random value
randomization_seed: 0xc1325f37d127be22,
}),
// Odd unit types.
@ -542,6 +547,7 @@ fn layout_of_uncached<'tcx>(
align,
max_repr_align: None,
unadjusted_abi_align: align.abi,
randomization_seed: e_ly.randomization_seed.wrapping_add(e_len),
})
}
@ -999,6 +1005,9 @@ fn coroutine_layout<'tcx>(
BackendRepr::Memory { sized: true }
};
// this is similar to how ReprOptions populates its field_shuffle_seed
let def_hash = tcx.def_path_hash(def_id).0.to_smaller_hash().as_u64();
let layout = tcx.mk_layout(LayoutData {
variants: Variants::Multiple {
tag,
@ -1019,6 +1028,7 @@ fn coroutine_layout<'tcx>(
align,
max_repr_align: None,
unadjusted_abi_align: align.abi,
randomization_seed: def_hash,
});
debug!("coroutine layout ({:?}): {:#?}", ty, layout);
Ok(layout)

View File

@ -197,6 +197,7 @@ fn layout_of_simd_ty(
align,
max_repr_align: None,
unadjusted_abi_align: align.abi,
randomization_seed: 0,
}))
}
@ -313,6 +314,7 @@ pub fn layout_of_ty_query(
size,
max_repr_align: None,
unadjusted_abi_align: element.align.abi,
randomization_seed: 0,
}
}
TyKind::Slice(element) => {
@ -326,6 +328,7 @@ pub fn layout_of_ty_query(
size: Size::ZERO,
max_repr_align: None,
unadjusted_abi_align: element.align.abi,
randomization_seed: 0,
}
}
TyKind::Str => Layout {
@ -337,6 +340,7 @@ pub fn layout_of_ty_query(
size: Size::ZERO,
max_repr_align: None,
unadjusted_abi_align: dl.i8_align.abi,
randomization_seed: 0,
},
// Potentially-wide pointers.
TyKind::Ref(_, _, pointee) | TyKind::Raw(_, pointee) => {

View File

@ -22,6 +22,7 @@ error: fn_abi_of(pass_zst) = FnAbi {
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: 0,
},
},
mode: Ignore,
@ -49,6 +50,7 @@ error: fn_abi_of(pass_zst) = FnAbi {
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: 0,
},
},
mode: Ignore,

View File

@ -22,6 +22,7 @@ error: fn_abi_of(pass_zst) = FnAbi {
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: 0,
},
},
mode: Indirect {
@ -60,6 +61,7 @@ error: fn_abi_of(pass_zst) = FnAbi {
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: 0,
},
},
mode: Ignore,

View File

@ -22,6 +22,7 @@ error: fn_abi_of(pass_zst) = FnAbi {
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: 0,
},
},
mode: Indirect {
@ -60,6 +61,7 @@ error: fn_abi_of(pass_zst) = FnAbi {
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: 0,
},
},
mode: Ignore,

View File

@ -22,6 +22,7 @@ error: fn_abi_of(pass_zst) = FnAbi {
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: 0,
},
},
mode: Indirect {
@ -60,6 +61,7 @@ error: fn_abi_of(pass_zst) = FnAbi {
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: 0,
},
},
mode: Ignore,

View File

@ -22,6 +22,7 @@ error: fn_abi_of(pass_zst) = FnAbi {
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: 0,
},
},
mode: Ignore,
@ -49,6 +50,7 @@ error: fn_abi_of(pass_zst) = FnAbi {
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: 0,
},
},
mode: Ignore,

View File

@ -22,6 +22,7 @@ error: fn_abi_of(pass_zst) = FnAbi {
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: 0,
},
},
mode: Indirect {
@ -60,6 +61,7 @@ error: fn_abi_of(pass_zst) = FnAbi {
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: 0,
},
},
mode: Ignore,

View File

@ -1,4 +1,5 @@
//@ normalize-stderr: "(abi|pref|unadjusted_abi_align): Align\([1-8] bytes\)" -> "$1: $$SOME_ALIGN"
//@ normalize-stderr: "randomization_seed: \d+" -> "randomization_seed: $$SEED"
//@ normalize-stderr: "(size): Size\([48] bytes\)" -> "$1: $$SOME_SIZE"
//@ normalize-stderr: "(can_unwind): (true|false)" -> "$1: $$SOME_BOOL"
//@ normalize-stderr: "(valid_range): 0\.\.=(4294967295|18446744073709551615)" -> "$1: $$FULL"

View File

@ -25,6 +25,7 @@ error: fn_abi_of(test) = FnAbi {
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: $SEED,
},
},
mode: Direct(
@ -71,6 +72,7 @@ error: fn_abi_of(test) = FnAbi {
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: $SEED,
},
},
mode: Direct(
@ -87,7 +89,7 @@ error: fn_abi_of(test) = FnAbi {
conv: Rust,
can_unwind: $SOME_BOOL,
}
--> $DIR/debug.rs:15:1
--> $DIR/debug.rs:16:1
|
LL | fn test(_x: u8) -> bool { true }
| ^^^^^^^^^^^^^^^^^^^^^^^
@ -128,6 +130,7 @@ error: fn_abi_of(TestFnPtr) = FnAbi {
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: $SEED,
},
},
mode: Direct(
@ -165,6 +168,7 @@ error: fn_abi_of(TestFnPtr) = FnAbi {
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: $SEED,
},
},
mode: Direct(
@ -181,7 +185,7 @@ error: fn_abi_of(TestFnPtr) = FnAbi {
conv: Rust,
can_unwind: $SOME_BOOL,
}
--> $DIR/debug.rs:18:1
--> $DIR/debug.rs:19:1
|
LL | type TestFnPtr = fn(bool) -> u8;
| ^^^^^^^^^^^^^^
@ -214,6 +218,7 @@ error: fn_abi_of(test_generic) = FnAbi {
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: $SEED,
},
},
mode: Direct(
@ -248,6 +253,7 @@ error: fn_abi_of(test_generic) = FnAbi {
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: $SEED,
},
},
mode: Ignore,
@ -257,13 +263,13 @@ error: fn_abi_of(test_generic) = FnAbi {
conv: Rust,
can_unwind: $SOME_BOOL,
}
--> $DIR/debug.rs:21:1
--> $DIR/debug.rs:22:1
|
LL | fn test_generic<T>(_x: *const T) { }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: `#[rustc_abi]` can only be applied to function items, type aliases, and associated functions
--> $DIR/debug.rs:24:1
--> $DIR/debug.rs:25:1
|
LL | const C: () = ();
| ^^^^^^^^^^^
@ -296,6 +302,7 @@ error: ABIs are not compatible
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: $SEED,
},
},
mode: Direct(
@ -330,6 +337,7 @@ error: ABIs are not compatible
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: $SEED,
},
},
mode: Ignore,
@ -366,6 +374,7 @@ error: ABIs are not compatible
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: $SEED,
},
},
mode: Direct(
@ -400,6 +409,7 @@ error: ABIs are not compatible
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: $SEED,
},
},
mode: Ignore,
@ -409,7 +419,7 @@ error: ABIs are not compatible
conv: Rust,
can_unwind: $SOME_BOOL,
}
--> $DIR/debug.rs:40:1
--> $DIR/debug.rs:41:1
|
LL | type TestAbiNe = (fn(u8), fn(u32));
| ^^^^^^^^^^^^^^
@ -439,6 +449,7 @@ error: ABIs are not compatible
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: $SEED,
},
},
mode: Indirect {
@ -477,6 +488,7 @@ error: ABIs are not compatible
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: $SEED,
},
},
mode: Ignore,
@ -510,6 +522,7 @@ error: ABIs are not compatible
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: $SEED,
},
},
mode: Indirect {
@ -548,6 +561,7 @@ error: ABIs are not compatible
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: $SEED,
},
},
mode: Ignore,
@ -557,7 +571,7 @@ error: ABIs are not compatible
conv: Rust,
can_unwind: $SOME_BOOL,
}
--> $DIR/debug.rs:43:1
--> $DIR/debug.rs:44:1
|
LL | type TestAbiNeLarger = (fn([u8; 32]), fn([u32; 32]));
| ^^^^^^^^^^^^^^^^^^^^
@ -589,6 +603,7 @@ error: ABIs are not compatible
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: $SEED,
},
},
mode: Direct(
@ -623,6 +638,7 @@ error: ABIs are not compatible
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: $SEED,
},
},
mode: Ignore,
@ -659,6 +675,7 @@ error: ABIs are not compatible
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: $SEED,
},
},
mode: Direct(
@ -693,6 +710,7 @@ error: ABIs are not compatible
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: $SEED,
},
},
mode: Ignore,
@ -702,7 +720,7 @@ error: ABIs are not compatible
conv: Rust,
can_unwind: $SOME_BOOL,
}
--> $DIR/debug.rs:46:1
--> $DIR/debug.rs:47:1
|
LL | type TestAbiNeFloat = (fn(f32), fn(u32));
| ^^^^^^^^^^^^^^^^^^^
@ -735,6 +753,7 @@ error: ABIs are not compatible
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: $SEED,
},
},
mode: Direct(
@ -769,6 +788,7 @@ error: ABIs are not compatible
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: $SEED,
},
},
mode: Ignore,
@ -805,6 +825,7 @@ error: ABIs are not compatible
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: $SEED,
},
},
mode: Direct(
@ -839,6 +860,7 @@ error: ABIs are not compatible
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: $SEED,
},
},
mode: Ignore,
@ -848,13 +870,13 @@ error: ABIs are not compatible
conv: Rust,
can_unwind: $SOME_BOOL,
}
--> $DIR/debug.rs:50:1
--> $DIR/debug.rs:51:1
|
LL | type TestAbiNeSign = (fn(i32), fn(u32));
| ^^^^^^^^^^^^^^^^^^
error[E0277]: the size for values of type `str` cannot be known at compilation time
--> $DIR/debug.rs:53:46
--> $DIR/debug.rs:54:46
|
LL | type TestAbiEqNonsense = (fn((str, str)), fn((str, str)));
| ^^^^^^^^^^ doesn't have a size known at compile-time
@ -863,7 +885,7 @@ LL | type TestAbiEqNonsense = (fn((str, str)), fn((str, str)));
= note: only the last element of a tuple may have a dynamically sized type
error: `#[rustc_abi]` can only be applied to function items, type aliases, and associated functions
--> $DIR/debug.rs:28:5
--> $DIR/debug.rs:29:5
|
LL | const C: () = ();
| ^^^^^^^^^^^
@ -906,6 +928,7 @@ error: fn_abi_of(assoc_test) = FnAbi {
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: $SEED,
},
},
mode: Direct(
@ -942,6 +965,7 @@ error: fn_abi_of(assoc_test) = FnAbi {
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: $SEED,
},
},
mode: Ignore,
@ -951,7 +975,7 @@ error: fn_abi_of(assoc_test) = FnAbi {
conv: Rust,
can_unwind: $SOME_BOOL,
}
--> $DIR/debug.rs:33:5
--> $DIR/debug.rs:34:5
|
LL | fn assoc_test(&self) { }
| ^^^^^^^^^^^^^^^^^^^^

View File

@ -22,6 +22,7 @@ error: fn_abi_of(pass_zst) = FnAbi {
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: 0,
},
},
mode: Ignore,
@ -49,6 +50,7 @@ error: fn_abi_of(pass_zst) = FnAbi {
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: 0,
},
},
mode: Ignore,

View File

@ -22,6 +22,7 @@ error: fn_abi_of(pass_zst) = FnAbi {
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: 0,
},
},
mode: Ignore,
@ -49,6 +50,7 @@ error: fn_abi_of(pass_zst) = FnAbi {
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: 0,
},
},
mode: Ignore,

View File

@ -22,6 +22,7 @@ error: fn_abi_of(pass_zst) = FnAbi {
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: 0,
},
},
mode: Indirect {
@ -60,6 +61,7 @@ error: fn_abi_of(pass_zst) = FnAbi {
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: 0,
},
},
mode: Ignore,

View File

@ -22,6 +22,7 @@ error: fn_abi_of(pass_zst) = FnAbi {
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: 0,
},
},
mode: Ignore,
@ -49,6 +50,7 @@ error: fn_abi_of(pass_zst) = FnAbi {
},
max_repr_align: None,
unadjusted_abi_align: $SOME_ALIGN,
randomization_seed: 0,
},
},
mode: Ignore,

View File

@ -1,4 +1,5 @@
//@ normalize-stderr: "pref: Align\([1-8] bytes\)" -> "pref: $$SOME_ALIGN"
//@ normalize-stderr: "randomization_seed: \d+" -> "randomization_seed: $$SEED"
#![feature(never_type, rustc_attrs, type_alias_impl_trait, repr_simd)]
#![crate_type = "lib"]

View File

@ -1,5 +1,5 @@
error: unions cannot have zero fields
--> $DIR/debug.rs:82:1
--> $DIR/debug.rs:83:1
|
LL | union EmptyUnion {}
| ^^^^^^^^^^^^^^^^^^^
@ -61,6 +61,7 @@ error: layout_of(E) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
},
Layout {
size: Size(12 bytes),
@ -87,13 +88,15 @@ error: layout_of(E) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
}
--> $DIR/debug.rs:7:1
--> $DIR/debug.rs:8:1
|
LL | enum E { Foo, Bar(!, i32, i32) }
| ^^^^^^
@ -138,8 +141,9 @@ error: layout_of(S) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
}
--> $DIR/debug.rs:10:1
--> $DIR/debug.rs:11:1
|
LL | struct S { f1: i32, f2: (), f3: i32 }
| ^^^^^^^^
@ -162,8 +166,9 @@ error: layout_of(U) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
}
--> $DIR/debug.rs:13:1
--> $DIR/debug.rs:14:1
|
LL | union U { f1: (i32, i32), f3: i32 }
| ^^^^^^^
@ -255,6 +260,7 @@ error: layout_of(Result<i32, i32>) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
},
Layout {
size: Size(8 bytes),
@ -292,13 +298,15 @@ error: layout_of(Result<i32, i32>) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
}
--> $DIR/debug.rs:16:1
--> $DIR/debug.rs:17:1
|
LL | type Test = Result<i32, i32>;
| ^^^^^^^^^
@ -325,8 +333,9 @@ error: layout_of(i32) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
}
--> $DIR/debug.rs:19:1
--> $DIR/debug.rs:20:1
|
LL | type T = impl std::fmt::Debug;
| ^^^^^^
@ -349,8 +358,9 @@ error: layout_of(V) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(2 bytes),
randomization_seed: $SEED,
}
--> $DIR/debug.rs:25:1
--> $DIR/debug.rs:26:1
|
LL | pub union V {
| ^^^^^^^^^^^
@ -373,8 +383,9 @@ error: layout_of(W) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(2 bytes),
randomization_seed: $SEED,
}
--> $DIR/debug.rs:31:1
--> $DIR/debug.rs:32:1
|
LL | pub union W {
| ^^^^^^^^^^^
@ -397,8 +408,9 @@ error: layout_of(Y) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(2 bytes),
randomization_seed: $SEED,
}
--> $DIR/debug.rs:37:1
--> $DIR/debug.rs:38:1
|
LL | pub union Y {
| ^^^^^^^^^^^
@ -421,8 +433,9 @@ error: layout_of(P1) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
}
--> $DIR/debug.rs:44:1
--> $DIR/debug.rs:45:1
|
LL | union P1 { x: u32 }
| ^^^^^^^^
@ -445,8 +458,9 @@ error: layout_of(P2) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
}
--> $DIR/debug.rs:48:1
--> $DIR/debug.rs:49:1
|
LL | union P2 { x: (u32, u32) }
| ^^^^^^^^
@ -469,8 +483,9 @@ error: layout_of(P3) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
}
--> $DIR/debug.rs:56:1
--> $DIR/debug.rs:57:1
|
LL | union P3 { x: F32x4 }
| ^^^^^^^^
@ -493,8 +508,9 @@ error: layout_of(P4) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
}
--> $DIR/debug.rs:60:1
--> $DIR/debug.rs:61:1
|
LL | union P4 { x: E }
| ^^^^^^^^
@ -522,8 +538,9 @@ error: layout_of(P5) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
}
--> $DIR/debug.rs:64:1
--> $DIR/debug.rs:65:1
|
LL | union P5 { zst: [u16; 0], byte: u8 }
| ^^^^^^^^
@ -551,20 +568,21 @@ error: layout_of(MaybeUninit<u8>) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
}
--> $DIR/debug.rs:67:1
--> $DIR/debug.rs:68:1
|
LL | type X = std::mem::MaybeUninit<u8>;
| ^^^^^^
error: `#[rustc_layout]` can only be applied to `struct`/`enum`/`union` declarations and type aliases
--> $DIR/debug.rs:70:1
--> $DIR/debug.rs:71:1
|
LL | const C: () = ();
| ^^^^^^^^^^^
error[E0277]: the size for values of type `str` cannot be known at compilation time
--> $DIR/debug.rs:78:19
--> $DIR/debug.rs:79:19
|
LL | type Impossible = (str, str);
| ^^^^^^^^^^ doesn't have a size known at compile-time
@ -573,13 +591,13 @@ LL | type Impossible = (str, str);
= note: only the last element of a tuple may have a dynamically sized type
error: the type `EmptyUnion` has an unknown layout
--> $DIR/debug.rs:82:1
--> $DIR/debug.rs:83:1
|
LL | union EmptyUnion {}
| ^^^^^^^^^^^^^^^^
error: `#[rustc_layout]` can only be applied to `struct`/`enum`/`union` declarations and type aliases
--> $DIR/debug.rs:74:5
--> $DIR/debug.rs:75:5
|
LL | const C: () = ();
| ^^^^^^^^^^^

View File

@ -1,4 +1,5 @@
//@ compile-flags: --target hexagon-unknown-linux-musl
//@ normalize-stderr: "randomization_seed: \d+" -> "randomization_seed: $$SEED"
//@ needs-llvm-components: hexagon
//
// Verify that the hexagon targets implement the repr(C) for enums correctly.

View File

@ -61,13 +61,15 @@ error: layout_of(A) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
}
--> $DIR/hexagon-enum.rs:16:1
--> $DIR/hexagon-enum.rs:17:1
|
LL | enum A { Apple }
| ^^^^^^
@ -135,13 +137,15 @@ error: layout_of(B) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
}
--> $DIR/hexagon-enum.rs:20:1
--> $DIR/hexagon-enum.rs:21:1
|
LL | enum B { Banana = 255, }
| ^^^^^^
@ -209,13 +213,15 @@ error: layout_of(C) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(2 bytes),
randomization_seed: $SEED,
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(2 bytes),
randomization_seed: $SEED,
}
--> $DIR/hexagon-enum.rs:24:1
--> $DIR/hexagon-enum.rs:25:1
|
LL | enum C { Chaenomeles = 256, }
| ^^^^^^
@ -283,13 +289,15 @@ error: layout_of(P) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
}
--> $DIR/hexagon-enum.rs:28:1
--> $DIR/hexagon-enum.rs:29:1
|
LL | enum P { Peach = 0x1000_0000isize, }
| ^^^^^^
@ -357,13 +365,15 @@ error: layout_of(T) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
}
--> $DIR/hexagon-enum.rs:34:1
--> $DIR/hexagon-enum.rs:35:1
|
LL | enum T { Tangerine = TANGERINE as isize }
| ^^^^^^

View File

@ -1,4 +1,5 @@
//@ normalize-stderr: "pref: Align\([1-8] bytes\)" -> "pref: $$PREF_ALIGN"
//@ normalize-stderr: "randomization_seed: \d+" -> "randomization_seed: $$SEED"
#![crate_type = "lib"]
#![feature(rustc_attrs)]

View File

@ -83,6 +83,7 @@ error: layout_of(MissingPayloadField) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
},
Layout {
size: Size(1 bytes),
@ -103,13 +104,15 @@ error: layout_of(MissingPayloadField) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
}
--> $DIR/issue-96158-scalarpair-payload-might-be-uninit.rs:16:1
--> $DIR/issue-96158-scalarpair-payload-might-be-uninit.rs:17:1
|
LL | pub enum MissingPayloadField {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -201,6 +204,7 @@ error: layout_of(CommonPayloadField) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
},
Layout {
size: Size(2 bytes),
@ -238,13 +242,15 @@ error: layout_of(CommonPayloadField) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
}
--> $DIR/issue-96158-scalarpair-payload-might-be-uninit.rs:25:1
--> $DIR/issue-96158-scalarpair-payload-might-be-uninit.rs:26:1
|
LL | pub enum CommonPayloadField {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -334,6 +340,7 @@ error: layout_of(CommonPayloadFieldIsMaybeUninit) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
},
Layout {
size: Size(2 bytes),
@ -370,13 +377,15 @@ error: layout_of(CommonPayloadFieldIsMaybeUninit) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
}
--> $DIR/issue-96158-scalarpair-payload-might-be-uninit.rs:33:1
--> $DIR/issue-96158-scalarpair-payload-might-be-uninit.rs:34:1
|
LL | pub enum CommonPayloadFieldIsMaybeUninit {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -482,6 +491,7 @@ error: layout_of(NicheFirst) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
},
Layout {
size: Size(0 bytes),
@ -502,6 +512,7 @@ error: layout_of(NicheFirst) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
},
Layout {
size: Size(0 bytes),
@ -522,13 +533,15 @@ error: layout_of(NicheFirst) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
}
--> $DIR/issue-96158-scalarpair-payload-might-be-uninit.rs:41:1
--> $DIR/issue-96158-scalarpair-payload-might-be-uninit.rs:42:1
|
LL | pub enum NicheFirst {
| ^^^^^^^^^^^^^^^^^^^
@ -634,6 +647,7 @@ error: layout_of(NicheSecond) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
},
Layout {
size: Size(0 bytes),
@ -654,6 +668,7 @@ error: layout_of(NicheSecond) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
},
Layout {
size: Size(0 bytes),
@ -674,13 +689,15 @@ error: layout_of(NicheSecond) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
}
--> $DIR/issue-96158-scalarpair-payload-might-be-uninit.rs:50:1
--> $DIR/issue-96158-scalarpair-payload-might-be-uninit.rs:51:1
|
LL | pub enum NicheSecond {
| ^^^^^^^^^^^^^^^^^^^^

View File

@ -1,4 +1,5 @@
//@ normalize-stderr: "pref: Align\([1-8] bytes\)" -> "pref: $$PREF_ALIGN"
//@ normalize-stderr: "randomization_seed: \d+" -> "randomization_seed: $$SEED"
#![crate_type = "lib"]
#![feature(rustc_attrs)]

View File

@ -57,6 +57,7 @@ error: layout_of(Aligned1) = Layout {
Align(8 bytes),
),
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
},
Layout {
size: Size(8 bytes),
@ -79,6 +80,7 @@ error: layout_of(Aligned1) = Layout {
Align(8 bytes),
),
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
},
],
},
@ -86,8 +88,9 @@ error: layout_of(Aligned1) = Layout {
Align(8 bytes),
),
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
}
--> $DIR/issue-96185-overaligned-enum.rs:8:1
--> $DIR/issue-96185-overaligned-enum.rs:9:1
|
LL | pub enum Aligned1 {
| ^^^^^^^^^^^^^^^^^
@ -157,6 +160,7 @@ error: layout_of(Aligned2) = Layout {
Align(1 bytes),
),
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
},
Layout {
size: Size(1 bytes),
@ -179,6 +183,7 @@ error: layout_of(Aligned2) = Layout {
Align(1 bytes),
),
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
},
],
},
@ -186,8 +191,9 @@ error: layout_of(Aligned2) = Layout {
Align(1 bytes),
),
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
}
--> $DIR/issue-96185-overaligned-enum.rs:16:1
--> $DIR/issue-96185-overaligned-enum.rs:17:1
|
LL | pub enum Aligned2 {
| ^^^^^^^^^^^^^^^^^

View File

@ -0,0 +1,62 @@
//@ run-pass
//@ revisions: normal randomize-layout
//@ [randomize-layout]compile-flags: -Zrandomize-layout -Zlayout-seed=2
#![feature(offset_of_enum)]
use std::ptr;
// these types only have their field offsets taken, they're never constructed
#[allow(dead_code)]
pub struct Foo<T>(u32, T, u8);
#[allow(dead_code)]
pub struct Wrapper<T>(T);
#[repr(transparent)]
#[allow(dead_code)]
pub struct TransparentWrapper(u16);
const _: () = {
// Behavior of the current non-randomized implementation, not guaranteed
#[cfg(not(randomize_layout))]
assert!(std::mem::offset_of!(Foo::<u16>, 1) == std::mem::offset_of!(Foo::<Wrapper<u16>>, 1));
// under randomization Foo<T> != Foo<U>
#[cfg(randomize_layout)]
assert!(std::mem::offset_of!(Foo::<u16>, 1) != std::mem::offset_of!(Foo::<Wrapper<u16>>, 1));
// Even transparent wrapper inner types get a different layout since associated type
// specialization could result in the outer type behaving differently depending on the exact
// inner type.
#[cfg(randomize_layout)]
assert!(
std::mem::offset_of!(Foo::<u16>, 1) != std::mem::offset_of!(Foo::<TransparentWrapper>, 1)
);
// Currently all fn pointers are treated interchangably even with randomization. Not guaranteed.
// Associated type specialization could also break this.
assert!(
std::mem::offset_of!(Foo::<fn(u32)>, 1) == std::mem::offset_of!(Foo::<fn() -> usize>, 1)
);
// But subtype coercions must always result in the same layout.
assert!(
std::mem::offset_of!(Foo::<fn(&u32)>, 1) == std::mem::offset_of!(Foo::<fn(&'static u32)>, 1)
);
// Randomization must uphold NPO guarantees
assert!(std::mem::offset_of!(Option::<&usize>, Some.0) == 0);
assert!(std::mem::offset_of!(Result::<&usize, ()>, Ok.0) == 0);
};
#[allow(dead_code)]
struct Unsizable<T: ?Sized>(usize, T);
fn main() {
// offset_of doesn't let us probe the unsized field, check at runtime.
let x = &Unsizable::<[u32; 4]>(0, [0; 4]);
let y: &Unsizable::<[u32]> = x;
// type coercion must not change the layout.
assert_eq!(ptr::from_ref(&x.1).addr(), ptr::from_ref(&y.1).addr());
}

View File

@ -1,4 +1,5 @@
//@ compile-flags: --target thumbv8m.main-none-eabihf
//@ normalize-stderr: "randomization_seed: \d+" -> "randomization_seed: $$SEED"
//@ needs-llvm-components: arm
//
// Verify that thumb targets implement the repr(C) for enums correctly.

View File

@ -61,13 +61,15 @@ error: layout_of(A) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
}
--> $DIR/thumb-enum.rs:16:1
--> $DIR/thumb-enum.rs:17:1
|
LL | enum A { Apple }
| ^^^^^^
@ -135,13 +137,15 @@ error: layout_of(B) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
}
--> $DIR/thumb-enum.rs:20:1
--> $DIR/thumb-enum.rs:21:1
|
LL | enum B { Banana = 255, }
| ^^^^^^
@ -209,13 +213,15 @@ error: layout_of(C) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(2 bytes),
randomization_seed: $SEED,
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(2 bytes),
randomization_seed: $SEED,
}
--> $DIR/thumb-enum.rs:24:1
--> $DIR/thumb-enum.rs:25:1
|
LL | enum C { Chaenomeles = 256, }
| ^^^^^^
@ -283,13 +289,15 @@ error: layout_of(P) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
}
--> $DIR/thumb-enum.rs:28:1
--> $DIR/thumb-enum.rs:29:1
|
LL | enum P { Peach = 0x1000_0000isize, }
| ^^^^^^
@ -357,13 +365,15 @@ error: layout_of(T) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
}
--> $DIR/thumb-enum.rs:34:1
--> $DIR/thumb-enum.rs:35:1
|
LL | enum T { Tangerine = TANGERINE as isize }
| ^^^^^^

View File

@ -1,4 +1,5 @@
//@ normalize-stderr: "pref: Align\([1-8] bytes\)" -> "pref: $$PREF_ALIGN"
//@ normalize-stderr: "randomization_seed: \d+" -> "randomization_seed: $$SEED"
#![crate_type = "lib"]
#![feature(rustc_attrs)]

View File

@ -59,6 +59,7 @@ error: layout_of(Result<[u32; 0], bool>) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
},
Layout {
size: Size(2 bytes),
@ -92,13 +93,15 @@ error: layout_of(Result<[u32; 0], bool>) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
}
--> $DIR/zero-sized-array-enum-niche.rs:13:1
--> $DIR/zero-sized-array-enum-niche.rs:14:1
|
LL | type AlignedResult = Result<[u32; 0], bool>;
| ^^^^^^^^^^^^^^^^^^
@ -164,6 +167,7 @@ error: layout_of(MultipleAlignments) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(2 bytes),
randomization_seed: $SEED,
},
Layout {
size: Size(4 bytes),
@ -188,6 +192,7 @@ error: layout_of(MultipleAlignments) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
},
Layout {
size: Size(2 bytes),
@ -221,13 +226,15 @@ error: layout_of(MultipleAlignments) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
}
--> $DIR/zero-sized-array-enum-niche.rs:21:1
--> $DIR/zero-sized-array-enum-niche.rs:22:1
|
LL | enum MultipleAlignments {
| ^^^^^^^^^^^^^^^^^^^^^^^
@ -293,6 +300,7 @@ error: layout_of(Result<[u32; 0], Packed<NonZero<u16>>>) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
},
Layout {
size: Size(3 bytes),
@ -326,13 +334,15 @@ error: layout_of(Result<[u32; 0], Packed<NonZero<u16>>>) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
}
--> $DIR/zero-sized-array-enum-niche.rs:37:1
--> $DIR/zero-sized-array-enum-niche.rs:38:1
|
LL | type NicheLosesToTagged = Result<[u32; 0], Packed<std::num::NonZero<u16>>>;
| ^^^^^^^^^^^^^^^^^^^^^^^
@ -402,6 +412,7 @@ error: layout_of(Result<[u32; 0], Packed<U16IsZero>>) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
},
Layout {
size: Size(2 bytes),
@ -435,13 +446,15 @@ error: layout_of(Result<[u32; 0], Packed<U16IsZero>>) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
}
--> $DIR/zero-sized-array-enum-niche.rs:44:1
--> $DIR/zero-sized-array-enum-niche.rs:45:1
|
LL | type NicheWinsOverTagged = Result<[u32; 0], Packed<U16IsZero>>;
| ^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -55,13 +55,15 @@ error: layout_of(Univariant) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
}
--> $DIR/repr-c-dead-variants.rs:38:1
--> $DIR/repr-c-dead-variants.rs:39:1
|
LL | enum Univariant {
| ^^^^^^^^^^^^^^^
@ -137,6 +139,7 @@ error: layout_of(TwoVariants) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
},
Layout {
size: Size(8 bytes),
@ -173,13 +176,15 @@ error: layout_of(TwoVariants) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
}
--> $DIR/repr-c-dead-variants.rs:45:1
--> $DIR/repr-c-dead-variants.rs:46:1
|
LL | enum TwoVariants {
| ^^^^^^^^^^^^^^^^
@ -247,6 +252,7 @@ error: layout_of(DeadBranchHasOtherField) = Layout {
Align(8 bytes),
),
unadjusted_abi_align: Align(8 bytes),
randomization_seed: $SEED,
},
Layout {
size: Size(16 bytes),
@ -271,6 +277,7 @@ error: layout_of(DeadBranchHasOtherField) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(8 bytes),
randomization_seed: $SEED,
},
],
},
@ -278,8 +285,9 @@ error: layout_of(DeadBranchHasOtherField) = Layout {
Align(8 bytes),
),
unadjusted_abi_align: Align(8 bytes),
randomization_seed: $SEED,
}
--> $DIR/repr-c-dead-variants.rs:57:1
--> $DIR/repr-c-dead-variants.rs:58:1
|
LL | enum DeadBranchHasOtherField {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -55,13 +55,15 @@ error: layout_of(Univariant) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
}
--> $DIR/repr-c-dead-variants.rs:38:1
--> $DIR/repr-c-dead-variants.rs:39:1
|
LL | enum Univariant {
| ^^^^^^^^^^^^^^^
@ -137,6 +139,7 @@ error: layout_of(TwoVariants) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
},
Layout {
size: Size(2 bytes),
@ -173,13 +176,15 @@ error: layout_of(TwoVariants) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
}
--> $DIR/repr-c-dead-variants.rs:45:1
--> $DIR/repr-c-dead-variants.rs:46:1
|
LL | enum TwoVariants {
| ^^^^^^^^^^^^^^^^
@ -247,6 +252,7 @@ error: layout_of(DeadBranchHasOtherField) = Layout {
Align(8 bytes),
),
unadjusted_abi_align: Align(8 bytes),
randomization_seed: $SEED,
},
Layout {
size: Size(16 bytes),
@ -271,6 +277,7 @@ error: layout_of(DeadBranchHasOtherField) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(8 bytes),
randomization_seed: $SEED,
},
],
},
@ -278,8 +285,9 @@ error: layout_of(DeadBranchHasOtherField) = Layout {
Align(8 bytes),
),
unadjusted_abi_align: Align(8 bytes),
randomization_seed: $SEED,
}
--> $DIR/repr-c-dead-variants.rs:57:1
--> $DIR/repr-c-dead-variants.rs:58:1
|
LL | enum DeadBranchHasOtherField {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -55,13 +55,15 @@ error: layout_of(Univariant) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
}
--> $DIR/repr-c-dead-variants.rs:38:1
--> $DIR/repr-c-dead-variants.rs:39:1
|
LL | enum Univariant {
| ^^^^^^^^^^^^^^^
@ -137,6 +139,7 @@ error: layout_of(TwoVariants) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
},
Layout {
size: Size(8 bytes),
@ -173,13 +176,15 @@ error: layout_of(TwoVariants) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
}
--> $DIR/repr-c-dead-variants.rs:45:1
--> $DIR/repr-c-dead-variants.rs:46:1
|
LL | enum TwoVariants {
| ^^^^^^^^^^^^^^^^
@ -247,6 +252,7 @@ error: layout_of(DeadBranchHasOtherField) = Layout {
Align(8 bytes),
),
unadjusted_abi_align: Align(8 bytes),
randomization_seed: $SEED,
},
Layout {
size: Size(16 bytes),
@ -271,6 +277,7 @@ error: layout_of(DeadBranchHasOtherField) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(8 bytes),
randomization_seed: $SEED,
},
],
},
@ -278,8 +285,9 @@ error: layout_of(DeadBranchHasOtherField) = Layout {
Align(8 bytes),
),
unadjusted_abi_align: Align(8 bytes),
randomization_seed: $SEED,
}
--> $DIR/repr-c-dead-variants.rs:57:1
--> $DIR/repr-c-dead-variants.rs:58:1
|
LL | enum DeadBranchHasOtherField {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -7,6 +7,7 @@
// See also: repr-c-int-dead-variants.rs
//@ normalize-stderr: "pref: Align\([1-8] bytes\)" -> "pref: $$SOME_ALIGN"
//@ normalize-stderr: "randomization_seed: \d+" -> "randomization_seed: $$SEED"
// This test depends on the value of the `c_enum_min_bits` target option.
// As there's no way to actually check it from UI test, we only run this test on a subset of archs.

View File

@ -55,13 +55,15 @@ error: layout_of(Univariant) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
}
--> $DIR/repr-c-dead-variants.rs:38:1
--> $DIR/repr-c-dead-variants.rs:39:1
|
LL | enum Univariant {
| ^^^^^^^^^^^^^^^
@ -137,6 +139,7 @@ error: layout_of(TwoVariants) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
},
Layout {
size: Size(8 bytes),
@ -173,13 +176,15 @@ error: layout_of(TwoVariants) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
}
--> $DIR/repr-c-dead-variants.rs:45:1
--> $DIR/repr-c-dead-variants.rs:46:1
|
LL | enum TwoVariants {
| ^^^^^^^^^^^^^^^^
@ -247,6 +252,7 @@ error: layout_of(DeadBranchHasOtherField) = Layout {
Align(8 bytes),
),
unadjusted_abi_align: Align(8 bytes),
randomization_seed: $SEED,
},
Layout {
size: Size(16 bytes),
@ -271,6 +277,7 @@ error: layout_of(DeadBranchHasOtherField) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(8 bytes),
randomization_seed: $SEED,
},
],
},
@ -278,8 +285,9 @@ error: layout_of(DeadBranchHasOtherField) = Layout {
Align(8 bytes),
),
unadjusted_abi_align: Align(8 bytes),
randomization_seed: $SEED,
}
--> $DIR/repr-c-dead-variants.rs:57:1
--> $DIR/repr-c-dead-variants.rs:58:1
|
LL | enum DeadBranchHasOtherField {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -4,6 +4,7 @@
// See also: repr-c-dead-variants.rs
//@ normalize-stderr: "pref: Align\([1-8] bytes\)" -> "pref: $$SOME_ALIGN"
//@ normalize-stderr: "randomization_seed: \d+" -> "randomization_seed: $$SEED"
// A simple uninhabited type.
enum Void {}

View File

@ -55,13 +55,15 @@ error: layout_of(UnivariantU8) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
}
--> $DIR/repr-c-int-dead-variants.rs:14:1
--> $DIR/repr-c-int-dead-variants.rs:15:1
|
LL | enum UnivariantU8 {
| ^^^^^^^^^^^^^^^^^
@ -137,6 +139,7 @@ error: layout_of(TwoVariantsU8) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
},
Layout {
size: Size(2 bytes),
@ -173,13 +176,15 @@ error: layout_of(TwoVariantsU8) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
}
--> $DIR/repr-c-int-dead-variants.rs:21:1
--> $DIR/repr-c-int-dead-variants.rs:22:1
|
LL | enum TwoVariantsU8 {
| ^^^^^^^^^^^^^^^^^^
@ -247,6 +252,7 @@ error: layout_of(DeadBranchHasOtherFieldU8) = Layout {
Align(8 bytes),
),
unadjusted_abi_align: Align(8 bytes),
randomization_seed: $SEED,
},
Layout {
size: Size(16 bytes),
@ -271,6 +277,7 @@ error: layout_of(DeadBranchHasOtherFieldU8) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(8 bytes),
randomization_seed: $SEED,
},
],
},
@ -278,8 +285,9 @@ error: layout_of(DeadBranchHasOtherFieldU8) = Layout {
Align(8 bytes),
),
unadjusted_abi_align: Align(8 bytes),
randomization_seed: $SEED,
}
--> $DIR/repr-c-int-dead-variants.rs:33:1
--> $DIR/repr-c-int-dead-variants.rs:34:1
|
LL | enum DeadBranchHasOtherFieldU8 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -3,6 +3,7 @@
#![allow(incomplete_features)]
//@ normalize-stderr: "pref: Align\([1-8] bytes\)" -> "pref: $$SOME_ALIGN"
//@ normalize-stderr: "randomization_seed: \d+" -> "randomization_seed: $$SEED"
use std::pat::pattern_type;

View File

@ -36,8 +36,9 @@ error: layout_of(NonZero<u32>) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
}
--> $DIR/range_patterns.rs:10:1
--> $DIR/range_patterns.rs:11:1
|
LL | type X = std::num::NonZeroU32;
| ^^^^^^
@ -73,8 +74,9 @@ error: layout_of((u32) is 1..=) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
}
--> $DIR/range_patterns.rs:12:1
--> $DIR/range_patterns.rs:13:1
|
LL | type Y = pattern_type!(u32 is 1..);
| ^^^^^^
@ -137,6 +139,7 @@ error: layout_of(Option<(u32) is 1..=>) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
},
Layout {
size: Size(4 bytes),
@ -176,13 +179,15 @@ error: layout_of(Option<(u32) is 1..=>) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
}
--> $DIR/range_patterns.rs:14:1
--> $DIR/range_patterns.rs:15:1
|
LL | type Z = Option<pattern_type!(u32 is 1..)>;
| ^^^^^^
@ -245,6 +250,7 @@ error: layout_of(Option<NonZero<u32>>) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(1 bytes),
randomization_seed: $SEED,
},
Layout {
size: Size(4 bytes),
@ -284,13 +290,15 @@ error: layout_of(Option<NonZero<u32>>) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
},
],
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
}
--> $DIR/range_patterns.rs:16:1
--> $DIR/range_patterns.rs:17:1
|
LL | type A = Option<std::num::NonZeroU32>;
| ^^^^^^
@ -333,8 +341,9 @@ error: layout_of(NonZeroU32New) = Layout {
},
max_repr_align: None,
unadjusted_abi_align: Align(4 bytes),
randomization_seed: $SEED,
}
--> $DIR/range_patterns.rs:18:1
--> $DIR/range_patterns.rs:19:1
|
LL | struct NonZeroU32New(pattern_type!(u32 is 1..));
| ^^^^^^^^^^^^^^^^^^^^