Skip to content

Commit 7bdbcb7

Browse files
committed
gccrs: ensure packed and aligned is applied properly
We cannot apply aligned or packed after layout_type is called you need to set this up first then call it. Fixes #3260 gcc/rust/ChangeLog: * backend/rust-compile-type.cc (TyTyResolveCompile::visit): call lauout type directly * rust-backend.h (struct_type): add optional layout parameter (union_type): likewise (fill_in_fields): likewise * rust-gcc.cc (struct_type): likewise (union_type): likewise (fill_in_fields): only layout if we required Signed-off-by: Philip Herron <[email protected]>
1 parent 2aff749 commit 7bdbcb7

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

gcc/rust/backend/rust-compile-type.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "rust-gcc.h"
2323

2424
#include "tree.h"
25+
#include "stor-layout.h"
2526

2627
namespace Rust {
2728
namespace Compile {
@@ -268,8 +269,8 @@ TyTyResolveCompile::visit (const TyTy::ADTType &type)
268269
fields.push_back (std::move (f));
269270
}
270271

271-
type_record = type.is_union () ? Backend::union_type (fields)
272-
: Backend::struct_type (fields);
272+
type_record = type.is_union () ? Backend::union_type (fields, false)
273+
: Backend::struct_type (fields, false);
273274
}
274275
else
275276
{
@@ -359,7 +360,7 @@ TyTyResolveCompile::visit (const TyTy::ADTType &type)
359360
}
360361

361362
// finally make the union or the enum
362-
type_record = Backend::union_type (enum_fields);
363+
type_record = Backend::union_type (enum_fields, false);
363364
}
364365

365366
// Handle repr options
@@ -381,6 +382,7 @@ TyTyResolveCompile::visit (const TyTy::ADTType &type)
381382
SET_TYPE_ALIGN (type_record, repr.align * 8);
382383
TYPE_USER_ALIGN (type_record) = 1;
383384
}
385+
layout_type (type_record);
384386

385387
std::string named_struct_str
386388
= type.get_ident ().path.get () + type.subst_as_string ();

gcc/rust/rust-backend.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,11 @@ function_ptr_type (tree result, const std::vector<tree> &praameters,
133133

134134
// Get a struct type.
135135
tree
136-
struct_type (const std::vector<typed_identifier> &fields);
136+
struct_type (const std::vector<typed_identifier> &fields, bool layout = true);
137137

138138
// Get a union type.
139139
tree
140-
union_type (const std::vector<typed_identifier> &fields);
140+
union_type (const std::vector<typed_identifier> &fields, bool layout = true);
141141

142142
// Get an array type.
143143
tree
@@ -496,7 +496,7 @@ write_global_definitions (const std::vector<tree> &type_decls,
496496
// TODO: make static
497497

498498
tree
499-
fill_in_fields (tree, const std::vector<typed_identifier> &);
499+
fill_in_fields (tree, const std::vector<typed_identifier> &, bool);
500500

501501
tree fill_in_array (tree, tree, tree);
502502

gcc/rust/rust-gcc.cc

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -592,23 +592,24 @@ function_ptr_type (tree result_type, const std::vector<tree> &parameters,
592592
// Make a struct type.
593593

594594
tree
595-
struct_type (const std::vector<typed_identifier> &fields)
595+
struct_type (const std::vector<typed_identifier> &fields, bool layout)
596596
{
597-
return fill_in_fields (make_node (RECORD_TYPE), fields);
597+
return fill_in_fields (make_node (RECORD_TYPE), fields, layout);
598598
}
599599

600600
// Make a union type.
601601

602602
tree
603-
union_type (const std::vector<typed_identifier> &fields)
603+
union_type (const std::vector<typed_identifier> &fields, bool layout)
604604
{
605-
return fill_in_fields (make_node (UNION_TYPE), fields);
605+
return fill_in_fields (make_node (UNION_TYPE), fields, layout);
606606
}
607607

608608
// Fill in the fields of a struct or union type.
609609

610610
tree
611-
fill_in_fields (tree fill, const std::vector<typed_identifier> &fields)
611+
fill_in_fields (tree fill, const std::vector<typed_identifier> &fields,
612+
bool layout)
612613
{
613614
tree field_trees = NULL_TREE;
614615
tree *pp = &field_trees;
@@ -625,7 +626,9 @@ fill_in_fields (tree fill, const std::vector<typed_identifier> &fields)
625626
pp = &DECL_CHAIN (field);
626627
}
627628
TYPE_FIELDS (fill) = field_trees;
628-
layout_type (fill);
629+
630+
if (layout)
631+
layout_type (fill);
629632

630633
// Because Rust permits converting between named struct types and
631634
// equivalent struct types, for which we use VIEW_CONVERT_EXPR, and

0 commit comments

Comments
 (0)