Skip to content

Commit 6d2e501

Browse files
authored
Merge pull request #7417 from tautschnig/bugfixes/7414-contract-static
Remove internal symbols: keep all symbols used in contracts
2 parents a89fc23 + c4fdaf8 commit 6d2e501

File tree

3 files changed

+38
-10
lines changed

3 files changed

+38
-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: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,11 @@ 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+
const symbolt *symbol_ptr;
80+
// identifiers for parameters of prototypes need not exist, and neither
81+
// does __CPROVER_return_value
82+
if(!ns.lookup(s, symbol_ptr))
83+
working_set.push_back(symbol_ptr);
8984
}
9085
}
9186
}
@@ -239,6 +234,7 @@ void remove_internal_symbols(
239234
if(exported.find(it->first)==exported.end())
240235
{
241236
symbol_table_baset::symbolst::const_iterator next = std::next(it);
237+
log.debug() << "Removing unused symbol " << it->first << messaget::eom;
242238
symbol_table.erase(it);
243239
it=next;
244240
}

0 commit comments

Comments
 (0)