Use array range beginning with one

This commit is contained in:
2025-07-17 11:44:42 +02:00
parent 34abb6b4f5
commit d0300b3567
2 changed files with 4 additions and 8 deletions

View File

@@ -810,21 +810,18 @@ namespace elna::gcc
this->current_expression = error_mark_node; this->current_expression = error_mark_node;
return; return;
} }
if (this->current_expression != elna_word_type_node) tree offset = fold_convert(elna_word_type_node, this->current_expression);
{
this->current_expression = convert(elna_word_type_node, this->current_expression);
}
tree offset = build2(MINUS_EXPR, elna_word_type_node, this->current_expression, size_one_node);
if (TREE_CODE(TREE_TYPE(designator)) == ARRAY_TYPE) if (TREE_CODE(TREE_TYPE(designator)) == ARRAY_TYPE)
{ {
tree element_type = TREE_TYPE(TREE_TYPE(designator)); tree element_type = TREE_TYPE(TREE_TYPE(designator));
this->current_expression = build4_loc(location, this->current_expression = build4_loc(location,
ARRAY_REF, element_type, designator, offset, NULL_TREE, NULL_TREE); ARRAY_REF, element_type, designator, offset, size_one_node, NULL_TREE);
} }
else if (TREE_TYPE(designator) == elna_string_type_node) else if (TREE_TYPE(designator) == elna_string_type_node)
{ {
offset = build2(MINUS_EXPR, elna_word_type_node, offset, size_one_node);
tree string_ptr = build3_loc(location, COMPONENT_REF, TREE_TYPE(elna_string_ptr_field_node), tree string_ptr = build3_loc(location, COMPONENT_REF, TREE_TYPE(elna_string_ptr_field_node),
designator, elna_string_ptr_field_node, NULL_TREE); designator, elna_string_ptr_field_node, NULL_TREE);

View File

@@ -248,9 +248,8 @@ namespace elna::gcc
tree build_static_array_type(tree type, const std::uint64_t size) tree build_static_array_type(tree type, const std::uint64_t size)
{ {
tree lower_bound = build_int_cst_type(integer_type_node, 0);
tree upper_bound = build_int_cst_type(integer_type_node, size); tree upper_bound = build_int_cst_type(integer_type_node, size);
tree range_type = build_range_type(integer_type_node, lower_bound, upper_bound); tree range_type = build_range_type(integer_type_node, size_one_node, upper_bound);
return build_array_type(type, range_type); return build_array_type(type, range_type);
} }