|
5 | 5 | The MIT License (MIT) |
6 | 6 |
|
7 | 7 | Copyright (c) 2005-2019 Kestrel Technology LLC |
8 | | - Copyright (c) 2020-2023 Henny B. Sipma |
| 8 | + Copyright (c) 2020-2025 Henny B. Sipma |
9 | 9 | Copyright (c) 2026 Aarno Labs LLC |
10 | 10 |
|
11 | 11 | Permission is hereby granted, free of charge, to any person obtaining a copy |
@@ -202,10 +202,10 @@ object |
202 | 202 | end |
203 | 203 |
|
204 | 204 |
|
205 | | -let is_unreachable facts = |
206 | | - List.fold_left (fun acc f -> |
207 | | - match acc with Some _ -> acc | _ -> f#is_unreachable) |
208 | | - None facts |
| 205 | +(* domains that report the location unreachable *) |
| 206 | +let unreachable_domains facts = |
| 207 | + List.sort_uniq Stdlib.compare |
| 208 | + (List.filter_map (fun f -> f#is_unreachable) facts) |
209 | 209 |
|
210 | 210 | let _check_file_assumptions _fenv _file_assumptions _p = false |
211 | 211 |
|
@@ -261,22 +261,42 @@ let check_proof_obligations |
261 | 261 | | CCHFailure s -> po_check_failure (msg s) |
262 | 262 | | Failure s -> po_check_failure (msg (STR s)) in |
263 | 263 |
|
264 | | - match is_unreachable |
| 264 | + match unreachable_domains |
265 | 265 | (invIO#get_location_invariant |
266 | 266 | p#get_context#project_on_cfg)#get_invariants with |
267 | | - | Some domain -> |
| 267 | + | (domain :: _) as domains -> |
268 | 268 | if system_settings#use_unreachability then |
269 | 269 | ignore ((make_unreachable p domain)) |
270 | 270 | else |
| 271 | + (* Unreachability is rare in real code and usually |
| 272 | + points to an error or omission in the analysis; it must not |
| 273 | + silently discharge the proof obligation. The other domains' |
| 274 | + facts at this location are not used either: they are vacuous |
| 275 | + if the location is unreachable (a violation would be a false |
| 276 | + alarm, an api delegation a spurious precondition) and |
| 277 | + suspect otherwise. Only the statement-local check, which does |
| 278 | + not use invariants, is performed; if the proof obligation |
| 279 | + remains open it is marked with an explicit unreachable |
| 280 | + diagnostic that is reported separately. *) |
271 | 281 | begin |
272 | 282 | chlog#add |
273 | 283 | "unreachable" |
274 | 284 | (LBLOCK [ |
275 | 285 | location_to_pretty p#get_location; |
276 | | - STR " (domain: "; |
277 | | - STR domain; |
| 286 | + STR " (domains: "; |
| 287 | + STR (String.concat ", " domains); |
278 | 288 | STR ")"]); |
279 | | - default () |
| 289 | + (try |
| 290 | + check_ppo_validity env#get_functionname env#get_fdecls p |
| 291 | + with |
| 292 | + | CCHFailure s -> po_check_failure (msg s) |
| 293 | + | Failure s -> po_check_failure (msg (STR s))); |
| 294 | + if p#is_closed then |
| 295 | + () |
| 296 | + else |
| 297 | + List.iter (fun d -> |
| 298 | + p#add_diagnostic_key_msg |
| 299 | + "unreachable" ("proven by domain " ^ d)) domains |
280 | 300 | end |
281 | | - | _ -> |
| 301 | + | [] -> |
282 | 302 | default ()) proofObligations |
0 commit comments