diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-04-29 15:14:48 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-29 15:14:48 +0000 |
commit | f38bf60c3ac7f039db5ff5c7c0587325097892c8 (patch) | |
tree | 3a1bfc617f39ac85074f456c13617cb749cb4bdc /gcc/rust/backend | |
parent | f8a137bd9391733a3d0d7b58f0f30af441e25a5a (diff) | |
parent | fd51331270ed0318144cb0031b21ef710218e2fe (diff) | |
download | gcc-f38bf60c3ac7f039db5ff5c7c0587325097892c8.zip gcc-f38bf60c3ac7f039db5ff5c7c0587325097892c8.tar.gz gcc-f38bf60c3ac7f039db5ff5c7c0587325097892c8.tar.bz2 |
Merge #1188
1188: Support align and packed repr layout on structs r=dafaust a=dafaust
This is a start at handling the various layout options supported by Rust, beginning with `#[repr(align(N))]` and `#[repr(packed(N))]`, on structs and tuple structs.
There are several other layout options which remain to be supported such as `#[repr(C)]`, `#[repr(transparent)]`, combinations e.g. `#[repr(C, packed(2))]`, as well as layouts on union and enum types.
Fixes: #915
Co-authored-by: David Faust <david.faust@oracle.com>
Diffstat (limited to 'gcc/rust/backend')
-rw-r--r-- | gcc/rust/backend/rust-compile-type.cc | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/gcc/rust/backend/rust-compile-type.cc b/gcc/rust/backend/rust-compile-type.cc index 07b95c7..16029ba 100644 --- a/gcc/rust/backend/rust-compile-type.cc +++ b/gcc/rust/backend/rust-compile-type.cc @@ -280,6 +280,26 @@ TyTyResolveCompile::visit (const TyTy::ADTType &type) type_record = ctx->get_backend ()->union_type (enum_fields); } + // Handle repr options + // TODO: "packed" should only narrow type alignment and "align" should only + // widen it. Do we need to check and enforce this here, or is it taken care of + // later on in the gcc middle-end? + TyTy::ADTType::ReprOptions repr = type.get_repr_options (); + if (repr.pack) + { + TYPE_PACKED (type_record); + if (repr.pack > 1) + { + SET_TYPE_ALIGN (type_record, repr.pack * 8); + TYPE_USER_ALIGN (type_record) = 1; + } + } + else if (repr.align) + { + SET_TYPE_ALIGN (type_record, repr.align * 8); + TYPE_USER_ALIGN (type_record) = 1; + } + std::string named_struct_str = type.get_ident ().path.get () + type.subst_as_string (); tree named_struct |