15#include <unordered_set>
37 const exprt &e = it->second;
39 if(e.
type().
id() != ID_array)
45 static_cast<exprt &
>(s) = e;
52 const exprt &expr)
const
59 const typet &type)
const
68 if(type.
id() == ID_c_enum_tag)
70 else if(type.
id()==ID_struct_tag)
72 else if(type.
id()==ID_union_tag)
80 const typet &type)
const
84 if(followed.
id()==ID_struct || followed.
id()==ID_union)
88 const std::string &tag=followed.
get_string(ID_tag);
102 const typet &subtype = c.type();
107 if(!c.get_base_name().empty())
120 else if(followed.
id()==ID_pointer)
136 exprt &conflict_path)
139 debug() <<
"<BEGIN DEPTH " << depth <<
">" <<
eom;
148 msg=
"type classes differ";
149 else if(t1.
id()==ID_pointer ||
158 if(conflict_path.
type().
id() == ID_pointer)
169 else if(t1.
id()==ID_pointer)
170 msg=
"pointer types differ";
172 msg=
"array types differ";
174 else if(t1.
id()==ID_struct ||
183 exprt conflict_path_before=conflict_path;
185 if(components1.size()!=components2.size())
187 msg=
"number of members is different (";
193 for(std::size_t i=0; i<components1.size(); ++i)
195 const typet &subtype1=components1[i].type();
196 const typet &subtype2=components2[i].type();
198 if(components1[i].get_name()!=components2[i].get_name())
201 msg+=
id2string(components1[i].get_name())+
'/';
202 msg+=
id2string(components2[i].get_name())+
')';
207 typedef std::unordered_set<typet, irep_hash> type_sett;
208 type_sett parent_types;
210 exprt e=conflict_path_before;
211 while(e.
id()==ID_dereference ||
215 parent_types.insert(e.
type());
216 if(e.
id() == ID_dereference)
218 else if(e.
id() == ID_member)
220 else if(e.
id() == ID_index)
226 conflict_path=conflict_path_before;
227 conflict_path.
type()=t1;
232 parent_types.find(t1)==parent_types.end())
242 msg=
"type of member "+
261 if(parent_types.find(t1)==parent_types.end())
267 else if(t1.
id()==ID_c_enum)
279 msg=
"enum value types are different (";
287 else if(members1.size()!=members2.size())
289 msg=
"number of enum members is different (";
295 for(std::size_t i=0; i<members1.size(); ++i)
304 else if(members1[i].get_value()!=members2[i].get_value())
307 msg+=
id2string(members1[i].get_value())+
'/';
308 msg+=
id2string(members2[i].get_value())+
')';
314 msg+=
"\nenum declarations at\n";
318 else if(t1.
id()==ID_code)
329 if(parameters1.size()!=parameters2.size())
331 msg=
"parameter counts differ (";
350 msg=
"return types differ";
354 for(std::size_t i=0; i<parameters1.size(); i++)
356 const typet &subtype1=parameters1[i].type();
357 const typet &subtype2=parameters2[i].type();
374 msg=
"parameter types differ";
382 msg=
"conflict on POD";
387 error() <<
"reason for conflict at "
396 debug() <<
"<END DEPTH " << depth <<
">" <<
eom;
403 const std::string &msg)
409 error() <<
"old definition in module '" << old_symbol.
module <<
"' "
412 error() <<
"new definition in module '" << new_symbol.
module <<
"' "
420 const std::string &msg)
424 warning() <<
"warning: " << msg <<
" \""
427 warning() <<
"old definition in module " << old_symbol.
module <<
" "
430 warning() <<
"new definition in module " << new_symbol.
module <<
" "
455 return new_identifier;
493 "implicit function declaration");
498 "implicit function declaration");
511 "ignoring conflicting implicit function declaration");
516 "implicit function declaration");
543 "function declaration conflicts with with weak definition");
557 "ignoring conflicting weak function declaration");
571 "ignoring conflicting function alias declaration");
582 "ignoring conflicting function declarations");
602 "conflicting parameter counts of function declarations");
611 std::string warn_msg;
613 typedef std::deque<std::pair<typet, typet> > conflictst;
614 conflictst conflicts;
620 code_typet::parameterst::const_iterator
630 std::make_pair(o_it->type(), n_it->type()));
639 "conflicting parameter counts of function declarations");
654 "conflicting parameter counts of function declarations");
663 while(!conflicts.empty())
670 if((t1.
id()==ID_empty || t2.
id()==ID_empty) &&
674 warn_msg=
"void/non-void return type conflict on function";
680 else if((t1.
id()==ID_pointer || t2.
id()==ID_pointer) &&
685 warn_msg=
"different pointer types in extern function";
690 else if((t1.
id()==ID_pointer || t2.
id()==ID_pointer) &&
695 warn_msg=
"pointer parameter types differ between "
696 "declaration and definition";
702 else if((t1.
id()==ID_union &&
703 (t1.
get_bool(ID_C_transparent_union) ||
704 conflicts.front().first.get_bool(ID_C_transparent_union))) ||
705 (t2.
id()==ID_union &&
706 (t2.
get_bool(ID_C_transparent_union) ||
707 conflicts.front().second.get_bool(ID_C_transparent_union))))
711 (t1.
get_bool(ID_C_transparent_union) ||
712 conflicts.front().first.get_bool(ID_C_transparent_union)) &&
717 const typet &src_type=t1.
id()==ID_union?t2:t1;
725 warn_msg=
"conflict on transparent union parameter in function";
739 warn_msg=
"non-pointer parameter types differ between "
740 "declaration and definition";
746 conflicts.pop_front();
749 if(!conflicts.empty())
754 conflicts.front().first,
755 conflicts.front().second);
760 "conflicting function declarations");
801 warning() <<
"function '" << old_symbol.
name <<
"' in module '"
803 <<
"' is shadowed by a definition in module '"
810 "duplicate definition of function");
823 t1.
id() == ID_struct_tag || t1.
id() == ID_union_tag ||
824 t1.
id() == ID_c_enum_tag)
828 if(info.
o_symbols.insert(identifier).second)
840 t2.
id() == ID_struct_tag || t2.
id() == ID_union_tag ||
841 t2.
id() == ID_c_enum_tag)
845 if(info.
n_symbols.insert(identifier).second)
856 else if(t1.
id()==ID_pointer && t2.
id()==ID_array)
862 else if(t1.
id()==ID_array && t2.
id()==ID_pointer)
897 else if(t1.
id()!=t2.
id())
903 if(t1.
id()==ID_pointer)
912 "conflicting pointer types for variable");
919 "conflicting pointer types for variable");
930 t1.
id() == ID_array &&
944 else if(new_size.
is_nil() ||
959 "conflicting array sizes for variable");
968 else if(t1.
id()==ID_struct || t1.
id()==ID_union)
976 struct_union_typet::componentst::const_iterator
977 it1=components1.begin(), it2=components2.begin();
979 it1!=components1.end() && it2!=components2.end();
982 if(it1->get_name()!=it2->get_name() ||
986 if(it1!=components1.end() || it2!=components2.end())
1015 bool set_to_new =
false;
1028 if(old_type.
id()==ID_struct ||
1029 old_type.
id()==ID_union ||
1030 old_type.
id()==ID_array ||
1031 old_type.
id()==ID_c_enum)
1041 "conflicting types for variable");
1068 tmp_new=new_symbol.
value;
1081 warning() <<
"warning: conflicting initializers for"
1082 <<
" variable \"" << old_symbol.
name <<
"\"\n";
1083 warning() <<
"using old value in module " << old_symbol.
module <<
" "
1086 warning() <<
"ignoring new value in module " << new_symbol.
module <<
" "
1106 bool is_code_old_symbol=old_symbol.
type.
id()==ID_code;
1107 bool is_code_new_symbol=new_symbol.
type.
id()==ID_code;
1109 if(is_code_old_symbol!=is_code_new_symbol)
1114 "conflicting definition for symbol");
1120 if(is_code_old_symbol)
1145 "conflicting definition for symbol");
1151 if(old_symbol.
type==new_symbol.
type)
1155 old_symbol.
type.
id() == ID_struct &&
1157 new_symbol.
type.
id() == ID_struct &&
1166 old_symbol.
type.
id() == ID_struct &&
1168 new_symbol.
type.
id() == ID_struct &&
1176 old_symbol.
type.
id() == ID_union &&
1178 new_symbol.
type.
id() == ID_union &&
1187 old_symbol.
type.
id() == ID_union &&
1189 new_symbol.
type.
id() == ID_union &&
1197 old_symbol.
type.
id() == ID_array && new_symbol.
type.
id() == ID_array &&
1228 "unexpected difference between type symbols");
1240 if(old_symbol.
type==new_symbol.
type)
1244 old_symbol.
type.
id() == ID_struct &&
1246 new_symbol.
type.
id() == ID_struct &&
1251 old_symbol.
type.
id() == ID_struct &&
1253 new_symbol.
type.
id() == ID_struct &&
1258 old_symbol.
type.
id() == ID_union &&
1260 new_symbol.
type.
id() == ID_union &&
1265 old_symbol.
type.
id() == ID_union &&
1267 new_symbol.
type.
id() == ID_union &&
1272 old_symbol.
type.
id() == ID_array && new_symbol.
type.
id() == ID_array &&
1291 std::unordered_set<irep_idt> &needs_to_be_renamed)
1300 if(symbol_pair.second.is_type)
1306 for(
const auto &symbol_used : symbols_used)
1308 used_by[symbol_used].insert(symbol_pair.first);
1313 std::deque<irep_idt> queue(
1314 needs_to_be_renamed.begin(), needs_to_be_renamed.end());
1316 while(!queue.empty())
1321 const std::unordered_set<irep_idt> &u = used_by[id];
1323 for(
const auto &dep : u)
1324 if(needs_to_be_renamed.insert(dep).second)
1326 queue.push_back(dep);
1328 debug() <<
"LINKING: needs to be renamed (dependency): "
1336 const std::unordered_set<irep_idt> &needs_to_be_renamed)
1338 std::unordered_map<irep_idt, irep_idt> new_identifiers;
1341 for(
const irep_idt &
id : needs_to_be_renamed)
1350 new_identifier=
rename(
id);
1352 new_identifiers.emplace(
id, new_identifier);
1355 debug() <<
"LINKING: renaming " <<
id <<
" to "
1356 << new_identifier <<
eom;
1365 return new_identifiers;
1369 const std::unordered_map<irep_idt, irep_idt> &new_identifiers)
1371 std::map<irep_idt, symbolt> src_symbols;
1375 symbolt symbol=named_symbol.second;
1379 auto it = new_identifiers.find(named_symbol.first);
1380 if(it != new_identifiers.end())
1381 symbol.
name = it->second;
1383 src_symbols.emplace(named_symbol.first, std::move(symbol));
1387 std::unordered_set<irep_idt> collisions;
1389 for(
const auto &named_symbol : src_symbols)
1392 if(named_symbol.first!=named_symbol.second.name)
1405 collisions.insert(named_symbol.first);
1410 for(
const irep_idt &collision : collisions)
1413 symbolt &new_symbol=src_symbols.at(collision);
1424 if(!named_symbol.second.is_type &&
1425 !named_symbol.second.is_macro &&
1426 named_symbol.second.value.is_not_nil())
1442 std::unordered_set<irep_idt> needs_to_be_renamed;
1446 symbol_tablet::symbolst::const_iterator m_it =
1453 needs_to_be_renamed.insert(symbol_pair.first);
1455 debug() <<
"LINKING: needs to be renamed: " << symbol_pair.first <<
eom;
1476 dest_symbol_table, new_symbol_table, message_handler);
1478 return linking.typecheck_main();
void base_type(typet &type, const namespacet &ns)
bool base_type_eq(const typet &type1, const typet &type2, const namespacet &ns)
Check types for equality across all levels of hierarchy.
const c_enum_typet & to_c_enum_type(const typet &type)
Cast a typet to a c_enum_typet.
const c_enum_tag_typet & to_c_enum_tag_type(const typet &type)
Cast a typet to a c_enum_tag_typet.
const union_typet & to_union_type(const typet &type)
Cast a typet to a union_typet.
const union_tag_typet & to_union_tag_type(const typet &type)
Cast a typet to a union_tag_typet.
const exprt & size() const
const typet & element_type() const
The type of the elements of the array.
const memberst & members() const
std::vector< c_enum_membert > memberst
bool replace_symbol_expr(symbol_exprt &dest) const override
std::vector< parametert > parameterst
const parameterst & parameters() const
const typet & return_type() const
bool has_ellipsis() const
A constant literal expression.
Operator to dereference a pointer.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Base class for all expressions.
const source_locationt & find_source_location() const
Get a source_locationt from the expression or from its operands (non-recursively).
bool is_zero() const
Return whether the expression is a constant representing 0.
typet & type()
Return the type of the expression.
Unbounded, signed integers (mathematical integers, not bitvectors)
bool get_bool(const irep_idt &name) const
const std::string & id_string() const
const irep_idt & id() const
const std::string & get_string(const irep_idt &name) const
void duplicate_non_type_symbol(symbolt &old_symbol, symbolt &new_symbol)
bool adjust_object_type(const symbolt &old_symbol, const symbolt &new_symbol, bool &set_to_new)
bool needs_renaming_type(const symbolt &old_symbol, const symbolt &new_symbol)
rename_symbolt rename_symbol
void copy_symbols(const std::unordered_map< irep_idt, irep_idt > &)
bool adjust_object_type_rec(const typet &type1, const typet &type2, adjust_type_infot &info)
bool needs_renaming_non_type(const symbolt &old_symbol, const symbolt &new_symbol)
std::unordered_map< irep_idt, irep_idt > rename_symbols(const std::unordered_set< irep_idt > &needs_to_be_renamed)
irep_idt rename(const irep_idt &)
symbol_table_baset & main_symbol_table
std::unordered_map< irep_idt, std::unordered_set< irep_idt > > used_byt
std::string expr_to_string(const irep_idt &identifier, const exprt &expr) const
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 do_type_dependencies(std::unordered_set< irep_idt > &)
const symbol_table_baset & src_symbol_table
void link_warning(const symbolt &old_symbol, const symbolt &new_symbol, const std::string &msg)
void duplicate_object_symbol(symbolt &old_symbol, symbolt &new_symbol)
casting_replace_symbolt object_type_updates
std::string type_to_string(const irep_idt &identifier, const typet &type) const
std::unordered_set< irep_idt > renamed_ids
void duplicate_type_symbol(symbolt &old_symbol, const symbolt &new_symbol)
std::string type_to_string_verbose(const symbolt &symbol, const typet &type) const
void detailed_conflict_report(const symbolt &old_symbol, const symbolt &new_symbol, const typet &type1, const typet &type2)
bool needs_renaming(const symbolt &old_symbol, const symbolt &new_symbol)
void duplicate_code_symbol(symbolt &old_symbol, symbolt &new_symbol)
void link_error(const symbolt &old_symbol, const symbolt &new_symbol, const std::string &msg)
Extract member of struct or union.
const exprt & compound() const
source_locationt source_location
mstreamt & warning() const
mstreamt & result() const
const union_typet & follow_tag(const union_tag_typet &) const
Follow type tag of union type.
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
void insert_type(const irep_idt &old_id, const irep_idt &new_id)
void insert_expr(const irep_idt &old_id, const irep_idt &new_id)
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...
std::string as_string() const
const componentst & components() const
bool is_incomplete() const
A struct/union may be incomplete.
std::vector< componentt > componentst
Expression to hold a symbol (variable)
static symbol_exprt typeless(const irep_idt &id)
Generate a symbol_exprt without a proper type.
const irep_idt & get_identifier() const
symbolt & get_writeable_ref(const irep_idt &name)
Find a symbol in the symbol table for read-write access.
const symbolst & symbols
Read-only field, used to look up symbols given their names.
bool has_symbol(const irep_idt &name) const
Check whether a symbol exists in the symbol table.
bool add(const symbolt &symbol)
Add a new symbol to the symbol table.
irep_idt module
Name of module the symbol belongs to.
source_locationt location
Source code location of definition of symbol.
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
typet type
Type of symbol.
irep_idt name
The unique identifier.
const irep_idt & display_name() const
Return language specific display name if present.
exprt value
Initial value of symbol.
const irep_idt & get_identifier() const
Semantic type conversion.
static exprt conditional_cast(const exprt &expr, const typet &type)
The type of an expression, extends irept.
const typet & subtype() const
const source_locationt & source_location() const
void find_type_and_expr_symbols(const exprt &src, find_symbols_sett &dest)
std::unordered_set< irep_idt > find_symbols_sett
std::string get_base_name(const std::string &in, bool strip_suffix)
cleans a filename from path and extension
const std::string & id2string(const irep_idt &d)
std::string from_expr(const namespacet &ns, const irep_idt &identifier, const exprt &expr)
std::string type_to_name(const namespacet &ns, const irep_idt &identifier, const typet &type)
std::string from_type(const namespacet &ns, const irep_idt &identifier, const typet &type)
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...
static const typet & follow_tags_symbols(const namespacet &ns, const typet &type)
bool is_true(const literalt &l)
API to expression classes for Pointers.
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
const dereference_exprt & to_dereference_expr(const exprt &expr)
Cast an exprt to a dereference_exprt.
optionalt< mp_integer > pointer_offset_bits(const typet &type, const namespacet &ns)
bool simplify(exprt &expr, const namespacet &ns)
exprt simplify_expr(exprt src, const namespacet &ns)
#define UNREACHABLE
This should be used to mark dead code.
const index_exprt & to_index_expr(const exprt &expr)
Cast an exprt to an index_exprt.
const member_exprt & to_member_expr(const exprt &expr)
Cast an exprt to a member_exprt.
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
const struct_typet & to_struct_type(const typet &type)
Cast a typet to a struct_typet.
const struct_tag_typet & to_struct_tag_type(const typet &type)
Cast a typet to a struct_tag_typet.
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
const struct_union_typet & to_struct_union_type(const typet &type)
Cast a typet to a struct_union_typet.
const tag_typet & to_tag_type(const typet &type)
Cast a typet to a tag_typet.
void replace(const union_find_replacet &replace_map, string_not_contains_constraintt &constraint)
std::string to_string(const string_not_contains_constraintt &expr)
Used for debug printing.
const symbolt & old_symbol
std::unordered_set< irep_idt > o_symbols
std::unordered_set< irep_idt > n_symbols
const symbolt & new_symbol
static bool failed(bool error_indicator)
const type_with_subtypet & to_type_with_subtype(const typet &type)