Skip to content

Clean up unused template instantiation symbols #2449

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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