File tree Expand file tree Collapse file tree 3 files changed +33
-0
lines changed
regression/ansi-c/array_initialization6 Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ // an array that is larger than MAX_FLATTENED_ARRAY_SIZE
2+ static const unsigned char data [256 * 4 ] = {0x0 , 0x0 };
3+
4+ int main ()
5+ {
6+ return data [0 ];
7+ }
Original file line number Diff line number Diff line change 1+ CORE
2+ main.c
3+
4+ ^EXIT=0$
5+ ^SIGNAL=0$
6+ --
7+ ^warning: ignoring
Original file line number Diff line number Diff line change @@ -397,6 +397,25 @@ exprt::operandst::const_iterator c_typecheck_baset::do_designated_initializer(
397397 if (full_type.id ()==ID_array ||
398398 full_type.id ()==ID_vector)
399399 {
400+ // zero_initializer may have built an array_of expression for a large
401+ // array; as we have a designated initializer we need to have an array of
402+ // individual objects
403+ if (dest->id () == ID_array_of)
404+ {
405+ const array_typet array_type = to_array_type (dest->type ());
406+ const auto array_size = numeric_cast<mp_integer>(array_type.size ());
407+ if (!array_size.has_value ())
408+ {
409+ error ().source_location = value.source_location ();
410+ error () << " cannot zero-initialize array with subtype '"
411+ << to_string (full_type.subtype ()) << " '" << eom;
412+ throw 0 ;
413+ }
414+ const exprt zero = to_array_of_expr (*dest).what ();
415+ *dest = array_exprt{{}, array_type};
416+ dest->operands ().resize (numeric_cast_v<std::size_t >(*array_size), zero);
417+ }
418+
400419 if (index>=dest->operands ().size ())
401420 {
402421 if (full_type.id ()==ID_array &&
You can’t perform that action at this time.
0 commit comments