Skip to content

Commit bd45729

Browse files
authored
Merge pull request #6874 from diffblue/more_formatters2
add further formatters
2 parents 68cbf7a + f9456fe commit bd45729

File tree

4 files changed

+97
-3
lines changed

4 files changed

+97
-3
lines changed

regression/cbmc/double_deref/double_deref_with_pointer_arithmetic.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
CORE
22
double_deref_with_pointer_arithmetic.c
33
--show-vcc
4-
^\{-[0-9]+\} derefd_pointer::derefd_pointer!0#1 = \{ symex_dynamic::dynamic_object1#3\[\[0\]\], symex_dynamic::dynamic_object1#3\[\[1\]\] \}\[cast\(mod #source_location=""\(main::argc!0@1#1, 2\), signedbv\[64\]\)\]
4+
^\{-[0-9]+\} derefd_pointer::derefd_pointer!0#1 = \{ symex_dynamic::dynamic_object1#3\[\[0\]\], symex_dynamic::dynamic_object1#3\[\[1\]\] \}\[cast\(mod\(main::argc!0@1#1, 2\), signedbv\[64\]\)\]
55
^\{1\} \(derefd_pointer::derefd_pointer!0#1 = address_of\(symex_dynamic::dynamic_object[23]\) \? main::argc!0@1#1 = 2 : \(derefd_pointer::derefd_pointer!0#1 = address_of\(symex_dynamic::dynamic_object[23]\) \? main::argc!0@1#1 = 1 : symex::invalid_object!0#0 = main::argc!0@1#1\)\)
66
^EXIT=0$
77
^SIGNAL=0$

src/goto-programs/goto_program.cpp

+46-1
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,56 @@ std::ostream &goto_programt::output_instruction(
121121
if(instruction.get_other().id() == ID_code)
122122
{
123123
const auto &code = instruction.get_other();
124-
if(code.get_statement() == ID_havoc_object)
124+
if(code.get_statement() == ID_array_copy)
125+
{
126+
out << "ARRAY_COPY " << format(code.op0()) << ' ' << format(code.op1())
127+
<< '\n';
128+
break;
129+
}
130+
else if(code.get_statement() == ID_array_replace)
131+
{
132+
out << "ARRAY_REPLACE " << format(code.op0()) << ' '
133+
<< format(code.op1()) << '\n';
134+
break;
135+
}
136+
else if(code.get_statement() == ID_array_set)
137+
{
138+
out << "ARRAY_SET " << format(code.op0()) << ' ' << format(code.op1())
139+
<< '\n';
140+
break;
141+
}
142+
else if(code.get_statement() == ID_havoc_object)
125143
{
126144
out << "HAVOC_OBJECT " << format(code.op0()) << '\n';
127145
break;
128146
}
147+
else if(code.get_statement() == ID_fence)
148+
{
149+
out << "FENCE";
150+
if(code.get_bool(ID_WWfence))
151+
out << " WW";
152+
if(code.get_bool(ID_RRfence))
153+
out << " RR";
154+
if(code.get_bool(ID_RWfence))
155+
out << " RW";
156+
if(code.get_bool(ID_WRfence))
157+
out << " WR";
158+
out << '\n';
159+
break;
160+
}
161+
else if(code.get_statement() == ID_input)
162+
{
163+
out << "INPUT";
164+
for(const auto &op : code.operands())
165+
out << ' ' << format(op);
166+
out << '\n';
167+
break;
168+
}
169+
else if(code.get_statement() == ID_output)
170+
{
171+
out << "OUTPUT " << format(code.op0()) << '\n';
172+
break;
173+
}
129174
// fallthrough
130175
}
131176

src/util/format_expr.cpp

+27-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ std::ostream &fallback_format_rec(std::ostream &os, const exprt &expr)
223223
os << expr.id();
224224

225225
for(const auto &s : expr.get_named_sub())
226-
if(s.first != ID_type)
226+
if(s.first != ID_type && s.first != ID_C_source_location)
227227
os << ' ' << s.first << "=\"" << s.second.id() << '"';
228228

229229
if(expr.has_operands())
@@ -571,6 +571,32 @@ void format_expr_configt::setup()
571571
<< format(saturating_plus.rhs()) << ')';
572572
};
573573

574+
expr_map[ID_object_address] =
575+
[](std::ostream &os, const exprt &expr) -> std::ostream & {
576+
const auto &object_address_expr = to_object_address_expr(expr);
577+
return os << u8"\u275d" << object_address_expr.object_identifier()
578+
<< u8"\u275e";
579+
};
580+
581+
expr_map[ID_object_size] =
582+
[](std::ostream &os, const exprt &expr) -> std::ostream & {
583+
const auto &object_size_expr = to_object_size_expr(expr);
584+
return os << "object_size(" << format(object_size_expr.op()) << ')';
585+
};
586+
587+
expr_map[ID_pointer_offset] =
588+
[](std::ostream &os, const exprt &expr) -> std::ostream & {
589+
const auto &pointer_offset_expr = to_pointer_offset_expr(expr);
590+
return os << "pointer_offset(" << format(pointer_offset_expr.op()) << ')';
591+
};
592+
593+
expr_map[ID_field_address] =
594+
[](std::ostream &os, const exprt &expr) -> std::ostream & {
595+
const auto &field_address_expr = to_field_address_expr(expr);
596+
return os << format(field_address_expr.base()) << u8".\u275d"
597+
<< field_address_expr.component_name() << u8"\u275e";
598+
};
599+
574600
fallback = [](std::ostream &os, const exprt &expr) -> std::ostream & {
575601
return fallback_format_rec(os, expr);
576602
};

src/util/pointer_expr.h

+23
Original file line numberDiff line numberDiff line change
@@ -1012,6 +1012,29 @@ class object_size_exprt : public unary_exprt
10121012
}
10131013
};
10141014

1015+
/// \brief Cast an exprt to a \ref object_size_exprt
1016+
///
1017+
/// \a expr must be known to be \ref object_size_exprt.
1018+
///
1019+
/// \param expr: Source expression
1020+
/// \return Object of type \ref object_size_exprt
1021+
inline const object_size_exprt &to_object_size_expr(const exprt &expr)
1022+
{
1023+
PRECONDITION(expr.id() == ID_object_size);
1024+
const object_size_exprt &ret = static_cast<const object_size_exprt &>(expr);
1025+
validate_expr(ret);
1026+
return ret;
1027+
}
1028+
1029+
/// \copydoc to_object_size_expr(const exprt &)
1030+
inline object_size_exprt &to_object_size_expr(exprt &expr)
1031+
{
1032+
PRECONDITION(expr.id() == ID_object_size);
1033+
object_size_exprt &ret = static_cast<object_size_exprt &>(expr);
1034+
validate_expr(ret);
1035+
return ret;
1036+
}
1037+
10151038
template <>
10161039
inline bool can_cast_expr<object_size_exprt>(const exprt &base)
10171040
{

0 commit comments

Comments
 (0)