Skip to content

Commit 34bd58f

Browse files
peterschrammeltautschnig
authored andcommitted
Clean up unused template instantiation symbols
1 parent dca5b76 commit 34bd58f

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

regression/cpp/Decltype3/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
CORE
22
main.cpp
33
-std=c++11
44
^EXIT=0$

regression/cpp/Template_Instantiation4/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
CORE
22
main.cpp
33

44
^EXIT=0$

src/cpp/cpp_typecheck.cpp

+16-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,12 @@ void cpp_typecheckt::clean_up()
277277
const symbolt &symbol=cur_it->second;
278278

279279
// erase templates
280-
if(symbol.type.get_bool(ID_is_template))
280+
if(symbol.type.get_bool(ID_is_template) ||
281+
// Remove all symbols that have not been converted.
282+
// In particular this includes symbols created for functions
283+
// during template instantiation that are never called,
284+
// and hence, their bodies have not been converted.
285+
contains_cpp_name(symbol.value))
281286
{
282287
symbol_table.erase(cur_it);
283288
continue;
@@ -327,3 +332,13 @@ bool cpp_typecheckt::builtin_factory(const irep_idt &identifier)
327332
{
328333
return ::builtin_factory(identifier, symbol_table, get_message_handler());
329334
}
335+
336+
bool cpp_typecheckt::contains_cpp_name(const exprt &expr)
337+
{
338+
if(expr.id() == ID_cpp_name || expr.id() == ID_cpp_declaration)
339+
return true;
340+
forall_operands(it, expr)
341+
if(contains_cpp_name(*it))
342+
return true;
343+
return false;
344+
}

src/cpp/cpp_typecheck.h

+2
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,8 @@ class cpp_typecheckt:public c_typecheck_baset
590590
exprt &new_expr,
591591
bool check_constantness=true);
592592

593+
bool contains_cpp_name(const exprt &expr);
594+
593595
private:
594596
typedef std::list<irep_idt> dynamic_initializationst;
595597
dynamic_initializationst dynamic_initializations;

0 commit comments

Comments
 (0)