Skip to content

Commit

Permalink
Merge pull request diffblue#2449 from tautschnig/c++-template-cleanup
Browse files Browse the repository at this point in the history
Clean up unused template instantiation symbols
  • Loading branch information
Daniel Kroening authored Jul 6, 2018
2 parents 1134455 + 34bd58f commit 6409eae
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion regression/cpp/Decltype3/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
KNOWNBUG
CORE
main.cpp
-std=c++11
^EXIT=0$
Expand Down
2 changes: 1 addition & 1 deletion regression/cpp/Template_Instantiation4/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
KNOWNBUG
CORE
main.cpp

^EXIT=0$
Expand Down
17 changes: 16 additions & 1 deletion src/cpp/cpp_typecheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,12 @@ void cpp_typecheckt::clean_up()
const symbolt &symbol=cur_it->second;

// erase templates
if(symbol.type.get_bool(ID_is_template))
if(symbol.type.get_bool(ID_is_template) ||
// Remove all symbols that have not been converted.
// In particular this includes symbols created for functions
// during template instantiation that are never called,
// and hence, their bodies have not been converted.
contains_cpp_name(symbol.value))
{
symbol_table.erase(cur_it);
continue;
Expand Down Expand Up @@ -327,3 +332,13 @@ bool cpp_typecheckt::builtin_factory(const irep_idt &identifier)
{
return ::builtin_factory(identifier, symbol_table, get_message_handler());
}

bool cpp_typecheckt::contains_cpp_name(const exprt &expr)
{
if(expr.id() == ID_cpp_name || expr.id() == ID_cpp_declaration)
return true;
forall_operands(it, expr)
if(contains_cpp_name(*it))
return true;
return false;
}
2 changes: 2 additions & 0 deletions src/cpp/cpp_typecheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,8 @@ class cpp_typecheckt:public c_typecheck_baset
exprt &new_expr,
bool check_constantness=true);

bool contains_cpp_name(const exprt &expr);

private:
typedef std::list<irep_idt> dynamic_initializationst;
dynamic_initializationst dynamic_initializations;
Expand Down

0 comments on commit 6409eae

Please sign in to comment.