@@ -812,6 +812,19 @@ std::string smt2_convt::type2id(const typet &type) const
812
812
{
813
813
return type2id (ns.follow_tag (to_c_enum_tag_type (type)).subtype ());
814
814
}
815
+ else if (type.id () == ID_c_bit_field)
816
+ {
817
+ const auto &c_bit_field_type = to_c_bit_field_type (type);
818
+ // use underlying type
819
+ if (c_bit_field_type.subtype ().id () == ID_unsignedbv)
820
+ return type2id (unsignedbv_typet (c_bit_field_type.get_width ()));
821
+ else if (c_bit_field_type.subtype ().id () == ID_signedbv)
822
+ return type2id (signedbv_typet (c_bit_field_type.get_width ()));
823
+ else if (c_bit_field_type.subtype ().id () == ID_c_bool)
824
+ return type2id (c_bool_typet (c_bit_field_type.get_width ()));
825
+ else
826
+ UNIMPLEMENTED;
827
+ }
815
828
else
816
829
{
817
830
UNREACHABLE;
@@ -2352,46 +2365,28 @@ void smt2_convt::convert_typecast(const typecast_exprt &expr)
2352
2365
}
2353
2366
else if (dest_type.id ()==ID_floatbv)
2354
2367
{
2368
+ const auto &dest_floatbv_type = to_floatbv_type (dest_type);
2369
+
2355
2370
// Typecast from integer to floating-point should have be been
2356
2371
// converted to ID_floatbv_typecast during symbolic execution,
2357
2372
// adding the rounding mode. See
2358
2373
// smt2_convt::convert_floatbv_typecast.
2359
- // The exception is bool and c_bool to float.
2374
+ // The exceptions are bool and c_bool to float,
2375
+ // and non-semantic conversion.
2360
2376
2361
- if (src_type.id ()== ID_bool)
2377
+ if (src_type.id () == ID_bool || src_type. id () == ID_c_bool )
2362
2378
{
2363
- constant_exprt val (irep_idt (), dest_type);
2364
-
2365
- ieee_floatt a (to_floatbv_type (dest_type));
2366
-
2367
- mp_integer significand ;
2368
- mp_integer exponent;
2369
-
2370
- out << " (ite " ;
2371
- convert_expr (src);
2372
- out << " " ;
2373
-
2374
- significand = 1 ;
2375
- exponent = 0 ;
2376
- a.build (significand , exponent);
2377
- val.set (ID_value, integer2binary (a.pack (), a.spec .width ()));
2378
-
2379
- convert_constant (val);
2380
- out << " " ;
2381
-
2382
- significand = 0 ;
2383
- exponent = 0 ;
2384
- a.build (significand , exponent);
2385
- val.set (ID_value, integer2binary (a.pack (), a.spec .width ()));
2386
-
2387
- convert_constant (val);
2388
- out << " )" ;
2379
+ convert_expr (float_bv (expr));
2389
2380
}
2390
- else if (src_type.id ()==ID_c_bool )
2381
+ else if (src_type.id () == ID_bv )
2391
2382
{
2392
- // turn into proper bool
2393
- const typecast_exprt tmp (src, bool_typet ());
2394
- convert_typecast (typecast_exprt (tmp, dest_type));
2383
+ if (to_bv_type (src_type).get_width () == dest_floatbv_type.get_width ())
2384
+ {
2385
+ // preserve representation, this just changes the type
2386
+ convert_expr (src);
2387
+ }
2388
+ else
2389
+ UNEXPECTEDCASE (" typecast bv -> float with wrong width" );
2395
2390
}
2396
2391
else
2397
2392
UNEXPECTEDCASE (" Unknown typecast " +src_type.id_string ()+" -> float" );
@@ -2429,7 +2424,7 @@ void smt2_convt::convert_typecast(const typecast_exprt &expr)
2429
2424
void smt2_convt::convert_floatbv_typecast (const floatbv_typecast_exprt &expr)
2430
2425
{
2431
2426
const exprt &src=expr.op ();
2432
- // const exprt &rounding_mode= expr.rounding_mode();
2427
+ const exprt &rounding_mode = expr.rounding_mode ();
2433
2428
const typet &src_type=src.type ();
2434
2429
const typet &dest_type=expr.type ();
2435
2430
@@ -2533,6 +2528,14 @@ void smt2_convt::convert_floatbv_typecast(const floatbv_typecast_exprt &expr)
2533
2528
ns.follow_tag (to_c_enum_tag_type (src_type)).subtype ());
2534
2529
convert_floatbv_typecast (tmp);
2535
2530
}
2531
+ else if (src_type.id () == ID_c_bit_field)
2532
+ {
2533
+ // go through underlying type
2534
+ convert_floatbv_typecast (floatbv_typecast_exprt (
2535
+ typecast_exprt (src, to_c_bit_field_type (src_type).subtype ()),
2536
+ rounding_mode,
2537
+ dest_type));
2538
+ }
2536
2539
else
2537
2540
UNEXPECTEDCASE (
2538
2541
" TODO typecast11 " +src_type.id_string ()+" -> " +dest_type.id_string ());
0 commit comments