Skip to content

Commit 8f9b8d9

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 1996c6d commit 8f9b8d9

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
@@ -272,7 +272,10 @@ void c_typecheck_baset::designator_enter(
272272

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

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

464470
dest=&(dest->operands()[index]);
465471
}
@@ -737,8 +743,7 @@ void c_typecheck_baset::increment_designator(designatort &designator)
737743
(components[entry.index].get_is_padding() ||
738744
(components[entry.index].get_anonymous() &&
739745
components[entry.index].type().id() != ID_struct_tag &&
740-
components[entry.index].type().id() != ID_union_tag) ||
741-
components[entry.index].type().id() == ID_code))
746+
components[entry.index].type().id() != ID_union_tag)))
742747
{
743748
entry.index++;
744749
}

src/ansi-c/expr2c.cpp

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

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

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

0 commit comments

Comments
 (0)