@@ -42,24 +42,29 @@ boolbvt::convert_bv(const exprt &expr, optionalt<std::size_t> expected_width)
42
42
// check cache first
43
43
std::pair<bv_cachet::iterator, bool > cache_result=
44
44
bv_cache.insert (std::make_pair (expr, bvt ()));
45
+
46
+ // get a reference to the cache entry
47
+ auto &cache_entry = cache_result.first ->second ;
48
+
45
49
if (!cache_result.second )
46
50
{
47
- return cache_result.first ->second ;
51
+ // Found in cache
52
+ return cache_entry;
48
53
}
49
54
50
- // Iterators into hash_maps supposedly stay stable
51
- // even though we are inserting more elements recursively.
52
-
53
- cache_result. first -> second = convert_bitvector (expr);
55
+ // Iterators into hash_maps do not remain valid when inserting
56
+ // more elements recursively. C++11 §23.2.5/13
57
+ // However, the _reference_ to the entry does!
58
+ cache_entry = convert_bitvector (expr);
54
59
55
60
INVARIANT_WITH_DIAGNOSTICS (
56
- !expected_width || cache_result. first -> second .size () == *expected_width,
61
+ !expected_width || cache_entry .size () == *expected_width,
57
62
" bitvector width shall match the indicated expected width" ,
58
63
expr.find_source_location (),
59
64
irep_pretty_diagnosticst (expr));
60
65
61
66
// check
62
- for (const auto &literal : cache_result. first -> second )
67
+ for (const auto &literal : cache_entry )
63
68
{
64
69
if (freeze_all && !literal.is_constant ())
65
70
prop.set_frozen (literal);
@@ -71,7 +76,7 @@ boolbvt::convert_bv(const exprt &expr, optionalt<std::size_t> expected_width)
71
76
irep_pretty_diagnosticst (expr));
72
77
}
73
78
74
- return cache_result. first -> second ;
79
+ return cache_entry ;
75
80
}
76
81
77
82
// / Print that the expression of x has failed conversion,
0 commit comments