@@ -10,15 +10,16 @@ Author: Daniel Kroening, kroening@kroening.com
1010
1111#include < cstdlib>
1212
13- #include " namespace.h"
14- #include " symbol_table.h"
1513#include " arith_tools.h"
1614#include " cmdline.h"
15+ #include " cprover_prefix.h"
16+ #include " exception_utils.h"
17+ #include " namespace.h"
1718#include " simplify_expr.h"
1819#include " std_expr.h"
19- #include " cprover_prefix.h"
2020#include " string2int.h"
2121#include " string_utils.h"
22+ #include " symbol_table.h"
2223
2324configt config;
2425
@@ -945,20 +946,42 @@ bool configt::set(const cmdlinet &cmdline)
945946 // the same architecture and OS that we are verifying for.
946947 if (arch==this_arch && os==this_os)
947948 {
948- assert (ansi_c.int_width ==sizeof (int )*8 );
949- assert (ansi_c.long_int_width ==sizeof (long )*8 );
950- assert (ansi_c.bool_width ==sizeof (bool )*8 );
951- assert (ansi_c.char_width ==sizeof (char )*8 );
952- assert (ansi_c.short_int_width ==sizeof (short )*8 );
953- assert (ansi_c.long_long_int_width ==sizeof (long long )*8 );
954- assert (ansi_c.pointer_width ==sizeof (void *)*8 );
955- assert (ansi_c.single_width ==sizeof (float )*8 );
956- assert (ansi_c.double_width ==sizeof (double )*8 );
957- assert (ansi_c.char_is_unsigned ==(static_cast <char >(255 )==255 ));
949+ INVARIANT (
950+ ansi_c.int_width == sizeof (int ) * 8 ,
951+ " int width shall be equal to the system int width" );
952+ INVARIANT (
953+ ansi_c.long_int_width == sizeof (long ) * 8 ,
954+ " long int width shall be equal to the system long int width" );
955+ INVARIANT (
956+ ansi_c.bool_width == sizeof (bool ) * 8 ,
957+ " bool width shall be equal to the system bool width" );
958+ INVARIANT (
959+ ansi_c.char_width == sizeof (char ) * 8 ,
960+ " char width shall be equal to the system char width" );
961+ INVARIANT (
962+ ansi_c.short_int_width == sizeof (short ) * 8 ,
963+ " short int width shall be equal to the system short int width" );
964+ INVARIANT (
965+ ansi_c.long_long_int_width == sizeof (long long ) * 8 ,
966+ " long long int width shall be equal to the system long long int width" );
967+ INVARIANT (
968+ ansi_c.pointer_width == sizeof (void *) * 8 ,
969+ " pointer width shall be equal to the system pointer width" );
970+ INVARIANT (
971+ ansi_c.single_width == sizeof (float ) * 8 ,
972+ " float width shall be equal to the system float width" );
973+ INVARIANT (
974+ ansi_c.double_width == sizeof (double ) * 8 ,
975+ " double width shall be equal to the system double width" );
976+ INVARIANT (
977+ ansi_c.char_is_unsigned == (static_cast <char >(255 ) == 255 ),
978+ " char_is_unsigned flag shall indicate system char unsignedness" );
958979
959980 #ifndef _WIN32
960981 // On Windows, long double width varies by compiler
961- assert (ansi_c.long_double_width ==sizeof (long double )*8 );
982+ INVARIANT (
983+ ansi_c.long_double_width == sizeof (long double ) * 8 ,
984+ " long double width shall be equal to the system long double width" );
962985 #endif
963986 }
964987
@@ -1026,14 +1049,17 @@ bool configt::set(const cmdlinet &cmdline)
10261049 {
10271050 bv_encoding.object_bits =
10281051 unsafe_string2unsigned (cmdline.get_value (" object-bits" ));
1029- bv_encoding.is_object_bits_default =false ;
10301052
10311053 if (!(0 <bv_encoding.object_bits &&
10321054 bv_encoding.object_bits <ansi_c.pointer_width ))
10331055 {
1034- throw " object-bits must be positive and less than the pointer width (" +
1035- std::to_string (ansi_c.pointer_width )+" ) " ;
1056+ throw invalid_user_input_exceptiont (
1057+ " object-bits must be positive and less than the pointer width (" +
1058+ std::to_string (ansi_c.pointer_width ) + " ) " ,
1059+ " --object_bits" );
10361060 }
1061+
1062+ bv_encoding.is_object_bits_default = false ;
10371063 }
10381064
10391065 return false ;
@@ -1069,21 +1095,17 @@ static irep_idt string_from_ns(
10691095 const irep_idt id=CPROVER_PREFIX " architecture_" +what;
10701096 const symbolt *symbol;
10711097
1072- if ( ns.lookup (id, symbol))
1073- throw " failed to find " + id2string (id );
1098+ bool not_found = ns.lookup (id, symbol);
1099+ INVARIANT (!not_found, id2string (id) + " must be in namespace " );
10741100
10751101 const exprt &tmp=symbol->value ;
10761102
1077- if (tmp.id ()!=ID_address_of ||
1078- tmp.operands ().size ()!=1 ||
1079- tmp.op0 ().id ()!=ID_index ||
1080- tmp.op0 ().operands ().size ()!=2 ||
1081- tmp.op0 ().op0 ().id ()!=ID_string_constant)
1082- {
1083- throw
1084- " symbol table configuration entry `" +id2string (id)+
1085- " ' is not a string constant" ;
1086- }
1103+ INVARIANT (
1104+ tmp.id () == ID_address_of && tmp.operands ().size () == 1 &&
1105+ tmp.op0 ().id () == ID_index && tmp.op0 ().operands ().size () == 2 &&
1106+ tmp.op0 ().op0 ().id () == ID_string_constant,
1107+ " symbol table configuration entry `" + id2string (id) +
1108+ " ' must be a string constant" );
10871109
10881110 return tmp.op0 ().op0 ().get (ID_value);
10891111}
@@ -1095,21 +1117,24 @@ static unsigned unsigned_from_ns(
10951117 const irep_idt id=CPROVER_PREFIX " architecture_" +what;
10961118 const symbolt *symbol;
10971119
1098- if ( ns.lookup (id, symbol))
1099- throw " failed to find " + id2string (id );
1120+ bool not_found = ns.lookup (id, symbol);
1121+ INVARIANT (!not_found, id2string (id) + " must be in namespace " );
11001122
11011123 exprt tmp=symbol->value ;
11021124 simplify (tmp, ns);
11031125
1104- if (tmp.id ()!=ID_constant)
1105- throw
1106- " symbol table configuration entry `" +id2string (id)+" ' is not a constant" ;
1126+ INVARIANT (
1127+ tmp.id () == ID_constant,
1128+ " symbol table configuration entry `" + id2string (id) +
1129+ " ' must be a constant" );
11071130
11081131 mp_integer int_value;
11091132
1110- if (to_integer (to_constant_expr (tmp), int_value))
1111- throw
1112- " failed to convert symbol table configuration entry `" +id2string (id)+" '" ;
1133+ bool error = to_integer (to_constant_expr (tmp), int_value);
1134+ INVARIANT (
1135+ !error,
1136+ " symbol table configuration entry `" + id2string (id) +
1137+ " ' must be convertible to mp_integer" );
11131138
11141139 return integer2unsigned (int_value);
11151140}
0 commit comments