Skip to content

Commit 0060417

Browse files
authored
Merge pull request #6892 from tautschnig/cleanup/no-code
GOTO programs do not have code-typed struct members
2 parents f254d1a + 4c8e44b commit 0060417

File tree

10 files changed

+76
-66
lines changed

10 files changed

+76
-66
lines changed

jbmc/src/java_bytecode/expr2java.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -126,34 +126,34 @@ std::string expr2javat::convert_struct(
126126

127127
for(const auto &c : components)
128128
{
129-
if(c.type().id() != ID_code)
130-
{
131-
std::string tmp=convert(*o_it);
132-
std::string sep;
129+
DATA_INVARIANT(
130+
c.type().id() != ID_code, "struct member must not be of code type");
133131

134-
if(first)
135-
first=false;
136-
else
132+
std::string tmp = convert(*o_it);
133+
std::string sep;
134+
135+
if(first)
136+
first = false;
137+
else
138+
{
139+
if(last_size + 40 < dest.size())
137140
{
138-
if(last_size+40<dest.size())
139-
{
140-
sep=",\n ";
141-
last_size=dest.size();
142-
}
143-
else
144-
sep=", ";
141+
sep = ",\n ";
142+
last_size = dest.size();
145143
}
146-
147-
dest+=sep;
148-
dest+='.';
149-
irep_idt field_name = c.get_pretty_name();
150-
if(field_name.empty())
151-
field_name = c.get_name();
152-
dest += id2string(field_name);
153-
dest+='=';
154-
dest+=tmp;
144+
else
145+
sep = ", ";
155146
}
156147

148+
dest += sep;
149+
dest += '.';
150+
irep_idt field_name = c.get_pretty_name();
151+
if(field_name.empty())
152+
field_name = c.get_name();
153+
dest += id2string(field_name);
154+
dest += '=';
155+
dest += tmp;
156+
157157
o_it++;
158158
}
159159

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
@@ -2078,8 +2078,8 @@ std::string expr2ct::convert_struct(
20782078

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

20842084
if(component.get_is_padding() && !include_padding_components)
20852085
{

src/goto-instrument/dump_c.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -532,9 +532,10 @@ void dump_ct::convert_compound(
532532
{
533533
const typet &comp_type = comp.type();
534534

535-
if(comp_type.id()==ID_code ||
536-
comp.get_bool(ID_from_base) ||
537-
comp.get_is_padding())
535+
DATA_INVARIANT(
536+
comp_type.id() != ID_code, "struct member must not be of code type");
537+
538+
if(comp.get_bool(ID_from_base) || comp.get_is_padding())
538539
continue;
539540

540541
const typet *non_array_type = &comp_type;

src/goto-programs/graphml_witness.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,12 @@ std::string graphml_witnesst::convert_assign_rec(
147147
assign.rhs().operands().begin();
148148
for(const auto &comp : components)
149149
{
150-
if(comp.type().id()==ID_code ||
151-
comp.get_is_padding() ||
152-
// for some reason #is_padding gets lost in *some* cases
153-
has_prefix(id2string(comp.get_name()), "$pad"))
150+
DATA_INVARIANT(
151+
comp.type().id() != ID_code, "struct member must not be of code type");
152+
if(
153+
comp.get_is_padding() ||
154+
// for some reason #is_padding gets lost in *some* cases
155+
has_prefix(id2string(comp.get_name()), "$pad"))
154156
continue;
155157

156158
INVARIANT(

src/goto-programs/interpreter.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -976,10 +976,9 @@ mp_integer interpretert::get_size(const typet &type)
976976

977977
for(const auto &comp : components)
978978
{
979-
const typet &sub_type=comp.type();
980-
981-
if(sub_type.id()!=ID_code)
982-
sum+=get_size(sub_type);
979+
DATA_INVARIANT(
980+
comp.type().id() != ID_code, "struct member must not be of code type");
981+
sum += get_size(comp.type());
983982
}
984983

985984
return sum;
@@ -993,10 +992,9 @@ mp_integer interpretert::get_size(const typet &type)
993992

994993
for(const auto &comp : components)
995994
{
996-
const typet &sub_type=comp.type();
997-
998-
if(sub_type.id()!=ID_code)
999-
max_size=std::max(max_size, get_size(sub_type));
995+
DATA_INVARIANT(
996+
comp.type().id() != ID_code, "union member must not be of code type");
997+
max_size = std::max(max_size, get_size(comp.type()));
1000998
}
1001999

10021000
return max_size;

src/memory-analyzer/analyze_symbol.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,10 @@ exprt gdb_value_extractort::get_struct_value(
703703
{
704704
const struct_typet::componentt &component = struct_type.components()[i];
705705

706-
if(component.get_is_padding() || component.type().id() == ID_code)
706+
DATA_INVARIANT(
707+
component.type().id() != ID_code,
708+
"struct member must not be of code type");
709+
if(component.get_is_padding())
707710
{
708711
continue;
709712
}

src/pointer-analysis/value_set.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,8 +1286,10 @@ void value_sett::assign(
12861286
const typet &subtype = c.type();
12871287
const irep_idt &name = c.get_name();
12881288

1289-
// ignore methods and padding
1290-
if(subtype.id() == ID_code || c.get_is_padding())
1289+
// ignore padding
1290+
DATA_INVARIANT(
1291+
subtype.id() != ID_code, "struct member must not be of code type");
1292+
if(c.get_is_padding())
12911293
continue;
12921294

12931295
member_exprt lhs_member(lhs, name, subtype);
@@ -1792,8 +1794,10 @@ void value_sett::erase_struct_union_symbol(
17921794
const typet &subtype = c.type();
17931795
const irep_idt &name = c.get_name();
17941796

1795-
// ignore methods and padding
1796-
if(subtype.id() == ID_code || c.get_is_padding())
1797+
// ignore padding
1798+
DATA_INVARIANT(
1799+
subtype.id() != ID_code, "struct/union member must not be of code type");
1800+
if(c.get_is_padding())
17971801
continue;
17981802

17991803
erase_symbol_rec(subtype, erase_prefix + "." + id2string(name), ns);

src/pointer-analysis/value_set_fi.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -992,8 +992,11 @@ void value_set_fit::assign(
992992
const typet &subtype=c_it->type();
993993
const irep_idt &name = c_it->get_name();
994994

995-
// ignore methods
996-
if(subtype.id()==ID_code)
995+
// ignore padding
996+
DATA_INVARIANT(
997+
subtype.id() != ID_code,
998+
"struct/union member must not be of code type");
999+
if(c_it->get_is_padding())
9971000
continue;
9981001

9991002
member_exprt lhs_member(lhs, name, subtype);

src/util/expr_initializer.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -188,20 +188,14 @@ optionalt<exprt> expr_initializert<nondet>::expr_initializer_rec(
188188

189189
for(const auto &c : components)
190190
{
191-
if(c.type().id() == ID_code)
192-
{
193-
constant_exprt code_value(ID_nil, c.type());
194-
code_value.add_source_location()=source_location;
195-
value.add_to_operands(std::move(code_value));
196-
}
197-
else
198-
{
199-
const auto member = expr_initializer_rec(c.type(), source_location);
200-
if(!member.has_value())
201-
return {};
191+
DATA_INVARIANT(
192+
c.type().id() != ID_code, "struct member must not be of code type");
202193

203-
value.add_to_operands(std::move(*member));
204-
}
194+
const auto member = expr_initializer_rec(c.type(), source_location);
195+
if(!member.has_value())
196+
return {};
197+
198+
value.add_to_operands(std::move(*member));
205199
}
206200

207201
value.add_source_location()=source_location;

0 commit comments

Comments
 (0)