@@ -171,7 +171,20 @@ bool java_bytecode_languaget::parse(
171
171
172
172
return false ;
173
173
}
174
-
174
+
175
+ static void gather_needed_globals (const exprt& e, const symbol_tablet& symbol_table, symbol_tablet& needed)
176
+ {
177
+ if (e.id ()==ID_symbol)
178
+ {
179
+ const auto & sym=symbol_table.lookup (to_symbol_expr (e).get_identifier ());
180
+ if (sym.is_static_lifetime )
181
+ needed.add (sym);
182
+ }
183
+ else
184
+ forall_operands (opit,e)
185
+ gather_needed_globals (*opit,symbol_table,needed);
186
+ }
187
+
175
188
/* ******************************************************************\
176
189
177
190
Function: java_bytecode_languaget::typecheck
@@ -184,8 +197,6 @@ Function: java_bytecode_languaget::typecheck
184
197
185
198
\*******************************************************************/
186
199
187
-
188
-
189
200
bool java_bytecode_languaget::typecheck (
190
201
symbol_tablet &symbol_table,
191
202
const std::string &module)
@@ -268,12 +279,16 @@ bool java_bytecode_languaget::typecheck(
268
279
269
280
for (const auto & sym : symbol_table.symbols )
270
281
{
282
+ if (sym.second .is_static_lifetime )
283
+ continue ;
271
284
if (lazy_methods.count (sym.first ) && !already_populated.count (sym.first ))
272
285
continue ;
286
+ if (sym.second .type .id ()==ID_code)
287
+ gather_needed_globals (sym.second .value ,symbol_table,keep_symbols);
273
288
keep_symbols.add (sym.second );
274
289
}
275
290
276
- debug () << " Lazy methods: removed " << symbol_table.symbols .size () - keep_symbols.symbols .size () << " unreachable methods" << eom;
291
+ debug () << " Lazy methods: removed " << symbol_table.symbols .size () - keep_symbols.symbols .size () << " unreachable methods and globals " << eom;
277
292
278
293
symbol_table.swap (keep_symbols);
279
294
0 commit comments