Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/decl_inits.c
Original file line number Diff line number Diff line change
Expand Up @@ -1983,7 +1983,7 @@ the position at which diagnostics should be issued.
if (type_is(etype, tk_array)) {
/* The element is a sub-array. Create a single potentially-repeated
initializer for all array levels. */
if (!etype->variant.array.is_vla) {
if (!is_vla_type(etype)) {
count *= num_array_elements(etype);
} else {
/* is->variable_size_array should be TRUE, and therefore we should
Expand Down Expand Up @@ -2037,8 +2037,11 @@ the position at which diagnostics should be issued.
ck_repeat_init on top of it if needed. */
check_assertion(type_is(skip_typerefs(array_con->type), tk_array) &&
constant_is(array_con, ck_aggregate));
if (is->variable_size_array && !is->non_top_level_aggregate) {
/* Something like "new T[x]{...}" where x is a run-time value.
if (is->variable_size_array &&
(!is->non_top_level_aggregate ||
is_vla_type(array_con->type))) {
/* Something like "new T[x]{...}" where x is a run-time value, or
a (possibly nested) VLA such as a row of "T a[2][n] = {...}".
We don't know a priori how many default initializations are
needed, but we have to represent it in some way so that lowering
(or a back end) knows which routine to call. We use a zero count,
Expand Down
9 changes: 8 additions & 1 deletion src/il_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -5353,7 +5353,14 @@ typedef struct a_constant {
zero is used for new and delete of an array, and
means "use the number of elements recorded along
with the storage allocation". A similar case occurs
when initializing a variable-length array. */
when initializing a variable-length array: a count
of zero (which can also appear in a nested
variable-length row of a multidimensional array)
initializes all the remaining elements, a number
known only at run time. In that case the repeated
constant always initializes leaf elements and the
ck_init_repeat is the last constant of its
aggregate. */
a_byte_boolean
multidimensional_aggr_tail_not_repeated;
/* This flag is used to indicate that the repeated
Expand Down
13 changes: 11 additions & 2 deletions src/lower_eh.c
Original file line number Diff line number Diff line change
Expand Up @@ -3406,7 +3406,9 @@ region description entry).
The value put in the table is arbitrary, but use -1. */
elem_count = -1;
elem_type = entity_type;
if (!ipdp->array_element_sequence) {
if (is_array_type(entity_type)) {
/* The count is in elements of the innermost array, both for a whole
VLA and for a sequence of array elements that are arrays. */
elem_type = underlying_array_element_type(entity_type);
} /* if */
} else if (ipdp->array_element_sequence) {
Expand Down Expand Up @@ -4098,6 +4100,12 @@ The region table variable is created if necessary.
set_var_init_pos_descr(dip->variable->vla_element_count_variable, &ipd);
make_handle_for_entity(&ipd, &vla_elem_count_handle, insert_location);
} /* if */
} else if (dedp->runtime_elem_count_var != NULL) {
/* A sequence of array elements whose number is known only at run time
is described like a VLA. */
is_vla = TRUE;
set_var_init_pos_descr(dedp->runtime_elem_count_var, &ipd);
make_handle_for_entity(&ipd, &vla_elem_count_handle, insert_location);
} /* if */
#endif /* ABI_COMPATIBILITY_VERSION < 306 */
dedp->next_in_region_table = next_dip;
Expand Down Expand Up @@ -4207,7 +4215,8 @@ stop_before == NULL means stop at the beginning of the current lifetime.
} else
#endif /* !RUNTIME_VLA_DEALLOCATION_NEEDS_ELEMENT_COUNT */
/* Do not insert code here. */
if (is_dynamic_init_for_vla(dip)) {
if (is_dynamic_init_for_vla(dip) ||
dedp->runtime_elem_count_var != NULL) {
/* The entry has a VLA element count entry, so clone that too. */
(void)clone_raw_region_table_entry(next_entry, &region_number);
} /* if */
Expand Down
7 changes: 6 additions & 1 deletion src/lower_il.c
Original file line number Diff line number Diff line change
Expand Up @@ -4578,7 +4578,12 @@ called in C mode.
handles them correctly. If they are partially initialized, the
first member is (at least partially) initialized, which is all we
need here. */
if (is_array_type(type) && contains_ptr_to_data_member(type)) {
if (is_vla_type(type)) {
/* A constant of VLA type (for an array with rows of variable length)
cannot be filled out; the whole entity is set to its zero value
before the constant's elements are assigned (see
lower_vla_rows_constant_init in lower_init.c). */
} else if (is_array_type(type) && contains_ptr_to_data_member(type)) {
a_targ_size_t elem = 0;
/* Count the number of elements that have been explicitly
initialized. Note that they have previously been run through
Expand Down
19 changes: 19 additions & 0 deletions src/lower_il.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,15 @@ typedef struct an_init_pos_descr {
lowered. Such an element cannot refer to that
aggregate through an implicit "this" (see
lower_param_ref). */
a_byte_boolean
assign_constants;
/* TRUE if no part of the initialization can be kept
as a constant, so that constants must be assigned
by executable code even though the entity is a
simple variable. This is the case for an array
with rows of variable length, which can be neither
initialized by a C initializer nor copied from a
static constant. */
a_type_ptr base_type;
/* Base entity type. */
an_init_pos_modifier_ptr
Expand Down Expand Up @@ -337,6 +346,16 @@ typedef struct a_destructible_entity_descr {
slightly different than the front end order
(reflected by the dynamic init
next_in_destruction_list pointer). */
a_variable_ptr
runtime_elem_count_var;
/* When exceptions are enabled and the entity is a
sequence of array elements whose number is known
only at run time (e.g., the default-initialized
remainder of a row of a partially initialized
multidimensional variable-length array), points to
a size_t variable holding that number, which the
region table entry refers to like the element count
of a VLA. NULL otherwise. */
#endif /* GENERATE_EH_TABLES */
a_byte_boolean
initialization_done;
Expand Down
Loading
Loading