Skip to content

introduce code_havoc_objectt #4756

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
3 changes: 1 addition & 2 deletions src/goto-programs/builtin_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -793,9 +793,8 @@ void goto_convertt::do_function_call_symbol(
throw 0;
}

codet havoc(ID_havoc_object);
code_havoc_objectt havoc(arguments[0]);
havoc.add_source_location() = function.source_location();
havoc.copy_to_operands(arguments[0]);

dest.add(goto_programt::make_other(havoc, function.source_location()));
}
Expand Down
6 changes: 2 additions & 4 deletions src/goto-symex/symex_other.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,9 @@ void goto_symext::symex_other(
}
else if(statement==ID_havoc_object)
{
DATA_INVARIANT(
code.operands().size() == 1,
"expected havoc_object statement to have one operand");
const auto &havoc_object_statement = to_code_havoc_object(code);

exprt object = clean_expr(code.op0(), state, false);
exprt object = clean_expr(havoc_object_statement.object(), state, false);

process_array_expr(state, object);
havoc_rec(state, guardt(true_exprt(), guard_manager), object);
Expand Down
53 changes: 53 additions & 0 deletions src/util/std_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -2473,6 +2473,59 @@ inline code_try_catcht &to_code_try_catch(codet &code)
return ret;
}

/// \ref codet representation of a 'havoc_object' statement.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we please refrain from recursive documentation? No B. means B., please. If there genuinely is documentation of said statement then refer to it, else here will need to be the place to document it, I'm afraid.

class code_havoc_objectt : public codet
{
public:
explicit code_havoc_objectt(exprt op)
: codet(ID_havoc_object, {std::move(op)})
{
}

const exprt &object() const
{
return op0();
}

exprt &object()
{
return op0();
}

protected:
using codet::op0;
using codet::op1;
using codet::op2;
using codet::op3;
};

template <>
inline bool can_cast_expr<code_havoc_objectt>(const exprt &base)
{
return detail::can_cast_code_impl(base, ID_havoc_object);
}

inline void validate_expr(const code_havoc_objectt &x)
{
validate_operands(x, 1, "havoc_object must have one operand", true);
}

inline const code_havoc_objectt &to_code_havoc_object(const codet &code)
{
PRECONDITION(code.get_statement() == ID_havoc_object);
const code_havoc_objectt &ret = static_cast<const code_havoc_objectt &>(code);
validate_expr(ret);
return ret;
}

inline code_havoc_objectt &to_code_havoc_object(codet &code)
{
PRECONDITION(code.get_statement() == ID_try_catch);
code_havoc_objectt &ret = static_cast<code_havoc_objectt &>(code);
validate_expr(ret);
return ret;
}

/// This class is used to interface between a language frontend
/// and goto-convert -- it communicates the identifiers of the parameters
/// of a function or method
Expand Down