Skip to content

Commit 8e96d57

Browse files
committed
CHC: update checker for locally initialized
1 parent 2b25c87 commit 8e96d57

File tree

3 files changed

+33
-39
lines changed

3 files changed

+33
-39
lines changed

CodeHawk/CHC/cchanalyze/cCHGenerateAndCheck.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
Copyright (c) 2005-2019 Kestrel Technology LLC
88
Copyright (c) 2020-2022 Henny B. Sipma
9-
Copyright (c) 2023-2024 Aarno Labs LLC
9+
Copyright (c) 2023-2025 Aarno Labs LLC
1010
1111
Permission is hereby granted, free of charge, to any person obtaining a copy
1212
of this software and associated documentation files (the "Software"), to deal
@@ -28,4 +28,4 @@
2828
============================================================================= *)
2929

3030

31-
val generate_and_check_process_file: string list -> unit
31+
val generate_and_check_process_file: string list -> unit CHTraceResult.traceresult

CodeHawk/CHC/cchanalyze/cCHPOCheckLocallyInitialized.ml

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ open XprTypes
3636
(* cchlib *)
3737
open CCHBasicTypes
3838
open CCHTypesToPretty
39-
open CCHTypesUtil
4039

4140
(* cchpre *)
4241
open CCHMemoryBase
@@ -136,7 +135,7 @@ object (self)
136135
end
137136

138137
method private memlval_implies_safe (memlval: lval) (inv: invariant_int) =
139-
let mname = "memlval_vinv_implies_safe" in
138+
let mname = "memlval_implies_safe" in
140139
match inv#expr with
141140
| Some (XVar v) when poq#env#is_memory_address v ->
142141
let (memref, _) = poq#env#get_memory_address v in
@@ -318,41 +317,29 @@ object (self)
318317
None
319318
end
320319

321-
method private memlval_vinv_implies_violation
322-
(inv: invariant_int) (memoffset: offset) =
323-
let mname = "memlval_vinv_implies_violation" in
320+
method private memlval_implies_violation (memoffset: offset) (inv: invariant_int) =
321+
let mname = "memlval_implies_violation" in
324322
match inv#expr with
325323
| Some x when poq#is_api_expression x ->
326324
begin
327325
match poq#get_api_expression x with
328-
| Lval lval ->
329-
if is_constant_offset memoffset then
330-
let memlval = (Mem (Lval lval), memoffset) in
331-
let deps = DLocal ([inv#index]) in
332-
let msg =
333-
"initialized from parameter "
334-
^ (p2s (lval_to_pretty memlval))
335-
^ " with offset "
336-
^ (p2s (offset_to_pretty memoffset)) in
337-
let site = Some (__FILE__, __LINE__, mname) in
338-
Some (deps, msg, site)
339-
else
340-
begin
341-
poq#set_diagnostic
342-
~site:(Some (__FILE__, __LINE__, mname))
343-
("[api-lval, memoffset]: "
344-
^ (p2s (lval_to_pretty lval))
345-
^ ", "
346-
^ (p2s (offset_to_pretty memoffset)));
347-
None
348-
end
349-
| api_e ->
350-
begin
351-
poq#set_diagnostic
352-
~site:(Some (__FILE__, __LINE__, mname))
353-
("[api_e]: " ^ (e2s api_e));
354-
None
355-
end
326+
| Lval ((Var ((_, vid)), NoOffset) as lval) when vid = self#vinfo.vid ->
327+
let apimemlval = (Mem (Lval lval), memoffset) in
328+
let deps = DLocal ([inv#index]) in
329+
let msg =
330+
"initialized from parameter "
331+
^ (p2s (lval_to_pretty apimemlval))
332+
^ " with offset "
333+
^ (p2s (offset_to_pretty memoffset)) in
334+
let site = Some (__FILE__, __LINE__, mname) in
335+
Some (deps, msg, site)
336+
| api_e ->
337+
begin
338+
poq#set_diagnostic
339+
~site:(Some (__FILE__, __LINE__, mname))
340+
("[api_e]: " ^ (e2s api_e));
341+
None
342+
end
356343
end
357344
| _ ->
358345
begin
@@ -367,16 +354,15 @@ object (self)
367354

368355
method private check_violation_memlval (memlval: lval) (memoffset: offset) =
369356
match memlval with
370-
| (Var (_, vid), _) when vid > 0 ->
357+
| (Var (_, vid), _) ->
371358
let lvinfo = poq#env#get_varinfo vid in
372359
let vinfovalues = poq#get_vinfo_offset_values lvinfo in
373360
List.fold_left (fun acc (inv, offset) ->
374361
acc
375362
|| (match offset with
376363
| NoOffset ->
377364
begin
378-
match self#memlval_vinv_implies_violation
379-
inv memoffset with
365+
match self#memlval_implies_violation memoffset inv with
380366
| Some (deps, msg, site) ->
381367
begin
382368
poq#record_violation_result ~site deps msg;

CodeHawk/CHC/cchanalyze/cCHPOQuery.ml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,15 @@ object (self)
293293
po#set_status status;
294294
po#set_dependencies deps;
295295
po#set_explanation ~site expl;
296-
po#set_resolution_timestamp (current_time_to_string ())
296+
po#set_resolution_timestamp (current_time_to_string ());
297+
(match proof_scaffolding#record_proof_obligation_result self#fname po with
298+
| Ok _ -> ()
299+
| Error e ->
300+
raise
301+
(CCHFailure
302+
(LBLOCK [
303+
STR "Error in record-proof-result: ";
304+
STR (String.concat "; " e)])))
297305
end
298306

299307
method set_diagnostic

0 commit comments

Comments
 (0)