Skip to content

Commit 367a9c7

Browse files
Use format instead of from_expr
1 parent b537bcc commit 367a9c7

File tree

4 files changed

+53
-51
lines changed

4 files changed

+53
-51
lines changed

regression/cbmc-shadow-memory/void-ptr-param-get1/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ main.c
33
--verbosity 10
44
^EXIT=6$
55
^SIGNAL=0$
6-
Shadow memory: cannot get shadow memory via type void\* for s
6+
Shadow memory: cannot get shadow memory via type void\* for f_void_ptr::s
77
--
88
^warning: ignoring

regression/cbmc-shadow-memory/void-ptr-param-set1/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ main.c
33
--verbosity 10
44
^EXIT=6$
55
^SIGNAL=0$
6-
Shadow memory: cannot set shadow memory via type void\* for s
6+
Shadow memory: cannot set shadow memory via type void\* for f_void_ptr::s
77
--
88
^warning: ignoring

src/goto-symex/symex_shadow_memory.cpp

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Author: Peter Schrammel
1818
#include <util/cprover_prefix.h>
1919
#include <util/expr_initializer.h>
2020
#include <util/find_symbols.h>
21+
#include <util/format_expr.h>
2122
#include <util/fresh_symbol.h>
2223
#include <util/invariant.h>
2324
#include <util/message.h>
@@ -94,10 +95,10 @@ void goto_symext::initialize_shadow_memory(
9495

9596
log.conditional_output(
9697
log.debug(),
97-
[field, field_pair, this, address_expr](messaget::mstreamt &mstream) {
98+
[field, field_pair, address_expr](messaget::mstreamt &mstream) {
9899
mstream << "Shadow memory: initialize field " << id2string(field.get_identifier())
99-
<< " for " << from_expr(ns, "", address_expr)
100-
<< " with initial value " << from_expr(ns, "", field_pair.second)
100+
<< " for " << format(address_expr)
101+
<< " with initial value " << format(field_pair.second)
101102
<< messaget::eom;
102103
});
103104
}
@@ -113,7 +114,7 @@ symbol_exprt goto_symext::add_field(
113114
symbolt &new_symbol = get_fresh_aux_symbol(
114115
field_type,
115116
id2string(state.source.function_id),
116-
"SM__" + from_expr(ns, "", expr) + "__" + id2string(field_name),
117+
"SM__" + from_expr(expr) + "__" + id2string(field_name),
117118
state.source.pc->source_location(),
118119
ID_C,
119120
state.symbol_table);
@@ -136,8 +137,8 @@ static bool set_field_check_null(
136137
#ifdef DEBUG_SM
137138
log.conditional_output(
138139
log.debug(), [ns, null_pointer, expr](messaget::mstreamt &mstream) {
139-
mstream << "Shadow memory: value set match: " << from_expr(ns, "", null_pointer)
140-
<< " <-- " << from_expr(ns, "", expr) << messaget::eom;
140+
mstream << "Shadow memory: value set match: " << format(null_pointer)
141+
<< " <-- " << format(expr) << messaget::eom;
141142
mstream << "Shadow memory: ignoring set field on NULL object" << messaget::eom;
142143
});
143144
#endif
@@ -158,7 +159,7 @@ static value_set_dereferencet::valuet get_shadow(
158159
value_set_dereferencet::valuet shadow_dereference =
159160
value_set_dereferencet::build_reference_to(shadowed_object, expr, ns);
160161
#ifdef DEBUG_SM
161-
log.debug() << "Shadow memory: shadow-deref: " << from_expr(ns, "", shadow_dereference.value) << messaget::eom;
162+
log.debug() << "Shadow memory: shadow-deref: " << format(shadow_dereference.value) << messaget::eom;
162163
#endif
163164
return shadow_dereference;
164165
}
@@ -466,23 +467,23 @@ static optionalt<exprt> get_shadow_memory(
466467
{
467468
log.warning()
468469
<< "Shadow memory: value set contains unknown for "
469-
<< from_expr(ns, "", expr)
470+
<< format(expr)
470471
<< messaget::eom;
471472
continue;
472473
}
473474
if(to_object_descriptor_expr(matched_object).root_object().id() == ID_integer_address)
474475
{
475476
log.warning()
476477
<< "Shadow memory: value set contains integer_address for "
477-
<< from_expr(ns, "", expr)
478+
<< format(expr)
478479
<< messaget::eom;
479480
continue;
480481
}
481482
if(matched_object.type().get_bool(ID_C_is_failed_symbol))
482483
{
483484
log.warning()
484485
<< "Shadow memory: value set contains failed symbol for "
485-
<< from_expr(ns, "", expr)
486+
<< format(expr)
486487
<< messaget::eom;
487488
continue;
488489
}
@@ -604,10 +605,10 @@ void goto_symext::symex_shadow_memory_copy(
604605
return;
605606
}
606607
log.conditional_output(
607-
log.debug(), [this, dest_expr, src_expr](messaget::mstreamt &mstream) {
608+
log.debug(), [dest_expr, src_expr](messaget::mstreamt &mstream) {
608609
mstream << "Shadow memory: copy from "
609-
<< from_expr(ns, "", src_expr.object())
610-
<< " to " << from_expr(ns, "", dest_expr.object())
610+
<< format(src_expr.object())
611+
<< " to " << format(dest_expr.object())
611612
<< messaget::eom;
612613
});
613614
for(const auto &entry : state.address_fields)
@@ -625,7 +626,7 @@ void goto_symext::symex_shadow_memory_copy(
625626
{
626627
log.warning()
627628
<< "Shadow memory: cannot copy shadow memory to "
628-
<< from_expr(ns, "", dest_expr)
629+
<< format(dest_expr)
629630
<< messaget::eom;
630631
continue;
631632
}
@@ -641,17 +642,17 @@ void goto_symext::symex_shadow_memory_copy(
641642
{
642643
log.warning()
643644
<< "Shadow memory: cannot copy shadow memory from "
644-
<< from_expr(ns, "", src_expr)
645+
<< format(src_expr)
645646
<< messaget::eom;
646647
continue;
647648
}
648649
if(maybe_lhs->id() == ID_address_of && maybe_rhs->id() == ID_address_of)
649650
{
650651
log.warning()
651652
<< "Shadow memory: copied shadow memory from "
652-
<< from_expr(src_expr)
653+
<< format(src_expr)
653654
<< " to "
654-
<< from_expr(dest_expr)
655+
<< format(dest_expr)
655656
<< messaget::eom;
656657
symex_assign(
657658
state,
@@ -662,9 +663,9 @@ void goto_symext::symex_shadow_memory_copy(
662663
{
663664
log.warning()
664665
<< "Shadow memory: failed to copy shadow memory from "
665-
<< from_expr(ns, "", src_expr)
666+
<< format(src_expr)
666667
<< " to "
667-
<< from_expr(ns, "", dest_expr)
668+
<< format(dest_expr)
668669
<< messaget::eom;
669670
}
670671
}
@@ -736,7 +737,7 @@ static std::vector<exprt::operandst> get_field(
736737
{
737738
std::stringstream s;
738739
s << "Shadow memory: cannot get shadow memory via type void* for "
739-
<< from_expr(ns, "", expr)
740+
<< format(expr)
740741
<< ". Insert a cast to the type that you want to access.";
741742
throw invalid_input_exceptiont(s.str());
742743
}
@@ -857,13 +858,13 @@ void goto_symext::symex_set_field(
857858
log.debug() << "Shadow memory: mux size set_field: " << mux_size << messaget::eom;
858859
const exprt lhs = deref_expr(*maybe_lhs);
859860
#ifdef DEBUG_SM
860-
log.debug() << "Shadow memory: LHS: " << from_expr(ns, "", lhs) << messaget::eom;
861+
log.debug() << "Shadow memory: LHS: " << format(lhs) << messaget::eom;
861862
#endif
862863
if(lhs.type().id() == ID_empty)
863864
{
864865
std::stringstream s;
865866
s << "Shadow memory: cannot set shadow memory via type void* for "
866-
<< from_expr(ns, "", expr)
867+
<< format(expr)
867868
<< ". Insert a cast to the type that you want to access.";
868869
throw invalid_input_exceptiont(s.str());
869870
}
@@ -875,15 +876,15 @@ void goto_symext::symex_set_field(
875876
CHECK_RETURN(per_byte_rhs.has_value());
876877

877878
#ifdef DEBUG_SM
878-
log.debug() << "Shadow memory: RHS: " << from_expr(ns, "", per_byte_rhs) << messaget::eom;
879+
log.debug() << "Shadow memory: RHS: " << format(per_byte_rhs.value()) << messaget::eom;
879880
#endif
880881
symex_assign(state, lhs, typecast_exprt::conditional_cast(per_byte_rhs.value(), lhs.type()));
881882
}
882883
else
883884
{
884885
log.warning()
885886
<< "Shadow memory: cannot set_field for "
886-
<< from_expr(ns, "", expr)
887+
<< format(expr)
887888
<< messaget::eom;
888889
}
889890
}
@@ -932,23 +933,23 @@ void goto_symext::symex_get_field(
932933
{
933934
log.warning()
934935
<< "Shadow memory: value set contains unknown for "
935-
<< from_expr(ns, "", expr)
936+
<< format(expr)
936937
<< messaget::eom;
937938
continue;
938939
}
939940
if(to_object_descriptor_expr(matched_object).root_object().id() == ID_integer_address)
940941
{
941942
log.warning()
942943
<< "Shadow memory: value set contains integer_address for "
943-
<< from_expr(ns, "", expr)
944+
<< format(expr)
944945
<< messaget::eom;
945946
continue;
946947
}
947948
if(matched_object.type().get_bool(ID_C_is_failed_symbol))
948949
{
949950
log.warning()
950951
<< "Shadow memory: value set contains failed symbol for "
951-
<< from_expr(ns, "", expr)
952+
<< format(expr)
952953
<< messaget::eom;
953954
continue;
954955
}
@@ -972,7 +973,7 @@ void goto_symext::symex_get_field(
972973
const size_t mux_size = rhs_conds_values.size() - 1;
973974
log.debug() << "Shadow memory: mux size get_field: " << mux_size << messaget::eom;
974975
#ifdef DEBUG_SM
975-
log.debug() << "Shadow memory: RHS: " << from_expr(ns, "", rhs) << messaget::eom;
976+
log.debug() << "Shadow memory: RHS: " << format(rhs) << messaget::eom;
976977
#endif
977978
symex_assign(
978979
state, lhs, typecast_exprt::conditional_cast(rhs, lhs.type()));
@@ -981,7 +982,7 @@ void goto_symext::symex_get_field(
981982
{
982983
log.warning()
983984
<< "Shadow memory: cannot get_field for "
984-
<< from_expr(ns, "", expr)
985+
<< format(expr)
985986
<< messaget::eom;
986987
symex_assign(
987988
state, lhs, typecast_exprt::conditional_cast(field_init_expr, lhs.type()));

src/goto-symex/symex_shadow_memory_util.cpp

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <util/arith_tools.h>
66
#include <util/bitvector_expr.h>
77
#include <util/c_types.h>
8+
#include <util/format_expr.h>
89
#include <util/pointer_expr.h>
910
#include <util/expr_initializer.h>
1011

@@ -19,8 +20,8 @@ void log_exact_match(
1920
log.debug(),
2021
[ns, shadowed_address, resolved_expr](messaget::mstreamt &mstream) {
2122
mstream << "Shadow memory: exact match: "
22-
<< from_expr(ns, "", shadowed_address.address)
23-
<< " == " << from_expr(ns, "", resolved_expr) << messaget::eom;
23+
<< format(shadowed_address.address)
24+
<< " == " << format(resolved_expr) << messaget::eom;
2425
});
2526
#endif
2627
}
@@ -36,8 +37,8 @@ void log_value_set_match(
3637
log.debug(),
3738
[ns, shadowed_address, expr](messaget::mstreamt &mstream) {
3839
mstream << "Shadow memory: value set match: "
39-
<< from_expr(ns, "", shadowed_address.address)
40-
<< " == " << from_expr(ns, "", expr) << messaget::eom;
40+
<< format(shadowed_address.address)
41+
<< " == " << format(expr) << messaget::eom;
4142
});
4243
#endif
4344
}
@@ -57,14 +58,14 @@ void log_value_set_match(
5758
[ns, shadowed_address, expr, dereference, matched_base_address, shadow_dereference](
5859
messaget::mstreamt &mstream) {
5960
mstream << "Shadow memory: value set match: " << messaget::eom;
60-
mstream << "Shadow memory: base: " << from_expr(ns, "", shadowed_address.address)
61-
<< " <-- " << from_expr(ns, "", matched_base_address) << messaget::eom;
62-
mstream << "Shadow memory: cell: " << from_expr(ns, "", dereference.pointer) << " <-- "
63-
<< from_expr(ns, "", expr) << messaget::eom;
61+
mstream << "Shadow memory: base: " << format(shadowed_address.address)
62+
<< " <-- " << format(matched_base_address) << messaget::eom;
63+
mstream << "Shadow memory: cell: " << format(dereference.pointer) << " <-- "
64+
<< format(expr) << messaget::eom;
6465
mstream << "Shadow memory: shadow ptr: "
65-
<< from_expr(ns, "", shadow_dereference.pointer) << messaget::eom;
66+
<< format(shadow_dereference.pointer) << messaget::eom;
6667
mstream << "Shadow memory: shadow val: "
67-
<< from_expr(ns, "", shadow_dereference.value) << messaget::eom;
68+
<< format(shadow_dereference.value) << messaget::eom;
6869
});
6970
#endif
7071
}
@@ -78,8 +79,8 @@ void log_value_set_match(
7879
#ifdef DEBUG_SM
7980
log.conditional_output(
8081
log.debug(), [ns, address, expr](messaget::mstreamt &mstream) {
81-
mstream << "Shadow memory: value set match: " << from_expr(ns, "", address)
82-
<< " <-- " << from_expr(ns, "", expr) << messaget::eom;
82+
mstream << "Shadow memory: value set match: " << format(address)
83+
<< " <-- " << format(expr) << messaget::eom;
8384
});
8485
#endif
8586
}
@@ -93,7 +94,7 @@ void log_cond(
9394
#ifdef DEBUG_SM
9495
log.conditional_output(
9596
log.debug(), [ns, cond_text, cond](messaget::mstreamt &mstream) {
96-
mstream << "Shadow memory: " << cond_text << ": " << from_expr(ns, "", cond)
97+
mstream << "Shadow memory: " << cond_text << ": " << format(cond)
9798
<< messaget::eom;
9899
});
99100
#endif
@@ -109,7 +110,7 @@ void log_value_set(
109110
log.debug(), [ns, value_set](messaget::mstreamt &mstream) {
110111
for(const auto &e : value_set)
111112
{
112-
mstream << "Shadow memory: value set: " << from_expr(ns, "", e) << messaget::eom;
113+
mstream << "Shadow memory: value set: " << format(e) << messaget::eom;
113114
}
114115
});
115116
#endif
@@ -124,7 +125,7 @@ void log_try_shadow_address(
124125
log.conditional_output(
125126
log.debug(), [ns, shadowed_address](messaget::mstreamt &mstream) {
126127
mstream << "Shadow memory: trying shadowed address: "
127-
<< from_expr(ns, "", shadowed_address.address)
128+
<< format(shadowed_address.address)
128129
<< messaget::eom;
129130
});
130131
#endif
@@ -140,7 +141,7 @@ void log_set_field(
140141
log.conditional_output(
141142
log.debug(), [field_name, ns, expr, value](messaget::mstreamt &mstream) {
142143
mstream << "Shadow memory: set_field: " << id2string(field_name) << " for "
143-
<< from_expr(ns, "", expr) << " to " << from_expr(ns, "", value)
144+
<< format(expr) << " to " << format(value)
144145
<< messaget::eom;
145146
});
146147
}
@@ -154,7 +155,7 @@ void log_get_field(
154155
log.conditional_output(
155156
log.debug(), [ns, field_name, expr](messaget::mstreamt &mstream) {
156157
mstream << "Shadow memory: get_field: " << id2string(field_name) << " for "
157-
<< from_expr(ns, "", expr) << messaget::eom;
158+
<< format(expr) << messaget::eom;
158159
});
159160
}
160161

@@ -427,7 +428,7 @@ exprt compute_max_over_cells(
427428
{
428429
log.warning()
429430
<< "Shadow memory: cannot compute max over variable-size array "
430-
<< from_expr(ns, "", expr)
431+
<< format(expr)
431432
<< messaget::eom;
432433
}
433434
}
@@ -542,7 +543,7 @@ exprt compute_or_over_cells(
542543
{
543544
log.warning()
544545
<< "Shadow memory: cannot compute or over variable-size array "
545-
<< from_expr(ns, "", expr)
546+
<< format(expr)
546547
<< messaget::eom;
547548
}
548549
}
@@ -580,4 +581,4 @@ void replace_invalid_object_by_null(exprt &expr)
580581
{
581582
replace_invalid_object_by_null(*it);
582583
}
583-
}
584+
}

0 commit comments

Comments
 (0)