@@ -53,6 +53,8 @@ class goto_check_ct
5353 {
5454 enable_bounds_check = _options.get_bool_option (" bounds-check" );
5555 enable_pointer_check = _options.get_bool_option (" pointer-check" );
56+ enable_uninitialized_check =
57+ _options.get_bool_option (" uninitialized-check" );
5658 enable_memory_leak_check = _options.get_bool_option (" memory-leak-check" );
5759 enable_memory_cleanup_check =
5860 _options.get_bool_option (" memory-cleanup-check" );
@@ -189,6 +191,7 @@ class goto_check_ct
189191 void undefined_shift_check (const shift_exprt &, const guardt &);
190192 void pointer_rel_check (const binary_exprt &, const guardt &);
191193 void pointer_overflow_check (const exprt &, const guardt &);
194+ void uninitialized_check (const symbol_exprt &, const guardt &);
192195 void memory_leak_check (const irep_idt &function_id);
193196
194197 // / Generates VCCs for the validity of the given dereferencing operation.
@@ -265,6 +268,7 @@ class goto_check_ct
265268
266269 bool enable_bounds_check;
267270 bool enable_pointer_check;
271+ bool enable_uninitialized_check;
268272 bool enable_memory_leak_check;
269273 bool enable_memory_cleanup_check;
270274 bool enable_div_by_zero_check;
@@ -286,6 +290,7 @@ class goto_check_ct
286290 std::map<irep_idt, bool *> name_to_flag{
287291 {" bounds-check" , &enable_bounds_check},
288292 {" pointer-check" , &enable_pointer_check},
293+ {" uninitialized-check" , &enable_uninitialized_check},
289294 {" memory-leak-check" , &enable_memory_leak_check},
290295 {" memory-cleanup-check" , &enable_memory_cleanup_check},
291296 {" div-by-zero-check" , &enable_div_by_zero_check},
@@ -1339,6 +1344,23 @@ void goto_check_ct::nan_check(const exprt &expr, const guardt &guard)
13391344 guard);
13401345}
13411346
1347+ void goto_check_ct::uninitialized_check (
1348+ const symbol_exprt &expr,
1349+ const guardt &guard)
1350+ {
1351+ if (!enable_uninitialized_check)
1352+ return ;
1353+
1354+ add_guarded_property (
1355+ false_exprt{},
1356+ " reading uninitialized local" ,
1357+ " uninitialized" ,
1358+ true , // not fatal
1359+ expr.find_source_location (),
1360+ expr,
1361+ guard);
1362+ }
1363+
13421364void goto_check_ct::pointer_rel_check (
13431365 const binary_exprt &expr,
13441366 const guardt &guard)
@@ -2059,6 +2081,10 @@ void goto_check_ct::check_rec(
20592081 {
20602082 pointer_validity_check (to_dereference_expr (expr), expr, guard);
20612083 }
2084+ else if (expr.id () == ID_symbol)
2085+ {
2086+ uninitialized_check (to_symbol_expr (expr), guard);
2087+ }
20622088 else if (requires_pointer_primitive_check (expr))
20632089 {
20642090 pointer_primitive_check (expr, guard);
0 commit comments