Use array range beginning with one

This commit is contained in:
2025-07-17 11:44:42 +02:00
parent 34abb6b4f5
commit 32d4683315
4 changed files with 370 additions and 372 deletions

View File

@ -154,7 +154,9 @@ namespace elna::gcc
} }
else if (constant_expression != boolean_true_node) else if (constant_expression != boolean_true_node)
{ {
this->current_expression = call_built_in(call_location, "__builtin_trap", void_type_node); tree assert_expression = call_built_in(call_location, "__builtin_trap", void_type_node);
this->current_expression = build3(COND_EXPR, void_type_node, this->current_expression,
NULL_TREE, assert_expression);
} }
else else
{ {
@ -486,7 +488,6 @@ namespace elna::gcc
{ {
gcc_unreachable(); gcc_unreachable();
} }
if (left_type == elna_bool_type_node) if (left_type == elna_bool_type_node)
{ {
return build2_loc(expression_location, logical_code, elna_bool_type_node, left, right); return build2_loc(expression_location, logical_code, elna_bool_type_node, left, right);
@ -497,8 +498,7 @@ namespace elna::gcc
} }
else else
{ {
error_at(expression_location, error_at(expression_location, "Invalid operands of type '%s' and '%s' for operator %s",
"Invalid operands of type '%s' and '%s' for operator %s",
print_type(left_type).c_str(), print_type(right_type).c_str(), print_type(left_type).c_str(), print_type(right_type).c_str(),
elna::boot::print_binary_operator(expression->operation())); elna::boot::print_binary_operator(expression->operation()));
return error_mark_node; return error_mark_node;
@ -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

@ -21,7 +21,6 @@ along with GCC; see the file COPYING3. If not see
#include "function.h" #include "function.h"
#include "stor-layout.h" #include "stor-layout.h"
#include "fold-const.h"
#include "diagnostic-core.h" #include "diagnostic-core.h"
namespace elna::gcc namespace elna::gcc
@ -248,9 +247,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);
} }

View File

@ -25,6 +25,7 @@ along with GCC; see the file COPYING3. If not see
#include "tree.h" #include "tree.h"
#include "tree-iterator.h" #include "tree-iterator.h"
#include "stringpool.h" #include "stringpool.h"
#include "fold-const.h"
#include "elna/boot/ast.h" #include "elna/boot/ast.h"
#include "elna/boot/symbol.h" #include "elna/boot/symbol.h"
@ -97,6 +98,8 @@ namespace elna::gcc
tree fndecl_type = build_function_type(return_type, TYPE_ARG_TYPES(*builtin)); tree fndecl_type = build_function_type(return_type, TYPE_ARG_TYPES(*builtin));
tree builtin_addr = build1_loc(call_location, ADDR_EXPR, build_pointer_type(fndecl_type), *builtin); tree builtin_addr = build1_loc(call_location, ADDR_EXPR, build_pointer_type(fndecl_type), *builtin);
return build_call_nary(return_type, builtin_addr, sizeof...(Args), arguments...); tree argument_trees[sizeof...(Args)] = {arguments...};
return fold_build_call_array(return_type, builtin_addr, sizeof...(Args), argument_trees);
} }
} }