35 const exprt &const_dest(dest);
45 if(dest.
id() == ID_side_effect)
58 for(
auto &arg : call->arguments())
73 else if(dest.
id() == ID_address_of)
101 const exprt &e = it->second;
103 if(e.
type().
id() != ID_array && e.
type().
id() != ID_code)
109 static_cast<exprt &
>(s) = e;
116 const exprt &expr)
const
123 const typet &type)
const
132 if(type.
id() == ID_c_enum_tag)
134 else if(type.
id()==ID_struct_tag)
136 else if(type.
id()==ID_union_tag)
144 const typet &type)
const
148 if(followed.
id()==ID_struct || followed.
id()==ID_union)
152 const std::string &tag=followed.
get_string(ID_tag);
158 result +=
" (incomplete)";
166 const typet &subtype = c.type();
171 if(!c.get_base_name().empty())
184 else if(followed.
id()==ID_pointer)
200 exprt &conflict_path)
202 bool conclusive =
false;
206 log.debug() <<
"<BEGIN DEPTH " << depth <<
">" <<
messaget::eom;
216 msg=
"type classes differ";
219 else if(t1.
id()==ID_pointer ||
226 if(conflict_path.
type().
id() == ID_pointer)
237 else if(t1.
id()==ID_pointer)
238 msg=
"pointer types differ";
240 msg=
"array types differ";
242 else if(t1.
id()==ID_struct ||
251 exprt conflict_path_before=conflict_path;
253 if(components1.size()!=components2.size())
255 msg=
"number of members is different (";
256 msg+=std::to_string(components1.size())+
'/';
257 msg+=std::to_string(components2.size())+
')';
262 for(std::size_t i=0; i<components1.size(); ++i)
264 const typet &subtype1=components1[i].type();
265 const typet &subtype2=components2[i].type();
267 if(components1[i].get_name()!=components2[i].get_name())
269 msg=
"names of member "+std::to_string(i)+
" differ (";
270 msg+=
id2string(components1[i].get_name())+
'/';
271 msg+=
id2string(components2[i].get_name())+
')';
274 else if(subtype1 != subtype2)
276 typedef std::unordered_set<typet, irep_hash> type_sett;
277 type_sett parent_types;
279 exprt e=conflict_path_before;
280 while(e.
id()==ID_dereference ||
284 parent_types.insert(e.
type());
286 if(e.
id() == ID_dereference)
288 else if(e.
id() == ID_member)
290 else if(e.
id() == ID_index)
296 if(parent_types.find(subtype1) == parent_types.end())
298 conflict_path = conflict_path_before;
299 conflict_path.
type() = t1;
300 conflict_path =
member_exprt(conflict_path, components1[i]);
315 msg =
"type of member " +
id2string(components1[i].get_name()) +
316 " differs (recursive)";
325 else if(t1.
id()==ID_c_enum)
337 msg=
"enum value types are different (";
346 else if(members1.size()!=members2.size())
348 msg=
"number of enum members is different (";
349 msg+=std::to_string(members1.size())+
'/';
350 msg+=std::to_string(members2.size())+
')';
355 for(std::size_t i=0; i<members1.size(); ++i)
359 msg=
"names of member "+std::to_string(i)+
" differ (";
364 else if(members1[i].get_value()!=members2[i].get_value())
366 msg=
"values of member "+std::to_string(i)+
" differ (";
367 msg+=
id2string(members1[i].get_value())+
'/';
368 msg+=
id2string(members2[i].get_value())+
')';
377 msg+=
"\nenum declarations at\n";
381 else if(t1.
id()==ID_code)
392 if(parameters1.size()!=parameters2.size())
394 msg=
"parameter counts differ (";
395 msg+=std::to_string(parameters1.size())+
'/';
396 msg+=std::to_string(parameters2.size())+
')';
399 else if(return_type1 != return_type2)
417 msg=
"return types differ";
421 for(std::size_t i=0; i<parameters1.size(); i++)
423 const typet &subtype1=parameters1[i].type();
424 const typet &subtype2=parameters2[i].type();
426 if(subtype1 != subtype2)
444 msg=
"parameter types differ";
454 msg=
"conflict on POD";
458 if(conclusive && !msg.empty())
464 log.error() <<
"reason for conflict at "
475 log.debug() <<
"<END DEPTH " << depth <<
">" <<
messaget::eom;
484 const std::string &msg)
487 log.error().source_location = new_symbol.
location;
489 log.error() <<
"error: " << msg <<
" '" << old_symbol.
display_name() <<
"'"
491 log.error() <<
"old definition in module '" << old_symbol.
module <<
"' "
494 log.error() <<
"new definition in module '" << new_symbol.
module <<
"' "
502 const std::string &msg)
505 log.warning().source_location = new_symbol.
location;
507 log.warning() <<
"warning: " << msg <<
" \"" << old_symbol.
display_name()
509 log.warning() <<
"old definition in module " << old_symbol.
module <<
" "
512 log.warning() <<
"new definition in module " << new_symbol.
module <<
" "
525 id2string(
id)+
"$link"+std::to_string(++cnt);
534 if(src_symbol_table.
symbols.find(new_identifier)!=
535 src_symbol_table.
symbols.end())
538 return new_identifier;
561 if(old_symbol.
type != new_symbol.
type)
568 link_warning(old_symbol, new_symbol,
"implicit function declaration");
580 "ignoring conflicting implicit function declaration");
604 "function declaration conflicts with with weak definition");
618 "ignoring conflicting weak function declaration");
632 "ignoring conflicting function alias declaration");
641 "ignoring conflicting function declarations");
661 "conflicting parameter counts of function declarations");
670 std::string warn_msg;
672 typedef std::deque<std::pair<typet, typet> > conflictst;
673 conflictst conflicts;
677 link_warning(old_symbol, new_symbol,
"conflicting return types");
682 code_typet::parameterst::const_iterator
690 if(o_it->type() != n_it->type())
692 std::make_pair(o_it->type(), n_it->type()));
701 "conflicting parameter counts of function declarations");
716 "conflicting parameter counts of function declarations");
725 while(!conflicts.empty())
732 (t1.
id() == ID_pointer || t2.
id() == ID_pointer) &&
737 warn_msg=
"different pointer types in extern function";
742 else if((t1.
id()==ID_pointer || t2.
id()==ID_pointer) &&
748 warn_msg=
"pointer parameter types differ between "
749 "declaration and definition";
757 else if((t1.
id()==ID_union &&
758 (t1.
get_bool(ID_C_transparent_union) ||
759 conflicts.front().first.get_bool(ID_C_transparent_union))) ||
760 (t2.
id()==ID_union &&
761 (t2.
get_bool(ID_C_transparent_union) ||
762 conflicts.front().second.get_bool(ID_C_transparent_union))))
766 (t1.
get_bool(ID_C_transparent_union) ||
767 conflicts.front().first.get_bool(ID_C_transparent_union)) &&
772 const typet &src_type=t1.
id()==ID_union?t2:t1;
776 if(c.type() == src_type)
780 warn_msg=
"conflict on transparent union parameter in function";
794 warn_msg=
"non-pointer parameter types differ between "
795 "declaration and definition";
801 conflicts.pop_front();
804 if(!conflicts.empty())
809 conflicts.front().first,
810 conflicts.front().second);
815 "conflicting function declarations");
859 else if(old_symbol.
type == new_symbol.
type)
863 log.debug().source_location = new_symbol.
location;
864 log.debug() <<
"function '" << old_symbol.
name <<
"' in module '"
866 <<
"' is shadowed by a definition in module '"
873 "duplicate definition of function");
886 t1.
id() == ID_struct_tag || t1.
id() == ID_union_tag ||
887 t1.
id() == ID_c_enum_tag)
891 if(info.
o_symbols.insert(identifier).second)
903 t2.
id() == ID_struct_tag || t2.
id() == ID_union_tag ||
904 t2.
id() == ID_c_enum_tag)
908 if(info.
n_symbols.insert(identifier).second)
919 else if(t1.
id()==ID_pointer && t2.
id()==ID_array)
925 else if(t1.
id()==ID_array && t2.
id()==ID_pointer)
960 else if(t1.
id()!=t2.
id())
966 if(t1.
id()==ID_pointer)
975 "conflicting pointer types for variable");
982 "conflicting pointer types for variable");
993 t1.
id() == ID_array &&
1007 else if(new_size.
is_nil() ||
1015 if(new_size.
type() != old_size.
type())
1020 "conflicting array sizes for variable");
1033 "conflicting array sizes for variable");
1042 else if(t1.
id()==ID_struct || t1.
id()==ID_union)
1050 struct_union_typet::componentst::const_iterator
1051 it1=components1.begin(), it2=components2.begin();
1053 it1!=components1.end() && it2!=components2.end();
1056 if(it1->get_name()!=it2->get_name() ||
1060 if(it1!=components1.end() || it2!=components2.end())
1089 bool set_to_new =
false;
1091 if(old_symbol.
type != new_symbol.
type)
1102 if(old_type.
id()==ID_struct ||
1103 old_type.
id()==ID_union ||
1104 old_type.
id()==ID_array ||
1105 old_type.
id()==ID_c_enum)
1115 "conflicting types for variable");
1142 tmp_new=new_symbol.
value;
1147 if(tmp_old == tmp_new)
1154 log.warning().source_location = new_symbol.
location;
1156 log.warning() <<
"warning: conflicting initializers for"
1157 <<
" variable \"" << old_symbol.
name <<
"\"\n";
1158 log.warning() <<
"using old value in module " << old_symbol.
module
1161 log.warning() <<
"ignoring new value in module " << new_symbol.
module
1185 old_symbol.
type != new_symbol.
type))
1187 link_error(old_symbol, new_symbol,
"conflict on code contract");
1192 bool is_code_old_symbol=old_symbol.
type.
id()==ID_code;
1193 bool is_code_new_symbol=new_symbol.
type.
id()==ID_code;
1195 if(is_code_old_symbol!=is_code_new_symbol)
1200 "conflicting definition for symbol");
1206 if(is_code_old_symbol)
1231 "conflicting definition for symbol");
1237 if(old_symbol.
type==new_symbol.
type)
1241 old_symbol.
type.
id() == ID_struct &&
1243 new_symbol.
type.
id() == ID_struct &&
1252 old_symbol.
type.
id() == ID_struct &&
1254 new_symbol.
type.
id() == ID_struct &&
1262 old_symbol.
type.
id() == ID_union &&
1264 new_symbol.
type.
id() == ID_union &&
1273 old_symbol.
type.
id() == ID_union &&
1275 new_symbol.
type.
id() == ID_union &&
1283 old_symbol.
type.
id() == ID_array && new_symbol.
type.
id() == ID_array &&
1312 "unexpected difference between type symbols");
1324 if(old_symbol.
type==new_symbol.
type)
1328 old_symbol.
type.
id() == ID_struct &&
1330 new_symbol.
type.
id() == ID_struct &&
1335 old_symbol.
type.
id() == ID_struct &&
1337 new_symbol.
type.
id() == ID_struct &&
1342 old_symbol.
type.
id() == ID_union &&
1344 new_symbol.
type.
id() == ID_union &&
1349 old_symbol.
type.
id() == ID_union &&
1351 new_symbol.
type.
id() == ID_union &&
1356 old_symbol.
type.
id() == ID_array && new_symbol.
type.
id() == ID_array &&
1374 std::unordered_set<irep_idt> &needs_to_be_renamed,
1381 std::unordered_map<irep_idt, std::unordered_set<irep_idt>> used_by;
1383 for(
const auto &symbol_pair : src_symbol_table.
symbols)
1385 if(symbol_pair.second.is_type)
1391 for(
const auto &symbol_used : symbols_used)
1393 used_by[symbol_used].insert(symbol_pair.first);
1398 std::deque<irep_idt> queue(
1399 needs_to_be_renamed.begin(), needs_to_be_renamed.end());
1401 while(!queue.empty())
1406 const std::unordered_set<irep_idt> &u = used_by[id];
1408 for(
const auto &dep : u)
1409 if(needs_to_be_renamed.insert(dep).second)
1411 queue.push_back(dep);
1414 log.debug() <<
"LINKING: needs to be renamed (dependency): " << dep
1423 const std::unordered_set<irep_idt> &needs_to_be_renamed)
1425 std::unordered_map<irep_idt, irep_idt> new_identifiers;
1428 for(
const irep_idt &
id : needs_to_be_renamed)
1437 new_identifier =
rename(src_symbol_table,
id);
1439 new_identifiers.emplace(
id, new_identifier);
1443 log.debug() <<
"LINKING: renaming " <<
id <<
" to " << new_identifier
1453 return new_identifiers;
1458 const std::unordered_map<irep_idt, irep_idt> &new_identifiers)
1460 std::map<irep_idt, symbolt> src_symbols;
1462 for(
const auto &named_symbol : src_symbol_table.
symbols)
1464 symbolt symbol=named_symbol.second;
1468 auto it = new_identifiers.find(named_symbol.first);
1469 if(it != new_identifiers.end())
1470 symbol.
name = it->second;
1472 src_symbols.emplace(named_symbol.first, std::move(symbol));
1476 std::unordered_set<irep_idt> collisions;
1478 for(
const auto &named_symbol : src_symbols)
1481 if(named_symbol.first!=named_symbol.second.name)
1494 collisions.insert(named_symbol.first);
1499 for(
const irep_idt &collision : collisions)
1502 symbolt &new_symbol=src_symbols.at(collision);
1514 !it->second.is_type && !it->second.is_macro &&
1515 it->second.value.is_not_nil())
1524 const unsigned errors_before =
1533 std::unordered_set<irep_idt> needs_to_be_renamed;
1535 for(
const auto &symbol_pair : src_symbol_table.
symbols)
1537 symbol_table_baset::symbolst::const_iterator m_it =
1544 needs_to_be_renamed.insert(symbol_pair.first);
1547 log.debug() <<
"LINKING: needs to be renamed: " << symbol_pair.first
1557 auto new_identifiers =
rename_symbols(src_symbol_table, needs_to_be_renamed);
1572 return linking.link(new_symbol_table);
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.
Operator to return the address of an object.
const exprt & size() const
const typet & element_type() const
The type of the elements of the array.
std::vector< c_enum_membert > memberst
bool replace_symbol_expr(symbol_exprt &dest) const override
bool replace(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
std::unordered_map< irep_idt, irep_idt > rename_symbols(const symbol_table_baset &, const std::unordered_set< irep_idt > &needs_to_be_renamed)
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 link(const symbol_table_baset &src_symbol_table)
Merges the symbol table src_symbol_table into main_symbol_table, renaming symbols from src_symbol_tab...
bool needs_renaming_type(const symbolt &old_symbol, const symbolt &new_symbol)
rename_symbolt rename_symbol
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)
void copy_symbols(const symbol_table_baset &, const std::unordered_map< irep_idt, irep_idt > &)
irep_idt rename(const symbol_table_baset &, const irep_idt &)
symbol_table_baset & main_symbol_table
std::string expr_to_string(const irep_idt &identifier, const exprt &expr) const
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
bool detailed_conflict_report_rec(const symbolt &old_symbol, const symbolt &new_symbol, const typet &type1, const typet &type2, unsigned depth, exprt &conflict_path)
Returns true iff the conflict report on a particular branch of the tree of types was a definitive res...
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)
message_handlert & message_handler
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
std::size_t get_message_count(unsigned level) const
Class that provides messages with a built-in verbosity 'level'.
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().
The pointer type These are both 'bitvector_typet' (they have a width) and 'type_with_subtypet' (they ...
const typet & base_type() const
The type of the data what we point to.
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)
virtual bool replace(exprt &dest) const
std::size_t erase(const irep_idt &id)
bool have_to_replace(const exprt &dest) const
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)
const irep_idt & get_identifier() const
The symbol table base class interface.
symbolt & get_writeable_ref(const irep_idt &name)
Find a symbol in the symbol table for read-write access.
virtual iteratort begin()=0
const symbolst & symbols
Read-only field, used to look up symbols given their names.
virtual iteratort end()=0
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 source_locationt & source_location() const
auto expr_try_dynamic_cast(TExpr &base) -> typename detail::expr_try_dynamic_cast_return_typet< T, TExpr >::type
Try to cast a reference to a generic exprt to a specific derived class.
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,...
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)
static void do_type_dependencies(const symbol_table_baset &src_symbol_table, std::unordered_set< irep_idt > &needs_to_be_renamed, message_handlert &message_handler)
static const typet & follow_tags_symbols(const namespacet &ns, const typet &type)
bool linking(symbol_table_baset &dest_symbol_table, const symbol_table_baset &new_symbol_table, message_handlert &message_handler)
Merges the symbol table new_symbol_table into dest_symbol_table, renaming symbols from new_symbol_tab...
bool is_true(const literalt &l)
API to expression classes for Pointers.
const address_of_exprt & to_address_of_expr(const exprt &expr)
Cast an exprt to an address_of_exprt.
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.
#define PRECONDITION(CONDITION)
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)
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)