Skip to content

GOTO programs do not have code-typed struct members #6892

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 4 commits into from
Nov 11, 2022
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
46 changes: 23 additions & 23 deletions jbmc/src/java_bytecode/expr2java.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,34 +126,34 @@ std::string expr2javat::convert_struct(

for(const auto &c : components)
{
if(c.type().id() != ID_code)
{
std::string tmp=convert(*o_it);
std::string sep;
DATA_INVARIANT(
c.type().id() != ID_code, "struct member must not be of code type");

if(first)
first=false;
else
std::string tmp = convert(*o_it);
std::string sep;

if(first)
first = false;
else
{
if(last_size + 40 < dest.size())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic constant?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's the same constant (and approach) that expr2ct::convert_struct uses for pretty-printing (and the same is true for arrays). Could be replaced by a named constant, but I'll just create an issue for the readability of this code needs improvement: #6900.

{
if(last_size+40<dest.size())
{
sep=",\n ";
last_size=dest.size();
}
else
sep=", ";
sep = ",\n ";
last_size = dest.size();
}

dest+=sep;
dest+='.';
irep_idt field_name = c.get_pretty_name();
if(field_name.empty())
field_name = c.get_name();
dest += id2string(field_name);
dest+='=';
dest+=tmp;
else
sep = ", ";
}

dest += sep;
dest += '.';
irep_idt field_name = c.get_pretty_name();
if(field_name.empty())
field_name = c.get_name();
dest += id2string(field_name);
dest += '=';
dest += tmp;

o_it++;
}

Expand Down
17 changes: 11 additions & 6 deletions src/ansi-c/c_typecheck_initializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,10 @@ void c_typecheck_baset::designator_enter(

for(const auto &c : struct_type.components())
{
if(c.type().id() != ID_code && !c.get_is_padding())
DATA_INVARIANT(
c.type().id() != ID_code, "struct member must not be of code type");

if(!c.get_is_padding())
{
entry.subtype = c.type();
break;
Expand Down Expand Up @@ -457,9 +460,12 @@ exprt::operandst::const_iterator c_typecheck_baset::do_designated_initializer(

DATA_INVARIANT(index<components.size(),
"member designator is bounded by components size");
DATA_INVARIANT(components[index].type().id()!=ID_code &&
!components[index].get_is_padding(),
"member designator points at data member");
DATA_INVARIANT(
components[index].type().id() != ID_code,
"struct member must not be of code type");
DATA_INVARIANT(
!components[index].get_is_padding(),
"member designator points at non-padding member");

dest=&(dest->operands()[index]);
}
Expand Down Expand Up @@ -737,8 +743,7 @@ void c_typecheck_baset::increment_designator(designatort &designator)
(components[entry.index].get_is_padding() ||
(components[entry.index].get_anonymous() &&
components[entry.index].type().id() != ID_struct_tag &&
components[entry.index].type().id() != ID_union_tag) ||
components[entry.index].type().id() == ID_code))
components[entry.index].type().id() != ID_union_tag)))
{
entry.index++;
}
Expand Down
4 changes: 2 additions & 2 deletions src/ansi-c/expr2c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2074,8 +2074,8 @@ std::string expr2ct::convert_struct(

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

if(component.get_is_padding() && !include_padding_components)
{
Expand Down
7 changes: 4 additions & 3 deletions src/goto-instrument/dump_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,9 +532,10 @@ void dump_ct::convert_compound(
{
const typet &comp_type = comp.type();

if(comp_type.id()==ID_code ||
comp.get_bool(ID_from_base) ||
comp.get_is_padding())
DATA_INVARIANT(
comp_type.id() != ID_code, "struct member must not be of code type");

if(comp.get_bool(ID_from_base) || comp.get_is_padding())
continue;

const typet *non_array_type = &comp_type;
Expand Down
10 changes: 6 additions & 4 deletions src/goto-programs/graphml_witness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,12 @@ std::string graphml_witnesst::convert_assign_rec(
assign.rhs().operands().begin();
for(const auto &comp : components)
{
if(comp.type().id()==ID_code ||
comp.get_is_padding() ||
// for some reason #is_padding gets lost in *some* cases
has_prefix(id2string(comp.get_name()), "$pad"))
DATA_INVARIANT(
comp.type().id() != ID_code, "struct member must not be of code type");
if(
comp.get_is_padding() ||
// for some reason #is_padding gets lost in *some* cases
has_prefix(id2string(comp.get_name()), "$pad"))
continue;

INVARIANT(
Expand Down
14 changes: 6 additions & 8 deletions src/goto-programs/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -976,10 +976,9 @@ mp_integer interpretert::get_size(const typet &type)

for(const auto &comp : components)
{
const typet &sub_type=comp.type();

if(sub_type.id()!=ID_code)
sum+=get_size(sub_type);
DATA_INVARIANT(
comp.type().id() != ID_code, "struct member must not be of code type");
sum += get_size(comp.type());
}

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

for(const auto &comp : components)
{
const typet &sub_type=comp.type();

if(sub_type.id()!=ID_code)
max_size=std::max(max_size, get_size(sub_type));
DATA_INVARIANT(
comp.type().id() != ID_code, "union member must not be of code type");
max_size = std::max(max_size, get_size(comp.type()));
}

return max_size;
Expand Down
5 changes: 4 additions & 1 deletion src/memory-analyzer/analyze_symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,10 @@ exprt gdb_value_extractort::get_struct_value(
{
const struct_typet::componentt &component = struct_type.components()[i];

if(component.get_is_padding() || component.type().id() == ID_code)
DATA_INVARIANT(
component.type().id() != ID_code,
"struct member must not be of code type");
if(component.get_is_padding())
{
continue;
}
Expand Down
12 changes: 8 additions & 4 deletions src/pointer-analysis/value_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1286,8 +1286,10 @@ void value_sett::assign(
const typet &subtype = c.type();
const irep_idt &name = c.get_name();

// ignore methods and padding
if(subtype.id() == ID_code || c.get_is_padding())
// ignore padding
DATA_INVARIANT(
subtype.id() != ID_code, "struct member must not be of code type");
if(c.get_is_padding())
continue;

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

// ignore methods and padding
if(subtype.id() == ID_code || c.get_is_padding())
// ignore padding
DATA_INVARIANT(
subtype.id() != ID_code, "struct/union member must not be of code type");
if(c.get_is_padding())
continue;

erase_symbol_rec(subtype, erase_prefix + "." + id2string(name), ns);
Expand Down
7 changes: 5 additions & 2 deletions src/pointer-analysis/value_set_fi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -992,8 +992,11 @@ void value_set_fit::assign(
const typet &subtype=c_it->type();
const irep_idt &name = c_it->get_name();

// ignore methods
if(subtype.id()==ID_code)
// ignore padding
DATA_INVARIANT(
subtype.id() != ID_code,
"struct/union member must not be of code type");
if(c_it->get_is_padding())
continue;

member_exprt lhs_member(lhs, name, subtype);
Expand Down
20 changes: 7 additions & 13 deletions src/util/expr_initializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,20 +188,14 @@ optionalt<exprt> expr_initializert<nondet>::expr_initializer_rec(

for(const auto &c : components)
{
if(c.type().id() == ID_code)
{
constant_exprt code_value(ID_nil, c.type());
code_value.add_source_location()=source_location;
value.add_to_operands(std::move(code_value));
}
else
{
const auto member = expr_initializer_rec(c.type(), source_location);
if(!member.has_value())
return {};
DATA_INVARIANT(
c.type().id() != ID_code, "struct member must not be of code type");

value.add_to_operands(std::move(*member));
}
const auto member = expr_initializer_rec(c.type(), source_location);
if(!member.has_value())
return {};

value.add_to_operands(std::move(*member));
}

value.add_source_location()=source_location;
Expand Down