Skip to content

fix promotion for C bit fields #3717

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion regression/cbmc/Bitfields1/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
KNOWNBUG
CORE
main.c

^EXIT=0$
Expand Down
25 changes: 24 additions & 1 deletion src/ansi-c/c_typecast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,30 @@ c_typecastt::c_typet c_typecastt::get_c_type(
else if(type.id()==ID_complex)
return COMPLEX;
else if(type.id()==ID_c_bit_field)
return get_c_type(to_c_bit_field_type(type).subtype());
{
const auto &bit_field_type = to_c_bit_field_type(type);

// We take the underlying type, and then apply the number
// of bits given
typet underlying_type;

if(bit_field_type.subtype().id() == ID_c_enum_tag)
{
const auto &followed =
ns.follow_tag(to_c_enum_tag_type(bit_field_type.subtype()));
if(followed.is_incomplete())
return INT;
else
underlying_type = followed.subtype();
}
else
underlying_type = bit_field_type.subtype();

const bitvector_typet new_type(
underlying_type.id(), bit_field_type.get_width());

return get_c_type(new_type);
}

return OTHER;
}
Expand Down