Go to the documentation of this file.
15 #include <unordered_set>
36 const exprt &e = it->second;
38 if(e.
type().
id() != ID_array)
44 static_cast<exprt &
>(s) = e;
51 const exprt &expr)
const
58 const typet &type)
const
67 if(type.
id() == ID_c_enum_tag)
69 else if(type.
id()==ID_struct_tag)
71 else if(type.
id()==ID_union_tag)
79 const typet &type)
const
83 if(followed.
id()==ID_struct || followed.
id()==ID_union)
87 const std::string &tag=followed.
get_string(ID_tag);
101 const typet &subtype = c.type();
106 if(!c.get_base_name().empty())
119 else if(followed.
id()==ID_pointer)
135 exprt &conflict_path)
138 debug() <<
"<BEGIN DEPTH " << depth <<
">" <<
eom;
147 msg=
"type classes differ";
148 else if(t1.
id()==ID_pointer ||
155 if(conflict_path.
type().
id() == ID_pointer)
166 else if(t1.
id()==ID_pointer)
167 msg=
"pointer types differ";
169 msg=
"array types differ";
171 else if(t1.
id()==ID_struct ||
180 exprt conflict_path_before=conflict_path;
182 if(components1.size()!=components2.size())
184 msg=
"number of members is different (";
190 for(std::size_t i=0; i<components1.size(); ++i)
192 const typet &subtype1=components1[i].type();
193 const typet &subtype2=components2[i].type();
195 if(components1[i].get_name()!=components2[i].get_name())
198 msg+=
id2string(components1[i].get_name())+
'/';
199 msg+=
id2string(components2[i].get_name())+
')';
202 else if(subtype1 != subtype2)
204 typedef std::unordered_set<typet, irep_hash> type_sett;
205 type_sett parent_types;
207 exprt e=conflict_path_before;
208 while(e.
id()==ID_dereference ||
212 parent_types.insert(e.
type());
213 if(e.
id() == ID_dereference)
215 else if(e.
id() == ID_member)
217 else if(e.
id() == ID_index)
223 conflict_path=conflict_path_before;
224 conflict_path.
type()=t1;
229 parent_types.find(t1)==parent_types.end())
239 msg=
"type of member "+
258 if(parent_types.find(t1)==parent_types.end())
264 else if(t1.
id()==ID_c_enum)
276 msg=
"enum value types are different (";
284 else if(members1.size()!=members2.size())
286 msg=
"number of enum members is different (";
292 for(std::size_t i=0; i<members1.size(); ++i)
301 else if(members1[i].get_value()!=members2[i].get_value())
304 msg+=
id2string(members1[i].get_value())+
'/';
305 msg+=
id2string(members2[i].get_value())+
')';
311 msg+=
"\nenum declarations at\n";
315 else if(t1.
id()==ID_code)
326 if(parameters1.size()!=parameters2.size())
328 msg=
"parameter counts differ (";
332 else if(return_type1 != return_type2)
347 msg=
"return types differ";
351 for(std::size_t i=0; i<parameters1.size(); i++)
353 const typet &subtype1=parameters1[i].type();
354 const typet &subtype2=parameters2[i].type();
356 if(subtype1 != subtype2)
371 msg=
"parameter types differ";
379 msg=
"conflict on POD";
384 error() <<
"reason for conflict at "
393 debug() <<
"<END DEPTH " << depth <<
">" <<
eom;
400 const std::string &msg)
406 error() <<
"old definition in module '" << old_symbol.
module <<
"' "
409 error() <<
"new definition in module '" << new_symbol.
module <<
"' "
417 const std::string &msg)
421 warning() <<
"warning: " << msg <<
" \""
424 warning() <<
"old definition in module " << old_symbol.
module <<
" "
427 warning() <<
"new definition in module " << new_symbol.
module <<
" "
452 return new_identifier;
475 if(old_symbol.
type != new_symbol.
type)
487 link_warning(old_symbol, new_symbol,
"implicit function declaration");
492 "implicit function declaration");
505 "ignoring conflicting implicit function declaration");
510 "implicit function declaration");
536 "function declaration conflicts with with weak definition");
550 "ignoring conflicting weak function declaration");
564 "ignoring conflicting function alias declaration");
575 "ignoring conflicting function declarations");
595 "conflicting parameter counts of function declarations");
604 std::string warn_msg;
606 typedef std::deque<std::pair<typet, typet> > conflictst;
607 conflictst conflicts;
613 code_typet::parameterst::const_iterator
621 if(o_it->type() != n_it->type())
623 std::make_pair(o_it->type(), n_it->type()));
632 "conflicting parameter counts of function declarations");
647 "conflicting parameter counts of function declarations");
656 while(!conflicts.empty())
663 if((t1.
id()==ID_empty || t2.
id()==ID_empty) &&
667 warn_msg=
"void/non-void return type conflict on function";
673 else if((t1.
id()==ID_pointer || t2.
id()==ID_pointer) &&
678 warn_msg=
"different pointer types in extern function";
683 else if((t1.
id()==ID_pointer || t2.
id()==ID_pointer) &&
688 warn_msg=
"pointer parameter types differ between "
689 "declaration and definition";
695 else if((t1.
id()==ID_union &&
696 (t1.
get_bool(ID_C_transparent_union) ||
697 conflicts.front().first.get_bool(ID_C_transparent_union))) ||
698 (t2.
id()==ID_union &&
699 (t2.
get_bool(ID_C_transparent_union) ||
700 conflicts.front().second.get_bool(ID_C_transparent_union))))
704 (t1.
get_bool(ID_C_transparent_union) ||
705 conflicts.front().first.get_bool(ID_C_transparent_union)) &&
710 const typet &src_type=t1.
id()==ID_union?t2:t1;
714 if(c.type() == src_type)
718 warn_msg=
"conflict on transparent union parameter in function";
732 warn_msg=
"non-pointer parameter types differ between "
733 "declaration and definition";
739 conflicts.pop_front();
742 if(!conflicts.empty())
747 conflicts.front().first,
748 conflicts.front().second);
753 "conflicting function declarations");
789 else if(old_symbol.
type == new_symbol.
type)
794 debug() <<
"function '" << old_symbol.
name <<
"' in module '"
796 <<
"' is shadowed by a definition in module '"
803 "duplicate definition of function");
816 t1.
id() == ID_struct_tag || t1.
id() == ID_union_tag ||
817 t1.
id() == ID_c_enum_tag)
821 if(info.
o_symbols.insert(identifier).second)
833 t2.
id() == ID_struct_tag || t2.
id() == ID_union_tag ||
834 t2.
id() == ID_c_enum_tag)
838 if(info.
n_symbols.insert(identifier).second)
849 else if(t1.
id()==ID_pointer && t2.
id()==ID_array)
855 else if(t1.
id()==ID_array && t2.
id()==ID_pointer)
890 else if(t1.
id()!=t2.
id())
896 if(t1.
id()==ID_pointer)
905 "conflicting pointer types for variable");
912 "conflicting pointer types for variable");
923 t1.
id() == ID_array &&
937 else if(new_size.
is_nil() ||
945 if(new_size.
type() != old_size.
type())
950 "conflicting array sizes for variable");
963 "conflicting array sizes for variable");
972 else if(t1.
id()==ID_struct || t1.
id()==ID_union)
980 struct_union_typet::componentst::const_iterator
981 it1=components1.begin(), it2=components2.begin();
983 it1!=components1.end() && it2!=components2.end();
986 if(it1->get_name()!=it2->get_name() ||
990 if(it1!=components1.end() || it2!=components2.end())
1019 bool set_to_new =
false;
1021 if(old_symbol.
type != new_symbol.
type)
1032 if(old_type.
id()==ID_struct ||
1033 old_type.
id()==ID_union ||
1034 old_type.
id()==ID_array ||
1035 old_type.
id()==ID_c_enum)
1045 "conflicting types for variable");
1072 tmp_new=new_symbol.
value;
1077 if(tmp_old == tmp_new)
1085 warning() <<
"warning: conflicting initializers for"
1086 <<
" variable \"" << old_symbol.
name <<
"\"\n";
1087 warning() <<
"using old value in module " << old_symbol.
module <<
" "
1090 warning() <<
"ignoring new value in module " << new_symbol.
module <<
" "
1111 link_error(old_symbol, new_symbol,
"conflict on code contract");
1115 bool is_code_old_symbol=old_symbol.
type.
id()==ID_code;
1116 bool is_code_new_symbol=new_symbol.
type.
id()==ID_code;
1118 if(is_code_old_symbol!=is_code_new_symbol)
1123 "conflicting definition for symbol");
1129 if(is_code_old_symbol)
1154 "conflicting definition for symbol");
1160 if(old_symbol.
type==new_symbol.
type)
1164 old_symbol.
type.
id() == ID_struct &&
1166 new_symbol.
type.
id() == ID_struct &&
1175 old_symbol.
type.
id() == ID_struct &&
1177 new_symbol.
type.
id() == ID_struct &&
1185 old_symbol.
type.
id() == ID_union &&
1187 new_symbol.
type.
id() == ID_union &&
1196 old_symbol.
type.
id() == ID_union &&
1198 new_symbol.
type.
id() == ID_union &&
1206 old_symbol.
type.
id() == ID_array && new_symbol.
type.
id() == ID_array &&
1235 "unexpected difference between type symbols");
1247 if(old_symbol.
type==new_symbol.
type)
1251 old_symbol.
type.
id() == ID_struct &&
1253 new_symbol.
type.
id() == ID_struct &&
1258 old_symbol.
type.
id() == ID_struct &&
1260 new_symbol.
type.
id() == ID_struct &&
1265 old_symbol.
type.
id() == ID_union &&
1267 new_symbol.
type.
id() == ID_union &&
1272 old_symbol.
type.
id() == ID_union &&
1274 new_symbol.
type.
id() == ID_union &&
1279 old_symbol.
type.
id() == ID_array && new_symbol.
type.
id() == ID_array &&
1296 std::unordered_set<irep_idt> &needs_to_be_renamed)
1305 if(symbol_pair.second.is_type)
1311 for(
const auto &symbol_used : symbols_used)
1313 used_by[symbol_used].insert(symbol_pair.first);
1318 std::deque<irep_idt> queue(
1319 needs_to_be_renamed.begin(), needs_to_be_renamed.end());
1321 while(!queue.empty())
1326 const std::unordered_set<irep_idt> &u = used_by[id];
1328 for(
const auto &dep : u)
1329 if(needs_to_be_renamed.insert(dep).second)
1331 queue.push_back(dep);
1333 debug() <<
"LINKING: needs to be renamed (dependency): "
1341 const std::unordered_set<irep_idt> &needs_to_be_renamed)
1343 std::unordered_map<irep_idt, irep_idt> new_identifiers;
1346 for(
const irep_idt &
id : needs_to_be_renamed)
1355 new_identifier=
rename(
id);
1357 new_identifiers.emplace(
id, new_identifier);
1360 debug() <<
"LINKING: renaming " <<
id <<
" to "
1361 << new_identifier <<
eom;
1370 return new_identifiers;
1374 const std::unordered_map<irep_idt, irep_idt> &new_identifiers)
1376 std::map<irep_idt, symbolt> src_symbols;
1380 symbolt symbol=named_symbol.second;
1384 auto it = new_identifiers.find(named_symbol.first);
1385 if(it != new_identifiers.end())
1386 symbol.
name = it->second;
1388 src_symbols.emplace(named_symbol.first, std::move(symbol));
1392 std::unordered_set<irep_idt> collisions;
1394 for(
const auto &named_symbol : src_symbols)
1397 if(named_symbol.first!=named_symbol.second.name)
1410 collisions.insert(named_symbol.first);
1415 for(
const irep_idt &collision : collisions)
1418 symbolt &new_symbol=src_symbols.at(collision);
1429 if(!named_symbol.second.is_type &&
1430 !named_symbol.second.is_macro &&
1431 named_symbol.second.value.is_not_nil())
1447 std::unordered_set<irep_idt> needs_to_be_renamed;
1451 symbol_tablet::symbolst::const_iterator m_it =
1458 needs_to_be_renamed.insert(symbol_pair.first);
1460 debug() <<
"LINKING: needs to be renamed: " << symbol_pair.first <<
eom;
1481 dest_symbol_table, new_symbol_table, message_handler);
1483 return linking.typecheck_main();
bool needs_renaming_type(const symbolt &old_symbol, const symbolt &new_symbol)
const union_tag_typet & to_union_tag_type(const typet &type)
Cast a typet to a union_tag_typet.
bool adjust_object_type(const symbolt &old_symbol, const symbolt &new_symbol, bool &set_to_new)
const irep_idt & get_identifier() const
#define UNREACHABLE
This should be used to mark dead code.
const componentst & components() const
bool has_symbol(const irep_idt &name) const
Check whether a symbol exists in the symbol table.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
const union_typet & to_union_type(const typet &type)
Cast a typet to a union_typet.
bool has_ellipsis() const
std::string get_base_name(const std::string &in, bool strip_suffix)
cleans a filename from path and extension
static exprt conditional_cast(const exprt &expr, const typet &type)
bool needs_renaming(const symbolt &old_symbol, const symbolt &new_symbol)
const typet & subtype() const
std::string as_string() const
bool linking(symbol_tablet &dest_symbol_table, const symbol_tablet &new_symbol_table, message_handlert &message_handler)
Merges the symbol table new_symbol_table into dest_symbol_table, renaming symbols from new_symbol_tab...
void find_type_and_expr_symbols(const exprt &src, find_symbols_sett &dest)
Find identifiers of the sub expressions with id ID_symbol, considering both free and bound variables,...
const struct_typet & to_struct_type(const typet &type)
Cast a typet to a struct_typet.
const symbolt & new_symbol
const struct_union_typet & to_struct_union_type(const typet &type)
Cast a typet to a struct_union_typet.
const dereference_exprt & to_dereference_expr(const exprt &expr)
Cast an exprt to a dereference_exprt.
std::string type_to_name(const namespacet &ns, const irep_idt &identifier, const typet &type)
const irep_idt & display_name() const
Return language specific display name if present.
casting_replace_symbolt object_type_updates
The type of an expression, extends irept.
std::vector< parametert > parameterst
std::string type_to_string_verbose(const symbolt &symbol, const typet &type) const
const index_exprt & to_index_expr(const exprt &expr)
Cast an exprt to an index_exprt.
typet type
Type of symbol.
Operator to dereference a pointer.
std::vector< c_enum_membert > memberst
static symbol_exprt typeless(const irep_idt &id)
Generate a symbol_exprt without a proper type.
const c_enum_typet & to_c_enum_type(const typet &type)
Cast a typet to a c_enum_typet.
std::string type_to_string(const irep_idt &identifier, const typet &type) const
void replace(const union_find_replacet &replace_map, string_not_contains_constraintt &constraint)
Unbounded, signed integers (mathematical integers, not bitvectors)
bool needs_renaming_non_type(const symbolt &old_symbol, const symbolt &new_symbol)
const type_with_subtypet & to_type_with_subtype(const typet &type)
Base class for all expressions.
std::vector< componentt > componentst
std::unordered_map< irep_idt, irep_idt > rename_symbols(const std::unordered_set< irep_idt > &needs_to_be_renamed)
const union_typet & follow_tag(const union_tag_typet &) const
Follow type tag of union type.
std::string from_type(const namespacet &ns, const irep_idt &identifier, const typet &type)
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.
Expression to hold a symbol (variable)
void link_warning(const symbolt &old_symbol, const symbolt &new_symbol, const std::string &msg)
void duplicate_code_symbol(symbolt &old_symbol, symbolt &new_symbol)
symbol_table_baset & main_symbol_table
void copy_symbols(const std::unordered_map< irep_idt, irep_idt > &)
const exprt & size() const
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
typet & type()
Return the type of the expression.
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
bool adjust_object_type_rec(const typet &type1, const typet &type2, adjust_type_infot &info)
std::unordered_map< irep_idt, std::unordered_set< irep_idt > > used_byt
mstreamt & result() const
const tag_typet & to_tag_type(const typet &type)
Cast a typet to a tag_typet.
static const typet & follow_tags_symbols(const namespacet &ns, const typet &type)
void do_type_dependencies(std::unordered_set< irep_idt > &)
symbolt & get_writeable_ref(const irep_idt &name)
Find a symbol in the symbol table for read-write access.
const std::string & id2string(const irep_idt &d)
const exprt & compound() const
static bool failed(bool error_indicator)
source_locationt source_location
const c_enum_tag_typet & to_c_enum_tag_type(const typet &type)
Cast a typet to a c_enum_tag_typet.
const source_locationt & source_location() const
const source_locationt & find_source_location() const
Get a source_locationt from the expression or from its operands (non-recursively).
const irep_idt & get_identifier() const
optionalt< mp_integer > pointer_offset_bits(const typet &type, const namespacet &ns)
const symbol_table_baset & src_symbol_table
bool replace_symbol_expr(symbol_exprt &dest) const override
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
const std::string & id_string() const
bool simplify(exprt &expr, const namespacet &ns)
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
exprt simplify_expr(exprt src, const namespacet &ns)
const std::string & get_string(const irep_idt &name) const
void duplicate_non_type_symbol(symbolt &old_symbol, symbolt &new_symbol)
const irep_idt & id() const
const struct_tag_typet & to_struct_tag_type(const typet &type)
Cast a typet to a struct_tag_typet.
void detailed_conflict_report_rec(const symbolt &old_symbol, const symbolt &new_symbol, const typet &type1, const typet &type2, unsigned depth, exprt &conflict_path)
void insert(const class symbol_exprt &old_expr, const exprt &new_expr)
Sets old_expr to be replaced by new_expr if we don't already have a replacement; otherwise does nothi...
void duplicate_object_symbol(symbolt &old_symbol, symbolt &new_symbol)
const parameterst & parameters() const
std::string expr_to_string(const irep_idt &identifier, const exprt &expr) const
rename_symbolt rename_symbol
void link_error(const symbolt &old_symbol, const symbolt &new_symbol, const std::string &msg)
bool is_zero() const
Return whether the expression is a constant representing 0.
bool add(const symbolt &symbol)
Add a new symbol to the symbol table.
Extract member of struct or union.
exprt value
Initial value of symbol.
std::unordered_set< irep_idt > find_symbols_sett
void duplicate_type_symbol(symbolt &old_symbol, const symbolt &new_symbol)
source_locationt location
Source code location of definition of symbol.
const symbolst & symbols
Read-only field, used to look up symbols given their names.
void insert_expr(const irep_idt &old_id, const irep_idt &new_id)
void detailed_conflict_report(const symbolt &old_symbol, const symbolt &new_symbol, const typet &type1, const typet &type2)
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
irep_idt rename(const irep_idt &)
std::unordered_set< irep_idt > renamed_ids
const typet & return_type() const
const member_exprt & to_member_expr(const exprt &expr)
Cast an exprt to a member_exprt.
std::unordered_set< irep_idt > n_symbols
const symbolt & old_symbol
Semantic type conversion.
A constant literal expression.
irep_idt module
Name of module the symbol belongs to.
bool is_true(const literalt &l)
mstreamt & warning() const
bool is_incomplete() const
A struct/union may be incomplete.
std::unordered_set< irep_idt > o_symbols
std::string from_expr(const namespacet &ns, const irep_idt &identifier, const exprt &expr)
irep_idt name
The unique identifier.
void insert_type(const irep_idt &old_id, const irep_idt &new_id)
bool get_bool(const irep_idt &name) const
const memberst & members() const
const typet & element_type() const
The type of the elements of the array.