Go to the documentation of this file.
16 #include <unordered_set>
34 const exprt &e = it->second;
44 const exprt &expr)
const
51 const typet &type)
const
60 if(type.
id() == ID_symbol_type)
62 else if(type.
id()==ID_c_enum_tag)
64 else if(type.
id()==ID_struct_tag)
66 else if(type.
id()==ID_union_tag)
74 const typet &type)
const
78 if(followed.
id()==ID_struct || followed.
id()==ID_union)
82 const std::string &tag=followed.
get_string(ID_tag);
89 const typet &subtype = c.type();
94 if(!c.get_base_name().empty())
106 else if(followed.
id()==ID_pointer)
110 else if(followed.
id()==ID_incomplete_struct ||
111 followed.
id()==ID_incomplete_union)
125 exprt &conflict_path)
128 debug() <<
"<BEGIN DEPTH " << depth <<
">" <<
eom;
137 msg=
"type classes differ";
138 else if(t1.
id()==ID_pointer ||
154 else if(t1.
id()==ID_pointer)
155 msg=
"pointer types differ";
157 msg=
"array types differ";
159 else if(t1.
id()==ID_struct ||
168 exprt conflict_path_before=conflict_path;
170 if(components1.size()!=components2.size())
172 msg=
"number of members is different (";
178 for(std::size_t i=0; i<components1.size(); ++i)
180 const typet &subtype1=components1[i].type();
181 const typet &subtype2=components2[i].type();
183 if(components1[i].get_name()!=components2[i].get_name())
186 msg+=
id2string(components1[i].get_name())+
'/';
187 msg+=
id2string(components2[i].get_name())+
')';
192 typedef std::unordered_set<typet, irep_hash> type_sett;
193 type_sett parent_types;
195 exprt e=conflict_path_before;
196 while(e.
id()==ID_dereference ||
200 parent_types.insert(e.
type());
204 conflict_path=conflict_path_before;
205 conflict_path.
type()=t1;
210 parent_types.find(t1)==parent_types.end())
220 msg=
"type of member "+
239 if(parent_types.find(t1)==parent_types.end())
245 else if(t1.
id()==ID_c_enum)
255 msg=
"enum value types are different (";
259 else if(members1.size()!=members2.size())
261 msg=
"number of enum members is different (";
267 for(std::size_t i=0; i<members1.size(); ++i)
276 else if(members1[i].get_value()!=members2[i].get_value())
279 msg+=
id2string(members1[i].get_value())+
'/';
280 msg+=
id2string(members2[i].get_value())+
')';
286 msg+=
"\nenum declarations at\n";
290 else if(t1.
id()==ID_code)
301 if(parameters1.size()!=parameters2.size())
303 msg=
"parameter counts differ (";
322 msg=
"return types differ";
326 for(std::size_t i=0; i<parameters1.size(); i++)
328 const typet &subtype1=parameters1[i].type();
329 const typet &subtype2=parameters2[i].type();
346 msg=
"parameter types differ";
354 msg=
"conflict on POD";
360 <<
": " << msg <<
'\n';
368 debug() <<
"<END DEPTH " << depth <<
">" <<
eom;
375 const std::string &msg)
379 error() <<
"error: " << msg <<
" `"
382 error() <<
"old definition in module `" << old_symbol.
module <<
"' "
385 error() <<
"new definition in module `" << new_symbol.
module <<
"' "
393 const std::string &msg)
397 warning() <<
"warning: " << msg <<
" \""
400 warning() <<
"old definition in module " << old_symbol.
module <<
" "
403 warning() <<
"new definition in module " << new_symbol.
module <<
" "
428 return new_identifier;
467 "implicit function declaration");
472 "implicit function declaration");
485 "ignoring conflicting implicit function declaration");
490 "implicit function declaration");
517 "function declaration conflicts with with weak definition");
531 "ignoring conflicting weak function declaration");
545 "ignoring conflicting function alias declaration");
556 "ignoring conflicting function declarations");
576 "conflicting parameter counts of function declarations");
585 std::string warn_msg;
587 typedef std::deque<std::pair<typet, typet> > conflictst;
588 conflictst conflicts;
594 code_typet::parameterst::const_iterator
604 std::make_pair(o_it->type(), n_it->type()));
613 "conflicting parameter counts of function declarations");
628 "conflicting parameter counts of function declarations");
637 while(!conflicts.empty())
644 if((t1.
id()==ID_empty || t2.id()==ID_empty) &&
648 warn_msg=
"void/non-void return type conflict on function";
654 else if((t1.
id()==ID_pointer || t2.id()==ID_pointer) &&
659 warn_msg=
"different pointer types in extern function";
664 else if((t1.
id()==ID_pointer || t2.id()==ID_pointer) &&
669 warn_msg=
"pointer parameter types differ between "
670 "declaration and definition";
676 else if((t1.
id()==ID_union &&
677 (t1.
get_bool(ID_C_transparent_union) ||
678 conflicts.front().first.get_bool(ID_C_transparent_union))) ||
679 (t2.id()==ID_union &&
680 (t2.get_bool(ID_C_transparent_union) ||
681 conflicts.front().second.get_bool(ID_C_transparent_union))))
685 (t1.
get_bool(ID_C_transparent_union) ||
686 conflicts.front().first.get_bool(ID_C_transparent_union)) &&
691 const typet &src_type=t1.
id()==ID_union?t2:t1;
699 warn_msg=
"conflict on transparent union parameter in function";
713 warn_msg=
"non-pointer parameter types differ between "
714 "declaration and definition";
720 conflicts.pop_front();
723 if(!conflicts.empty())
728 conflicts.front().first,
729 conflicts.front().second);
734 "conflicting function declarations");
775 warning() <<
"function `" << old_symbol.
name <<
"' in module `"
776 << new_symbol.
module <<
"' is shadowed by a definition in module `"
783 "duplicate definition of function");
796 t1.
id() == ID_symbol_type || t1.
id() == ID_struct_tag ||
797 t1.
id() == ID_union_tag || t1.
id() == ID_c_enum_tag)
801 if(info.
o_symbols.insert(identifier).second)
813 t2.
id() == ID_symbol_type || t2.
id() == ID_struct_tag ||
814 t2.
id() == ID_union_tag || t2.
id() == ID_c_enum_tag)
818 if(info.
n_symbols.insert(identifier).second)
829 else if(t1.
id()==ID_pointer && t2.
id()==ID_array)
835 else if(t1.
id()==ID_array && t2.
id()==ID_pointer)
840 else if((t1.
id()==ID_incomplete_struct && t2.
id()==ID_struct) ||
841 (t1.
id()==ID_incomplete_union && t2.
id()==ID_union))
847 else if((t1.
id()==ID_struct && t2.
id()==ID_incomplete_struct) ||
848 (t1.
id()==ID_union && t2.
id()==ID_incomplete_union))
853 else if(t1.
id()!=t2.
id())
859 if(t1.
id()==ID_pointer)
868 "conflicting pointer types for variable");
875 "conflicting pointer types for variable");
885 else if(t1.
id()==ID_array &&
898 else if(new_size.
is_nil() ||
913 "conflicting array sizes for variable");
922 else if(t1.
id()==ID_struct || t1.
id()==ID_union)
930 struct_union_typet::componentst::const_iterator
931 it1=components1.begin(), it2=components2.begin();
933 it1!=components1.end() && it2!=components2.end();
936 if(it1->get_name()!=it2->get_name() ||
940 if(it1!=components1.end() || it2!=components2.end())
969 bool set_to_new =
false;
982 if(old_type.
id()==ID_struct ||
983 old_type.
id()==ID_union ||
984 old_type.
id()==ID_array ||
985 old_type.
id()==ID_c_enum)
995 "conflicting types for variable");
1024 tmp_new=new_symbol.
value;
1037 warning() <<
"warning: conflicting initializers for"
1038 <<
" variable \"" << old_symbol.
name <<
"\"\n";
1039 warning() <<
"using old value in module " << old_symbol.
module <<
" "
1042 warning() <<
"ignoring new value in module " << new_symbol.
module <<
" "
1064 bool is_code_old_symbol=old_symbol.
type.
id()==ID_code;
1065 bool is_code_new_symbol=new_symbol.
type.
id()==ID_code;
1067 if(is_code_old_symbol!=is_code_new_symbol)
1072 "conflicting definition for symbol");
1078 if(is_code_old_symbol)
1103 "conflicting definition for symbol");
1109 if(old_symbol.
type==new_symbol.
type)
1112 if(old_symbol.
type.
id()==ID_incomplete_struct &&
1113 new_symbol.
type.
id()==ID_struct)
1120 if(old_symbol.
type.
id()==ID_struct &&
1121 new_symbol.
type.
id()==ID_incomplete_struct)
1127 if(old_symbol.
type.
id()==ID_incomplete_union &&
1128 new_symbol.
type.
id()==ID_union)
1135 if(old_symbol.
type.
id()==ID_union &&
1136 new_symbol.
type.
id()==ID_incomplete_union)
1142 if(old_symbol.
type.
id()==ID_array &&
1143 new_symbol.
type.
id()==ID_array &&
1171 "unexpected difference between type symbols");
1183 if(old_symbol.
type==new_symbol.
type)
1186 if(old_symbol.
type.
id()==ID_incomplete_struct &&
1187 new_symbol.
type.
id()==ID_struct)
1190 if(old_symbol.
type.
id()==ID_struct &&
1191 new_symbol.
type.
id()==ID_incomplete_struct)
1194 if(old_symbol.
type.
id()==ID_incomplete_union &&
1195 new_symbol.
type.
id()==ID_union)
1198 if(old_symbol.
type.
id()==ID_union &&
1199 new_symbol.
type.
id()==ID_incomplete_union)
1202 if(old_symbol.
type.
id()==ID_array &&
1203 new_symbol.
type.
id()==ID_array &&
1219 std::unordered_set<irep_idt> &needs_to_be_renamed)
1228 if(symbol_pair.second.is_type)
1234 for(
const auto &symbol_used : symbols_used)
1236 used_by[symbol_used].insert(symbol_pair.first);
1241 std::deque<irep_idt> queue(
1242 needs_to_be_renamed.begin(), needs_to_be_renamed.end());
1244 while(!queue.empty())
1249 const std::unordered_set<irep_idt> &u = used_by[id];
1251 for(
const auto &dep : u)
1252 if(needs_to_be_renamed.insert(dep).second)
1254 queue.push_back(dep);
1256 debug() <<
"LINKING: needs to be renamed (dependency): "
1264 const std::unordered_set<irep_idt> &needs_to_be_renamed)
1268 for(
const irep_idt &
id : needs_to_be_renamed)
1277 new_identifier=
rename(
id);
1279 new_symbol.
name=new_identifier;
1282 debug() <<
"LINKING: renaming " <<
id <<
" to "
1283 << new_identifier <<
eom;
1295 std::map<irep_idt, symbolt> src_symbols;
1299 symbolt symbol=named_symbol.second;
1304 src_symbols.emplace(named_symbol.first, std::move(symbol));
1308 std::unordered_set<irep_idt> collisions;
1310 for(
const auto &named_symbol : src_symbols)
1313 if(named_symbol.first!=named_symbol.second.name)
1326 collisions.insert(named_symbol.first);
1331 for(
const irep_idt &collision : collisions)
1334 symbolt &new_symbol=src_symbols.at(collision);
1345 if(!named_symbol.second.is_type &&
1346 !named_symbol.second.is_macro &&
1347 named_symbol.second.value.is_not_nil())
1363 std::unordered_set<irep_idt> needs_to_be_renamed;
1367 symbol_tablet::symbolst::const_iterator m_it =
1374 needs_to_be_renamed.insert(symbol_pair.first);
1376 debug() <<
"LINKING: needs to be renamed: " << symbol_pair.first <<
eom;
1397 dest_symbol_table, new_symbol_table, message_handler);
1399 return linking.typecheck_main();
bool needs_renaming_type(const symbolt &old_symbol, const symbolt &new_symbol)
bool adjust_object_type(const symbolt &old_symbol, const symbolt &new_symbol, bool &set_to_new)
const componentst & components() const
symbol_table_baset & src_symbol_table
bool has_symbol(const irep_idt &name) const
Check whether a symbol exists in the symbol table.
const union_tag_typet & to_union_tag_type(const typet &type)
Cast a typet to a union_tag_typet.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
const c_enum_tag_typet & to_c_enum_tag_type(const typet &type)
Cast a typet to a c_enum_tag_typet.
const irep_idt & get_function() const
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
virtual symbolt * get_writeable(const irep_idt &name)=0
Find a symbol in the symbol table for read-write access.
void find_type_and_expr_symbols(const exprt &src, find_symbols_sett &dest)
const symbolt & new_symbol
const struct_union_typet & to_struct_union_type(const typet &type)
Cast a typet to a struct_union_typet.
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.
const c_enum_typet & to_c_enum_type(const typet &type)
Cast a typet to a c_enum_typet.
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
typet type
Type of symbol.
Operator to dereference a pointer.
std::vector< c_enum_membert > memberst
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)
Base class for all expressions.
std::vector< componentt > componentst
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)
exprt simplify_expr(const exprt &src, const namespacet &ns)
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
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 get_bool(const irep_namet &name) const
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
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)
source_locationt source_location
const typet & follow_tag(const union_tag_typet &) const
Follow type tag of union type.
bool base_type_eq(const typet &type1, const typet &type2, const namespacet &ns)
Check types for equality across all levels of hierarchy.
bool linking(symbol_tablet &dest_symbol_table, symbol_tablet &new_symbol_table, message_handlert &message_handler)
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)
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)
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.
irep_idt rename(irep_idt)
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.
const std::string & get_string(const irep_namet &name) const
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)
const typet & follow(const typet &) const
Resolve type symbol to the type it points to.
const irep_idt & get(const irep_namet &name) const
source_locationt location
Source code location of definition of symbol.
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.
std::unordered_set< irep_idt > renamed_ids
const typet & return_type() const
std::unordered_set< irep_idt > n_symbols
const symbolt & old_symbol
const union_typet & to_union_type(const typet &type)
Cast a typet to a union_typet.
void make_typecast(const typet &_type)
Create a typecast_exprt to the given type.
A constant literal expression.
irep_idt module
Name of module the symbol belongs to.
bool is_true(const literalt &l)
mstreamt & warning() const
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)
void rename_symbols(const std::unordered_set< irep_idt > &needs_to_be_renamed)
const memberst & members() const