Skip to content

Commit 33f65e1

Browse files
author
Daniel Kroening
committed
Merge branch 'master' of https://www.github.com/diffblue/cbmc
2 parents f4c5709 + 045aeb7 commit 33f65e1

File tree

9 files changed

+181
-18
lines changed

9 files changed

+181
-18
lines changed

src/goto-cc/compile.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ Date: June 2006
2525

2626
#include <ansi-c/ansi_c_language.h>
2727

28-
#include <linking/linking_class.h>
2928
#include <linking/entry_point.h>
3029

3130
#include <goto-programs/goto_convert.h>

src/goto-instrument/full_slicer.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,27 @@ void full_slicer(
473473

474474
/*******************************************************************\
475475
476+
Function: property_slicer
477+
478+
Inputs:
479+
480+
Outputs:
481+
482+
Purpose:
483+
484+
\*******************************************************************/
485+
486+
void property_slicer(
487+
goto_functionst &goto_functions,
488+
const namespacet &ns,
489+
const std::list<std::string> &properties)
490+
{
491+
properties_criteriont p(properties);
492+
full_slicert()(goto_functions, ns, p);
493+
}
494+
495+
/*******************************************************************\
496+
476497
Function: slicing_criteriont::~slicing_criteriont
477498
478499
Inputs:

src/goto-instrument/full_slicer.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ void full_slicer(
1515
goto_functionst &goto_functions,
1616
const namespacet &ns);
1717

18+
void property_slicer(
19+
goto_functionst &goto_functions,
20+
const namespacet &ns,
21+
const std::list<std::string> &properties);
22+
1823
class slicing_criteriont
1924
{
2025
public:

src/goto-instrument/full_slicer_class.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,35 @@ class assert_criteriont:public slicing_criteriont
118118
}
119119
};
120120

121+
class properties_criteriont:public slicing_criteriont
122+
{
123+
public:
124+
explicit properties_criteriont(
125+
const std::list<std::string> &properties):
126+
property_ids(properties)
127+
{
128+
}
129+
130+
virtual bool operator()(goto_programt::const_targett target)
131+
{
132+
if(!target->is_assert())
133+
return false;
134+
135+
const std::string &p_id=
136+
id2string(target->source_location.get_property_id());
137+
138+
for(std::list<std::string>::const_iterator
139+
it=property_ids.begin();
140+
it!=property_ids.end();
141+
++it)
142+
if(p_id==*it)
143+
return true;
144+
145+
return false;
146+
}
147+
148+
protected:
149+
const std::list<std::string> &property_ids;
150+
};
151+
121152
#endif

src/goto-instrument/goto_instrument_parse_options.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1224,6 +1224,9 @@ void goto_instrument_parse_optionst::instrument_goto_program()
12241224
// add loop ids
12251225
goto_functions.compute_loop_numbers();
12261226

1227+
// label the assertions
1228+
label_properties(goto_functions);
1229+
12271230
// nondet volatile?
12281231
if(cmdline.isset("nondet-volatile"))
12291232
{
@@ -1246,7 +1249,10 @@ void goto_instrument_parse_optionst::instrument_goto_program()
12461249
symbol_table, goto_functions, cmdline.isset("pointer-check"));
12471250

12481251
status() << "Performing a full slice" << eom;
1249-
full_slicer(goto_functions, ns);
1252+
if(cmdline.isset("property"))
1253+
property_slicer(goto_functions, ns, cmdline.get_values("property"));
1254+
else
1255+
full_slicer(goto_functions, ns);
12501256
}
12511257

12521258
// label the assertions
@@ -1347,6 +1353,7 @@ void goto_instrument_parse_optionst::help()
13471353
"Slicing:\n"
13481354
" --reachability-slice slice away instructions that can't reach assertions\n"
13491355
" --full-slice slice away instructions that don't affect assertions\n"
1356+
" --property id slice with respect to specific property only\n"
13501357
"\n"
13511358
"Further transformations:\n"
13521359
" --constant-propagator propagate constants and simplify expressions\n"

src/goto-instrument/goto_instrument_parse_options.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Author: Daniel Kroening, [email protected]
4949
"(show-uninitialized)(show-locations)" \
5050
"(full-slice)(reachability-slice)" \
5151
"(inline)" \
52-
"(show-claims)(show-properties)" \
52+
"(show-claims)(show-properties)(property):" \
5353
"(show-symbol-table)(show-points-to)(show-rw-set)" \
5454
"(cav11)" \
5555
"(show-natural-loops)(accelerate)(havoc-loops)" \

src/linking/linking.cpp

Lines changed: 97 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,34 @@ std::string linkingt::type_to_string(
6464

6565
/*******************************************************************\
6666
67+
Function: follow_tags_symbols
68+
69+
Inputs:
70+
71+
Outputs:
72+
73+
Purpose:
74+
75+
\*******************************************************************/
76+
77+
static const typet &follow_tags_symbols(
78+
const namespacet &ns,
79+
const typet &type)
80+
{
81+
if(type.id()==ID_symbol)
82+
return ns.follow(type);
83+
else if(type.id()==ID_c_enum_tag)
84+
return ns.follow_tag(to_c_enum_tag_type(type));
85+
else if(type.id()==ID_struct_tag)
86+
return ns.follow_tag(to_struct_tag_type(type));
87+
else if(type.id()==ID_union_tag)
88+
return ns.follow_tag(to_union_tag_type(type));
89+
else
90+
return type;
91+
}
92+
93+
/*******************************************************************\
94+
6795
Function: linkingt::type_to_string_verbose
6896
6997
Inputs:
@@ -79,7 +107,7 @@ std::string linkingt::type_to_string_verbose(
79107
const symbolt &symbol,
80108
const typet &type) const
81109
{
82-
const typet &followed=ns.follow(type);
110+
const typet &followed=follow_tags_symbols(ns, type);
83111

84112
if(followed.id()==ID_struct || followed.id()==ID_union)
85113
{
@@ -149,13 +177,13 @@ void linkingt::detailed_conflict_report_rec(
149177
{
150178
#ifdef DEBUG
151179
str << "<BEGIN DEPTH " << depth << ">";
152-
debug();
180+
debug_msg();
153181
#endif
154182

155183
std::string msg;
156184

157-
const typet &t1=ns.follow(type1);
158-
const typet &t2=ns.follow(type2);
185+
const typet &t1=follow_tags_symbols(ns, type1);
186+
const typet &t2=follow_tags_symbols(ns, type2);
159187

160188
if(t1.id()!=t2.id())
161189
msg="type classes differ";
@@ -231,6 +259,49 @@ void linkingt::detailed_conflict_report_rec(
231259
}
232260
}
233261
}
262+
else if(t1.id()==ID_c_enum)
263+
{
264+
const c_enum_typet::memberst &members1=
265+
to_c_enum_type(t1).members();
266+
267+
const c_enum_typet::memberst &members2=
268+
to_c_enum_type(t2).members();
269+
270+
if(t1.subtype()!=t2.subtype())
271+
{
272+
msg="enum value types are different (";
273+
msg+=type_to_string(ns, old_symbol.name, t1.subtype())+'/';
274+
msg+=type_to_string(ns, new_symbol.name, t2.subtype())+')';
275+
}
276+
else if(members1.size()!=members2.size())
277+
{
278+
msg="number of enum members is different (";
279+
msg+=i2string(members1.size())+'/';
280+
msg+=i2string(members2.size())+')';
281+
}
282+
else
283+
for(std::size_t i=0; i<members1.size(); ++i)
284+
{
285+
if(members1[i].get_base_name()!=members2[i].get_base_name())
286+
{
287+
msg="names of member "+i2string(i)+" differ (";
288+
msg+=id2string(members1[i].get_base_name())+'/';
289+
msg+=id2string(members2[i].get_base_name())+')';
290+
break;
291+
}
292+
else if(members1[i].get_value()!=members2[i].get_value())
293+
{
294+
msg="values of member "+i2string(i)+" differ (";
295+
msg+=id2string(members1[i].get_value())+'/';
296+
msg+=id2string(members2[i].get_value())+')';
297+
break;
298+
}
299+
}
300+
301+
msg+="\nenum declarations at\n";
302+
msg+=t1.source_location().as_string()+" and\n";
303+
msg+=t1.source_location().as_string();
304+
}
234305
else if(t1.id()==ID_code)
235306
{
236307
const code_typet::parameterst &parameters1=
@@ -309,7 +380,7 @@ void linkingt::detailed_conflict_report_rec(
309380

310381
#ifdef DEBUG
311382
str << "<END DEPTH " << depth << ">";
312-
debug();
383+
debug_msg();
313384
#endif
314385
}
315386

@@ -527,8 +598,8 @@ void linkingt::duplicate_code_symbol(
527598

528599
while(!conflicts.empty())
529600
{
530-
const typet &t1=ns.follow(conflicts.front().first);
531-
const typet &t2=ns.follow(conflicts.front().second);
601+
const typet &t1=follow_tags_symbols(ns, conflicts.front().first);
602+
const typet &t2=follow_tags_symbols(ns, conflicts.front().second);
532603

533604
// void vs. non-void return type may be acceptable if the
534605
// return value is never used
@@ -555,7 +626,8 @@ void linkingt::duplicate_code_symbol(
555626
old_symbol.value.is_nil()!=new_symbol.value.is_nil())
556627
{
557628
if(warn_msg.empty())
558-
warn_msg="different pointer types in function";
629+
warn_msg="pointer parameter types differ between "
630+
"declaration and definition";
559631
replace=new_symbol.value.is_not_nil();
560632
}
561633
// transparent union with (or entirely without) implementation is
@@ -736,10 +808,12 @@ void linkingt::duplicate_object_symbol(
736808
}
737809
else
738810
{
739-
// provide additional diagnostic output for struct/union/array
811+
// provide additional diagnostic output for
812+
// struct/union/array/enum
740813
if(old_type.id()==ID_struct ||
741814
old_type.id()==ID_union ||
742-
old_type.id()==ID_array)
815+
old_type.id()==ID_array ||
816+
old_type.id()==ID_c_enum)
743817
detailed_conflict_report(
744818
old_symbol,
745819
new_symbol,
@@ -1040,8 +1114,8 @@ void linkingt::do_type_dependencies(id_sett &needs_to_be_renamed)
10401114
{
10411115
queue.push(*d_it);
10421116
#ifdef DEBUG
1043-
str << "LINKING: needs to be renamed (dependency): " << s_it->first;
1044-
debug();
1117+
str << "LINKING: needs to be renamed (dependency): " << *d_it;
1118+
debug_msg();
10451119
#endif
10461120
}
10471121
}
@@ -1061,20 +1135,28 @@ Function: linkingt::rename_symbols
10611135

10621136
void linkingt::rename_symbols(const id_sett &needs_to_be_renamed)
10631137
{
1138+
namespacet src_ns(src_symbol_table);
1139+
10641140
for(id_sett::const_iterator
10651141
it=needs_to_be_renamed.begin();
10661142
it!=needs_to_be_renamed.end();
10671143
it++)
10681144
{
10691145
symbolt &new_symbol=src_symbol_table.symbols[*it];
10701146

1071-
irep_idt new_identifier=rename(*it);
1147+
irep_idt new_identifier;
1148+
1149+
if(new_symbol.is_type)
1150+
new_identifier=type_to_name(src_ns, *it, new_symbol.type);
1151+
else
1152+
new_identifier=rename(*it);
1153+
10721154
new_symbol.name=new_identifier;
10731155

10741156
#ifdef DEBUG
10751157
str << "LINKING: renaming " << *it << " to "
10761158
<< new_identifier;
1077-
debug();
1159+
debug_msg();
10781160
#endif
10791161

10801162
if(new_symbol.is_type)
@@ -1182,7 +1264,7 @@ void linkingt::typecheck()
11821264
needs_to_be_renamed.insert(s_it->first);
11831265
#ifdef DEBUG
11841266
str << "LINKING: needs to be renamed: " << s_it->first;
1185-
debug();
1267+
debug_msg();
11861268
#endif
11871269
}
11881270
}

src/util/merge_irep.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,17 @@ const irept& merge_irept::merged(const irept &irep)
200200
dest_named_sub[it->first]=merged(it->second); // recursive call
201201
#endif
202202

203+
const irept::named_subt &src_comments=irep.get_comments();
204+
irept::named_subt &dest_comments=new_irep.get_comments();
205+
206+
forall_named_irep(it, src_comments)
207+
#ifdef SUB_IS_LIST
208+
dest_comments.push_back(
209+
std::make_pair(it->first, merged(it->second))); // recursive call
210+
#else
211+
dest_comments[it->first]=merged(it->second); // recursive call
212+
#endif
213+
203214
return *irep_store.insert(new_irep).first;
204215
}
205216

src/util/message_stream.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ class message_streamt:public message_clientt
8686
sequence_number++;
8787
}
8888

89+
void debug_msg()
90+
{
91+
send_msg(9, str.str());
92+
clear_err();
93+
sequence_number++;
94+
}
95+
8996
std::ostringstream str;
9097

9198
bool get_error_found() const

0 commit comments

Comments
 (0)