Skip to content

Commit 25a3c04

Browse files
committed
Remove internal symbols: keep all symbols used in contracts
In beb1353 we had chosen to only keep code-typed symbols, but indeed we also need to retain objects (only) referred to from contracts. Also add debug-level status information of what symbols are being removed (which is information I have previously needed more than once in debugging, and it's also now the only actual use of the messaget that we already had in place). Fixes: #7414
1 parent 8d6f87b commit 25a3c04

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

regression/ansi-c/static5/main.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
typedef struct vtable_s
2+
{
3+
int (*f)(void);
4+
} vtable_t;
5+
6+
int return_0()
7+
{
8+
return 0;
9+
}
10+
11+
static vtable_t vtable_0 = {.f = &return_0};
12+
13+
void foo(vtable_t *vtable)
14+
__CPROVER_requires((void *)0 == vtable || &vtable_0 == vtable)
15+
{
16+
if(vtable->f)
17+
vtable->f();
18+
}
19+
20+
int main()
21+
{
22+
vtable_t *vtable;
23+
foo(vtable);
24+
}

regression/ansi-c/static5/test.desc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--verbosity 10
4+
^Removing unused symbol
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
^Removing unused symbol vtable_0$

src/linking/remove_internal_symbols.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,8 @@ static void get_symbols(
7676

7777
for(const auto &s : new_symbols)
7878
{
79-
// keep functions called in contracts within scope.
80-
// should we keep local variables from the contract as well?
81-
const symbolt *new_symbol = nullptr;
82-
if(!ns.lookup(s, new_symbol))
83-
{
84-
if(new_symbol->type.id() == ID_code)
85-
{
86-
working_set.push_back(new_symbol);
87-
}
88-
}
79+
if(s != CPROVER_PREFIX "return_value")
80+
working_set.push_back(&ns.lookup(s));
8981
}
9082
}
9183
}
@@ -239,6 +231,7 @@ void remove_internal_symbols(
239231
if(exported.find(it->first)==exported.end())
240232
{
241233
symbol_table_baset::symbolst::const_iterator next = std::next(it);
234+
log.debug() << "Removing unused symbol " << it->first << messaget::eom;
242235
symbol_table.erase(it);
243236
it=next;
244237
}

0 commit comments

Comments
 (0)