From bd2b80d6ac582b9f0bcd96c86d4b79bfdb64eca1 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Fri, 11 Sep 2026 09:11:47 +0200 Subject: Implement aligned attribute --- gcc/gcc/elna-builtins.cc | 13 +++++++++++-- gcc/gcc/elna-generic.cc | 13 ++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) (limited to 'gcc') diff --git a/gcc/gcc/elna-builtins.cc b/gcc/gcc/elna-builtins.cc index 7d2f8f0..2dc1147 100644 --- a/gcc/gcc/elna-builtins.cc +++ b/gcc/gcc/elna-builtins.cc @@ -116,14 +116,21 @@ namespace elna::gcc return builtin_table; } - static tree build_composite_type(const boot::ordered_map& fields, + static tree build_composite_type(const boot::ordered_map& fields, tree composite_type_node, const std::shared_ptr& symbols) { for (const auto& field : fields) { - tree rewritten_field = get_inner_alias(field.second, symbols); + tree rewritten_field = get_inner_alias(field.second.field_type, symbols); tree field_declaration = build_field(UNKNOWN_LOCATION, composite_type_node, field.first, rewritten_field); + + if (field.second.alignment.has_value()) + { + SET_DECL_ALIGN(field_declaration, field.second.alignment.value() * BITS_PER_UNIT); + DECL_USER_ALIGN(field_declaration) = 1; + DECL_PACKED(field_declaration) = 1; + } TYPE_FIELDS(composite_type_node) = chainon(TYPE_FIELDS(composite_type_node), field_declaration); } return composite_type_node; @@ -148,6 +155,8 @@ namespace elna::gcc } TYPE_SIZE_UNIT(record_type) = size_int(record_layout.value().size); TYPE_SIZE(record_type) = bitsize_int(record_layout.value().size * BITS_PER_UNIT); + SET_TYPE_ALIGN(record_type, record_layout.value().alignment * BITS_PER_UNIT); + TYPE_USER_ALIGN(record_type) = static_cast(subject->alignment.has_value()); return true; } diff --git a/gcc/gcc/elna-generic.cc b/gcc/gcc/elna-generic.cc index b67e91c..8ab6762 100644 --- a/gcc/gcc/elna-generic.cc +++ b/gcc/gcc/elna-generic.cc @@ -744,13 +744,20 @@ namespace elna::gcc for (const auto& variable_identifier : declaration->identifiers) { const location_t declaration_location = get_location(&declaration->position()); - tree declaration_tree = this->symbols->lookup(variable_identifier.name()); + const std::string& variable_name = variable_identifier.name(); + tree declaration_tree = this->symbols->lookup(variable_name); - auto variable_symbol = this->bag.lookup(variable_identifier.name())->is_variable(); + auto variable_symbol = this->bag.lookup(variable_name)->is_variable(); if (declaration_tree == NULL_TREE) { - declaration_tree = declare_variable(variable_identifier.name(), *variable_symbol, this->symbols); + declaration_tree = declare_variable(variable_name, *variable_symbol, this->symbols); + } + if (variable_symbol->alignment.has_value()) + { + SET_DECL_ALIGN(declaration_tree, + variable_symbol->alignment.value() * BITS_PER_UNIT); + DECL_USER_ALIGN(declaration_tree) = 1; } if (variable_symbol->value.has_value()) { -- cgit v1.2.3