Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion CodeHawk/CHC/cchanalyze/cCHExpTranslator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,20 @@ object (self)
~ok:(fun ftype ->
match x with
| Const c -> self#translate_const_expr c
| CastE (_, xx) -> self#translate_expr xx
| CastE (_, xx) ->
(* An integer conversion that may change the value (C11
6.3.1.3p2-3; issue 21) is applied to a constant operand and
makes any other operand unknown. Previously every cast was
the identity: (uint8_t)x > 100 with x == 300 folded to TRUE
and made the else branch unreachable (issue 25). *)
let inner = self#translate_expr xx in
(match CCHIntegerSemantics.get_correction env context x with
| None -> inner
| Some c ->
match inner with
| XConst (IntConst n) ->
num_constant_expr (CCHIntegerSemantics.fold_constant c n)
| _ -> random_constant_expr)
| Lval lval -> self#translate_variable_expr lval ftype
| AddrOf lval
| StartOf lval -> self#translate_address lval ftype
Expand Down
42 changes: 31 additions & 11 deletions CodeHawk/CHC/cchanalyze/cCHPOChecker.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
The MIT License (MIT)

Copyright (c) 2005-2019 Kestrel Technology LLC
Copyright (c) 2020-2023 Henny B. Sipma
Copyright (c) 2020-2025 Henny B. Sipma
Copyright (c) 2026 Aarno Labs LLC

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down Expand Up @@ -202,10 +202,10 @@ object
end


let is_unreachable facts =
List.fold_left (fun acc f ->
match acc with Some _ -> acc | _ -> f#is_unreachable)
None facts
(* domains that report the location unreachable *)
let unreachable_domains facts =
List.sort_uniq Stdlib.compare
(List.filter_map (fun f -> f#is_unreachable) facts)

let _check_file_assumptions _fenv _file_assumptions _p = false

Expand Down Expand Up @@ -261,22 +261,42 @@ let check_proof_obligations
| CCHFailure s -> po_check_failure (msg s)
| Failure s -> po_check_failure (msg (STR s)) in

match is_unreachable
match unreachable_domains
(invIO#get_location_invariant
p#get_context#project_on_cfg)#get_invariants with
| Some domain ->
| (domain :: _) as domains ->
if system_settings#use_unreachability then
ignore ((make_unreachable p domain))
else
(* Unreachability is rare in real code and usually
points to an error or omission in the analysis; it must not
silently discharge the proof obligation. The other domains'
facts at this location are not used either: they are vacuous
if the location is unreachable (a violation would be a false
alarm, an api delegation a spurious precondition) and
suspect otherwise. Only the statement-local check, which does
not use invariants, is performed; if the proof obligation
remains open it is marked with an explicit unreachable
diagnostic that is reported separately. *)
begin
chlog#add
"unreachable"
(LBLOCK [
location_to_pretty p#get_location;
STR " (domain: ";
STR domain;
STR " (domains: ";
STR (String.concat ", " domains);
STR ")"]);
default ()
(try
check_ppo_validity env#get_functionname env#get_fdecls p
with
| CCHFailure s -> po_check_failure (msg s)
| Failure s -> po_check_failure (msg (STR s)));
if p#is_closed then
()
else
List.iter (fun d ->
p#add_diagnostic_key_msg
"unreachable" ("proven by domain " ^ d)) domains
end
| _ ->
| [] ->
default ()) proofObligations
5 changes: 4 additions & 1 deletion CodeHawk/CHC/cchpre/cCHProofObligation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

Copyright (c) 2005-2019 Kestrel Technology LLC
Copyright (c) 2020 Henny B. Sipma
Copyright (c) 2021-2025 Aarno Labs LLC
Copyright (c) 2021-2026 Aarno Labs LLC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -208,6 +208,8 @@ object (self)
method clear =
begin
H.clear invarianttable;
H.clear argmessages;
H.clear keymessages;
messages#removeList messages#toList
end

Expand Down Expand Up @@ -267,6 +269,7 @@ object (self)
method is_empty =
(H.length invarianttable) = 0
&& (H.length argmessages = 0)
&& (H.length keymessages = 0)
&& messages#isEmpty

method private write_xml_situated_msg
Expand Down
Loading