Skip to content

Commit bc25988

Browse files
committed
CHC:add representation for output parameter rejection reasons
1 parent 66ecadb commit bc25988

11 files changed

+134
-32
lines changed

CodeHawk/CH/chutil/cHTraceResult.ml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,16 @@ let tbind_iter_list (f: 'a -> unit traceresult) (args: 'a list): unit traceresul
168168
| _ -> f a) (Ok ()) args
169169

170170

171+
let tbind_map_list (f: 'a -> 'b traceresult) (args: 'a list): 'b list traceresult =
172+
List.fold_left (fun acc_r a ->
173+
match acc_r with
174+
| Error _ -> acc_r
175+
| Ok vl ->
176+
match f a with
177+
| Error e -> Error e
178+
| Ok v -> Ok (vl @ [v])) (Ok []) args
179+
180+
171181
let to_bool (f: 'a -> bool) (r: 'a traceresult) =
172182
match r with
173183
| Ok v -> f v

CodeHawk/CH/chutil/cHTraceResult.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ val tfold_list_fail:
143143
val tbind_iter_list: ('a -> unit traceresult) -> 'a list -> unit traceresult
144144

145145

146+
val tbind_map_list: ('a -> 'b traceresult) -> 'a list -> 'b list traceresult
147+
148+
146149
(** [to_bool f r] is [f v] if [r] is [Ok v] and [false] otherwise.*)
147150
val to_bool: ('a -> bool) -> 'a traceresult -> bool
148151

CodeHawk/CHC/cchcil/cCHXParseFile.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,17 @@ let save_xml_file f =
240240
List.fold_left (fun a g ->
241241
match g with
242242
| GFun (fdec, _loc) -> fdec :: a | _ -> a) [] f.globals in
243+
let _ =
244+
log_info "Found %d function(s) [%s:%d]" (List.length fns) __FILE__ __LINE__ in
245+
let _ =
246+
List.iter (fun fn -> log_info "Decl: %s" fn.svar.vdecl.file) fns in
243247
let fns =
244248
if !keep_system_includes then
245249
fns
246250
else
247251
(* filter out functions with an absolute path names *)
248252
List.filter (fun fdec ->
249-
not ((String.get fdec.svar.vdecl.file 0) = '/')) fns in
253+
not ((String.sub fdec.svar.vdecl.file 0 4) = "/usr")) fns in
250254
let fnsTarget = Filename.concat (Filename.dirname absoluteTarget) "functions" in
251255
begin
252256
List.iter (fun f -> cil_function_to_file target f fnsTarget) fns;

CodeHawk/CHC/cchlib/cCHTypesUtil.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ let rec is_scalar_struct_type (t: typ): bool =
870870
| TComp (ckey, _) ->
871871
let cinfo = fenv#get_comp ckey in
872872
List.for_all (fun finfo ->
873-
match finfo.ftype with
873+
match fenv#get_type_unrolled finfo.ftype with
874874
| TInt _
875875
| TFloat _
876876
| TPtr _

CodeHawk/CHC/cchpre/cCHCandidateOutputParameter.ml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ open CCHPreTypes
3939

4040
module H = Hashtbl
4141

42-
let (let* ) x f = CHTraceResult.tbind f x
42+
let (let* ) x f = CHTraceResult.tbind f x
4343

4444
let ccontexts = CCHContext.ccontexts
4545
let cdictionary = CCHDictionary.cdictionary
@@ -150,7 +150,7 @@ object (self)
150150
fdecls#write_xml_location node self#loc;
151151
ccontexts#write_xml_context node self#ctxt;
152152
cdictionary#write_xml_exp_opt node self#rv;
153-
end
153+
end
154154

155155
end
156156

@@ -163,11 +163,11 @@ object (self)
163163
val mutable status: output_parameter_status_t = OpUnknown
164164
val returnsites = H.create 3 (* ictxt -> copparam_returnsite_t *)
165165
val calldeps = H.create 3 (* ictxt -> copparam_call_dependency_t *)
166-
val mutable reject_reasons: string list = []
166+
val mutable reject_reasons: output_parameter_rejection_reason_t list = []
167167

168168
method parameter = vinfo
169169

170-
method reject (reason: string) =
170+
method reject (reason: output_parameter_rejection_reason_t) =
171171
begin
172172
reject_reasons <- reason :: reject_reasons;
173173
status <- OpRejected reject_reasons
@@ -177,15 +177,17 @@ object (self)
177177
match po#get_predicate with
178178
| PLocallyInitialized _ ->
179179
if po#is_violation then
180-
self#reject
181-
("parameter is read at line " ^ (string_of_int po#get_location.line))
180+
self#reject (OpParameterRead po#get_location.line)
181+
| POutputParameterScalar (vinfo, _) ->
182+
if po#is_violation then
183+
self#reject (OpArrayType vinfo.vtype)
182184
| POutputParameterInitialized _
183185
| POutputParameterUnaltered _ ->
184186
let ictxt = ccontexts#index_context po#get_context in
185187
if H.mem returnsites ictxt then
186188
(H.find returnsites ictxt)#record_proof_obligation_result po
187189
| _ -> ()
188-
190+
189191

190192
method is_active (_po_s: proof_obligation_int list) =
191193
match status with

CodeHawk/CHC/cchpre/cCHCreateOutputParameterPOs.ml

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -439,37 +439,31 @@ let initialize_output_parameters
439439
let ptype = fenv#get_type_unrolled ptrparam.vtype in
440440
if has_const_attribute ptype then
441441
(* parameter is read-only *)
442-
analysisdigest#reject_parameter pname "parameter has const qualifier"
442+
analysisdigest#reject_parameter pname (OpConstQualifier ptype)
443443
else if has_deref_const_attribute ptype then
444444
(* pointed-to object is read-only *)
445-
analysisdigest#reject_parameter
446-
pname "deref parameter has const qualifier"
445+
analysisdigest#reject_parameter pname (OpConstQualifier ptype)
447446
else if is_char_star_type ptype then
448447
(* parameter is probably an array, excluded for now *)
449-
analysisdigest#reject_parameter pname "parameter is a char-star"
448+
analysisdigest#reject_parameter pname (OpArrayType ptype)
450449
else if is_void_ptr_type ptype then
451450
(* parameter target has undetermined type, excluded for now *)
452-
analysisdigest#reject_parameter pname "parameter is void-star"
451+
analysisdigest#reject_parameter pname OpVoidPointer
453452
else
454453
match ptype with
455454
| TPtr (tgt, _) ->
456455
(match tgt with
457456
| TPtr _ ->
458457
(* parameter is pointer to pointer, excluded for now *)
459-
analysisdigest#reject_parameter pname "parameter is double reference"
458+
analysisdigest#reject_parameter pname (OpPointerPointer ptype)
460459
| TComp (ckey, _) when is_system_struct tgt ->
461460
(* structs created by a system library, such as _IO__FILE_ *)
462461
let compinfo = fenv#get_comp ckey in
463-
analysisdigest#reject_parameter
464-
pname
465-
("parameter is pointer to system struct: " ^ compinfo.cname)
462+
analysisdigest#reject_parameter pname (OpSystemStruct compinfo)
466463
| TComp (ckey, _) when not (is_scalar_struct_type tgt) ->
467464
(* struct has embedded arrays, excluded for now *)
468465
let compinfo = fenv#get_comp ckey in
469-
analysisdigest#reject_parameter
470-
pname
471-
("parameter is pointer to struct with embedded array: " ^
472-
compinfo.cname)
466+
analysisdigest#reject_parameter pname (OpArrayStruct compinfo)
473467
| _ -> (* accept *) Ok ())
474468
| _ ->
475469
Error [__FILE__ ^ ":" ^ (string_of_int __LINE__);
@@ -484,7 +478,7 @@ let process_function (fname:string): unit traceresult =
484478
let _ = log_info "Process function %s [%s:%d]" fname __FILE__ __LINE__ in
485479
let fundec = read_function_semantics fname in
486480
let ptrparams = get_pointer_parameters fundec in
487-
if (List.length ptrparams) > 0 then
481+
(* if (List.length ptrparams) > 0 then *)
488482
let _ = read_proof_files fname fundec.sdecls in
489483
let* _ = proof_scaffolding#initialize_output_parameter_analysis fname in
490484
let* analysisdigest = proof_scaffolding#get_output_parameter_analysis fname in
@@ -495,8 +489,8 @@ let process_function (fname:string): unit traceresult =
495489
let _ = save_proof_files fname in
496490
let _ = save_api fname in
497491
Ok ()
498-
else
499-
Ok ()
492+
(* else
493+
Ok () *)
500494

501495

502496
let output_parameter_po_process_file (): unit traceresult =
@@ -508,7 +502,7 @@ let output_parameter_po_process_file (): unit traceresult =
508502
let _ = fenv#initialize cfile in
509503
let _ = cdeclarations#index_location call_sink in
510504
let functions = fenv#get_application_functions in
511-
let functions = List.filter (fun f -> not (f.vname = "main")) functions in
505+
(* let functions = List.filter (fun f -> not (f.vname = "main")) functions in *)
512506
let _ =
513507
log_info
514508
"Cfile %s initialized with %d functions [%s:%d]"

CodeHawk/CHC/cchpre/cCHOutputParameterAnalysis.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,9 @@ object (self)
222222
method private callee_callsites =
223223
H.fold (fun _ v a -> v :: a) callee_callsites []
224224

225-
method reject_parameter (vname: string) (reason: string): unit traceresult =
225+
method reject_parameter
226+
(vname: string)
227+
(reason: output_parameter_rejection_reason_t): unit traceresult =
226228
if H.mem params vname then
227229
Ok ((H.find params vname)#reject reason)
228230
else

CodeHawk/CHC/cchpre/cCHPODictionary.ml

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ open CCHPreSumTypeSerializer
4545
open CCHPreTypes
4646

4747
module H = Hashtbl
48+
module TR = CHTraceResult
4849

50+
let (let* ) x f = CHTraceResult.tbind f x
4951

5052
let cdecls = CCHDeclarations.cdeclarations
5153
let cd = CCHDictionary.cdictionary
@@ -87,6 +89,8 @@ class podictionary_t
8789
(_fname:string) (fdecls:cfundeclarations_int):podictionary_int =
8890
object (self)
8991

92+
val output_parameter_rejection_reason_table =
93+
mk_index_table "output-parameter-rejection-reason-table"
9094
val output_parameter_status_table = mk_index_table "output-parameter-status-table"
9195
val assumption_table = mk_index_table "assumption-table"
9296
val ppo_type_table = mk_index_table "ppo-type-table"
@@ -96,6 +100,7 @@ object (self)
96100

97101
initializer
98102
tables <- [
103+
output_parameter_rejection_reason_table;
99104
output_parameter_status_table;
100105
assumption_table;
101106
ppo_type_table;
@@ -104,11 +109,43 @@ object (self)
104109

105110
method fdecls = fdecls
106111

112+
method index_output_parameter_rejection_reason
113+
(r: output_parameter_rejection_reason_t) =
114+
let tags = [output_parameter_rejection_reason_mcts#ts r] in
115+
let key = match r with
116+
| OpConstQualifier ty -> (tags, [cd#index_typ ty])
117+
| OpSystemStruct cinfo -> (tags, [cdecls#index_compinfo cinfo])
118+
| OpArrayStruct cinfo -> (tags, [cdecls#index_compinfo cinfo])
119+
| OpArrayType ty -> (tags, [cd#index_typ ty])
120+
| OpVoidPointer -> (tags, [])
121+
| OpPointerPointer ty -> (tags, [cd#index_typ ty])
122+
| OpParameterRead linenumber -> (tags, [linenumber])
123+
| OpOtherReason reason -> (tags, [cd#index_string reason]) in
124+
output_parameter_rejection_reason_table#add key
125+
126+
method get_output_parameter_rejection_reason (index: int):
127+
output_parameter_rejection_reason_t traceresult =
128+
let name = "output_parameter_rejection_reason" in
129+
let (tags, args) = output_parameter_rejection_reason_table#retrieve index in
130+
let t = t name tags in
131+
let a = a name args in
132+
match (t 0) with
133+
| "a" -> Ok (OpArrayStruct (cdecls#get_compinfo (a 0)))
134+
| "at" -> Ok (OpArrayType (cd#get_typ (a 0)))
135+
| "c" -> Ok (OpConstQualifier (cd#get_typ (a 0)))
136+
| "o" -> Ok (OpOtherReason (cd#get_string (a 0)))
137+
| "p" -> Ok (OpPointerPointer (cd#get_typ (a 0)))
138+
| "r" -> Ok (OpParameterRead (a 0))
139+
| "s" -> Ok (OpSystemStruct (cdecls#get_compinfo (a 0)))
140+
| "v" -> Ok OpVoidPointer
141+
| s -> Error [elocm __LINE__ name s output_parameter_rejection_reason_mcts#tags]
142+
107143
method index_output_parameter_status (s: output_parameter_status_t) =
108144
let tags = [output_parameter_status_mcts#ts s] in
109145
let key = match s with
110146
| OpUnknown -> (tags, [])
111-
| OpRejected rs -> (tags, (List.map cd#index_string rs))
147+
| OpRejected rs ->
148+
(tags, (List.map self#index_output_parameter_rejection_reason rs))
112149
| OpViable -> (tags, [])
113150
| OpWritten -> (tags, [])
114151
| OpUnaltered -> (tags, []) in
@@ -124,7 +161,10 @@ object (self)
124161
| "v" -> Ok OpViable
125162
| "w" -> Ok OpWritten
126163
| "a" -> Ok OpUnaltered
127-
| "r" -> Ok (OpRejected (List.map cd#get_string args))
164+
| "r" ->
165+
let* reasons =
166+
TR.tbind_map_list self#get_output_parameter_rejection_reason args in
167+
Ok (OpRejected reasons)
128168
| s -> Error [elocm __LINE__ name s output_parameter_status_mcts#tags]
129169

130170
method index_assumption (a:assumption_type_t) =

CodeHawk/CHC/cchpre/cCHPreSumTypeSerializer.ml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,33 @@ let address_type_mfts: address_type_t mfts_int =
5858
mk_mfts "address_type_t" [(Heap, "h"); (Stack, "s"); (External, "x")]
5959

6060

61+
class output_parameter_rejection_reason_mcts_t:
62+
[output_parameter_rejection_reason_t] mfts_int =
63+
object
64+
65+
inherit [output_parameter_rejection_reason_t] mcts_t
66+
"output_parameter_rejection_reason_t"
67+
68+
method! ts (r: output_parameter_rejection_reason_t) =
69+
match r with
70+
| OpConstQualifier _ -> "c"
71+
| OpSystemStruct _ -> "s"
72+
| OpArrayStruct _ -> "a"
73+
| OpArrayType _ -> "at"
74+
| OpVoidPointer -> "v"
75+
| OpPointerPointer _ -> "p"
76+
| OpParameterRead _ -> "r"
77+
| OpOtherReason _ -> "o"
78+
79+
method! tags = ["a"; "at"; "c"; "p"; "r"; "s"; "v"]
80+
81+
end
82+
83+
let output_parameter_rejection_reason_mcts:
84+
output_parameter_rejection_reason_t mfts_int =
85+
new output_parameter_rejection_reason_mcts_t
86+
87+
6188
class output_parameter_status_mcts_t: [output_parameter_status_t] mfts_int =
6289
object
6390

CodeHawk/CHC/cchpre/cCHPreSumTypeSerializer.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ val bound_type_mfts: bound_type_t mfts_int
4141

4242
val dependencies_mcts: dependencies_t mfts_int
4343

44+
val output_parameter_rejection_reason_mcts:
45+
output_parameter_rejection_reason_t mfts_int
46+
4447
val output_parameter_status_mcts: output_parameter_status_t mfts_int
4548

4649
val po_status_mfts: po_status_t mfts_int

0 commit comments

Comments
 (0)