Skip to content

Commit ab6e2d1

Browse files
author
Daniel Kroening
committed
fix promotion for C bit fields
promotion rules apply to bit-fields, based on number of bits, not based on underlying type
1 parent 5419894 commit ab6e2d1

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

regression/cbmc/Bitfields1/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
CORE
22
main.c
33

44
^EXIT=0$

src/ansi-c/c_typecast.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,30 @@ c_typecastt::c_typet c_typecastt::get_c_type(
354354
else if(type.id()==ID_complex)
355355
return COMPLEX;
356356
else if(type.id()==ID_c_bit_field)
357-
return get_c_type(to_c_bit_field_type(type).subtype());
357+
{
358+
const auto &bit_field_type = to_c_bit_field_type(type);
359+
360+
// We take the underlying type, and then apply the number
361+
// of bits given
362+
typet underlying_type;
363+
364+
if(bit_field_type.subtype().id() == ID_c_enum_tag)
365+
{
366+
const auto &followed =
367+
ns.follow_tag(to_c_enum_tag_type(bit_field_type.subtype()));
368+
if(followed.is_incomplete())
369+
return INT;
370+
else
371+
underlying_type = followed.subtype();
372+
}
373+
else
374+
underlying_type = bit_field_type.subtype();
375+
376+
const bitvector_typet new_type(
377+
underlying_type.id(), bit_field_type.get_width());
378+
379+
return get_c_type(new_type);
380+
}
358381

359382
return OTHER;
360383
}

0 commit comments

Comments
 (0)