/[packages]/cauldron/rust/current/SOURCES/0001-rustc_transmute-fix-big-endian-discriminants.patch
ViewVC logotype

Contents of /cauldron/rust/current/SOURCES/0001-rustc_transmute-fix-big-endian-discriminants.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1891745 - (show annotations) (download)
Fri Sep 23 08:40:48 2022 UTC (2 months, 1 week ago) by akien
File size: 2217 byte(s)
Add Patch3 missed in previous commit (SILENT)
1 From 2946828fcb8e2e68a16839dfcf4319bf119f8acd Mon Sep 17 00:00:00 2001
2 From: Josh Stone <jistone@redhat.com>
3 Date: Tue, 20 Sep 2022 13:03:43 -0700
4 Subject: [PATCH] rustc_transmute: fix big-endian discriminants
5
6 (cherry picked from commit a72666ed56ec5f1b6d254c7020cf86143edc6dbd)
7 ---
8 compiler/rustc_transmute/src/layout/tree.rs | 22 +++++++++++++++------
9 1 file changed, 16 insertions(+), 6 deletions(-)
10
11 diff --git a/compiler/rustc_transmute/src/layout/tree.rs b/compiler/rustc_transmute/src/layout/tree.rs
12 index 70b3ba02b05b..e4fcde35ed37 100644
13 --- a/compiler/rustc_transmute/src/layout/tree.rs
14 +++ b/compiler/rustc_transmute/src/layout/tree.rs
15 @@ -402,7 +402,7 @@ fn from_repr_c_variant(
16 .unwrap();
17 tracing::trace!(?discr_layout, "computed discriminant layout");
18 variant_layout = variant_layout.extend(discr_layout).unwrap().0;
19 - tree = tree.then(Self::from_disr(discr, tcx, layout_summary.discriminant_size));
20 + tree = tree.then(Self::from_discr(discr, tcx, layout_summary.discriminant_size));
21 }
22
23 // Next come fields.
24 @@ -442,11 +442,21 @@ fn from_repr_c_variant(
25 Ok(tree)
26 }
27
28 - pub fn from_disr(discr: Discr<'tcx>, tcx: TyCtxt<'tcx>, size: usize) -> Self {
29 - // FIXME(@jswrenn): I'm certain this is missing needed endian nuance.
30 - let bytes = discr.val.to_ne_bytes();
31 - let bytes = &bytes[..size];
32 - Self::Seq(bytes.into_iter().copied().map(|b| Self::from_bits(b)).collect())
33 + pub fn from_discr(discr: Discr<'tcx>, tcx: TyCtxt<'tcx>, size: usize) -> Self {
34 + use rustc_target::abi::Endian;
35 +
36 + let bytes: [u8; 16];
37 + let bytes = match tcx.data_layout.endian {
38 + Endian::Little => {
39 + bytes = discr.val.to_le_bytes();
40 + &bytes[..size]
41 + }
42 + Endian::Big => {
43 + bytes = discr.val.to_be_bytes();
44 + &bytes[bytes.len() - size..]
45 + }
46 + };
47 + Self::Seq(bytes.iter().map(|&b| Self::from_bits(b)).collect())
48 }
49 }
50
51 --
52 2.37.3
53

  ViewVC Help
Powered by ViewVC 1.1.28