Skip to content

Commit cb36f17

Browse files
committed
C front-end: struct components cannot be procedures
Cleanup of unnecessary branches: Any such component would be a function pointer, not an actual code-typed element.
1 parent 5f1dcee commit cb36f17

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/ansi-c/c_typecheck_initializer.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,10 @@ void c_typecheck_baset::designator_enter(
271271

272272
for(const auto &c : struct_type.components())
273273
{
274-
if(c.type().id() != ID_code && !c.get_is_padding())
274+
DATA_INVARIANT(
275+
c.type().id() != ID_code, "struct member must not be of code type");
276+
277+
if(!c.get_is_padding())
275278
{
276279
entry.subtype = c.type();
277280
break;
@@ -456,9 +459,12 @@ exprt::operandst::const_iterator c_typecheck_baset::do_designated_initializer(
456459

457460
DATA_INVARIANT(index<components.size(),
458461
"member designator is bounded by components size");
459-
DATA_INVARIANT(components[index].type().id()!=ID_code &&
460-
!components[index].get_is_padding(),
461-
"member designator points at data member");
462+
DATA_INVARIANT(
463+
components[index].type().id() != ID_code,
464+
"struct member must not be of code type");
465+
DATA_INVARIANT(
466+
!components[index].get_is_padding(),
467+
"member designator points at non-padding member");
462468

463469
dest=&(dest->operands()[index]);
464470
}
@@ -736,8 +742,7 @@ void c_typecheck_baset::increment_designator(designatort &designator)
736742
(components[entry.index].get_is_padding() ||
737743
(components[entry.index].get_anonymous() &&
738744
components[entry.index].type().id() != ID_struct_tag &&
739-
components[entry.index].type().id() != ID_union_tag) ||
740-
components[entry.index].type().id() == ID_code))
745+
components[entry.index].type().id() != ID_union_tag)))
741746
{
742747
entry.index++;
743748
}

src/ansi-c/expr2c.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2073,8 +2073,8 @@ std::string expr2ct::convert_struct(
20732073

20742074
for(const auto &component : struct_type.components())
20752075
{
2076-
if(o_it->type().id()==ID_code)
2077-
continue;
2076+
DATA_INVARIANT(
2077+
o_it->type().id() != ID_code, "struct member must not be of code type");
20782078

20792079
if(component.get_is_padding() && !include_padding_components)
20802080
{

0 commit comments

Comments
 (0)