Skip to content

Commit c9f3334

Browse files
peterschrammeltautschnig
authored andcommitted
Clean up unused template instantiation symbols
1 parent 1db4a04 commit c9f3334

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

regression/cpp/Template_Instantiation4/test.desc

Lines changed: 1 addition & 1 deletion
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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,12 @@ void cpp_typecheckt::clean_up()
278278
const symbolt &symbol=cur_it->second;
279279

280280
// erase templates
281-
if(symbol.type.get_bool(ID_is_template))
281+
if(symbol.type.get_bool(ID_is_template) ||
282+
// Remove all symbols that have not been converted.
283+
// In particular this includes symbols created for functions
284+
// during template instantiation that are never called,
285+
// and hence, their bodies have not been converted.
286+
contains_cpp_name(symbol.value))
282287
{
283288
symbol_table.erase(cur_it);
284289
continue;
@@ -323,3 +328,13 @@ void cpp_typecheckt::clean_up()
323328
}
324329
}
325330
}
331+
332+
bool cpp_typecheckt::contains_cpp_name(const exprt &expr)
333+
{
334+
if(expr.id()==ID_cpp_name)
335+
return true;
336+
forall_operands(it, expr)
337+
if(contains_cpp_name(*it))
338+
return true;
339+
return false;
340+
}

src/cpp/cpp_typecheck.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,8 @@ class cpp_typecheckt:public c_typecheck_baset
587587
exprt &new_expr,
588588
bool check_constantness=true);
589589

590+
bool contains_cpp_name(const exprt &expr);
591+
590592
private:
591593
typedef std::list<irep_idt> dynamic_initializationst;
592594
dynamic_initializationst dynamic_initializations;

0 commit comments

Comments
 (0)