@@ -15,6 +15,7 @@ Author: Daniel Kroening, kroening@kroening.com
1515
1616#include < util/c_types.h>
1717#include < util/config.h>
18+ #include < util/invariant.h>
1819#include < util/simplify_expr.h>
1920#include < util/arith_tools.h>
2021#include < util/std_types.h>
@@ -551,9 +552,15 @@ void c_typecheck_baset::typecheck_array_type(array_typet &type)
551552 {
552553 // not a constant and not infinity
553554
554- assert (!current_symbol_id .empty ());
555+ PRECONDITION (!current_symbol. name .empty ());
555556
556- const symbolt &base_symbol=lookup (current_symbol_id);
557+ if (current_symbol.is_static_lifetime )
558+ {
559+ error ().source_location =current_symbol.location ;
560+ error () << " array size of static symbol `"
561+ << current_symbol.base_name << " ' is not constant" << eom;
562+ throw 0 ;
563+ }
557564
558565 // Need to pull out! We insert new symbol.
559566 source_locationt source_location=size.find_source_location ();
@@ -564,7 +571,7 @@ void c_typecheck_baset::typecheck_array_type(array_typet &type)
564571 do
565572 {
566573 suffix=" $array_size" +std::to_string (count);
567- temp_identifier=id2string (base_symbol .name )+suffix;
574+ temp_identifier=id2string (current_symbol .name )+suffix;
568575 count++;
569576 }
570577 while (symbol_table.symbols .find (temp_identifier)!=
@@ -573,13 +580,13 @@ void c_typecheck_baset::typecheck_array_type(array_typet &type)
573580 // add the symbol to symbol table
574581 auxiliary_symbolt new_symbol;
575582 new_symbol.name =temp_identifier;
576- new_symbol.pretty_name =id2string (base_symbol .pretty_name )+suffix;
577- new_symbol.base_name =id2string (base_symbol .base_name )+suffix;
583+ new_symbol.pretty_name =id2string (current_symbol .pretty_name )+suffix;
584+ new_symbol.base_name =id2string (current_symbol .base_name )+suffix;
578585 new_symbol.type =size.type ();
579586 new_symbol.type .set (ID_C_constant, true );
580587 new_symbol.is_type =false ;
581588 new_symbol.is_static_lifetime =false ;
582- new_symbol.value . make_nil () ;
589+ new_symbol.value =size ;
583590 new_symbol.location =source_location;
584591
585592 symbol_table.add (new_symbol);
0 commit comments