Skip to content

Commit 83bc815

Browse files
committed
CHC: add command-line option to control the status of system includes
1 parent 7010e7d commit 83bc815

File tree

7 files changed

+60
-27
lines changed

7 files changed

+60
-27
lines changed

CodeHawk/CHC/cchanalyze/cCHGenerateAndCheck.ml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ open CHPretty
3535

3636
(* chutil *)
3737
open CHLogger
38+
open CHTiming
3839
open CHTimingLog
3940

4041
(* cchlib *)
@@ -160,6 +161,7 @@ let make_invariant_generation_spec t =
160161

161162

162163
let process_function gspecs fname =
164+
let cfilename = system_settings#get_cfilename in
163165
try
164166
if !function_to_be_analyzed = fname || !function_to_be_analyzed = "" then
165167
let _ = log_info "analyze function %s [%s:%d]" fname __FILE__ __LINE__ in
@@ -180,6 +182,10 @@ let process_function gspecs fname =
180182
(List.length openpos)
181183
__FILE__ __LINE__ in
182184
if (List.length openpos) > 0 then
185+
let _ =
186+
pr_timing [
187+
STR cfilename; STR ": ===analyze function=== "; STR fname;
188+
STR " with "; INT (List.length openpos); STR " open pos"] in
183189
let callcount = proof_scaffolding#get_call_count fname in
184190
let _ =
185191
List.iter
@@ -209,6 +215,10 @@ let process_function gspecs fname =
209215
begin
210216
gspec.ig_invariant_extractor env invio invariants;
211217
record_postconditions fname env invio;
218+
pr_timing [
219+
STR cfilename; STR ":"; STR fname;
220+
STR ": Finished analyzing with domain ";
221+
STR gspec.ig_domain]
212222
end
213223
with
214224
| CCHFailure p | CHFailure p ->
@@ -342,6 +352,7 @@ let process_function gspecs fname =
342352
let generate_and_check_process_file (domains: string list) =
343353
let gspecs = List.map make_invariant_generation_spec domains in
344354
try
355+
let cfilename = system_settings#get_cfilename in
345356
let _ = read_cfile_dictionary () in
346357
let cfile = read_cfile () in
347358
let _ = fenv#initialize cfile in
@@ -352,7 +363,14 @@ let generate_and_check_process_file (domains: string list) =
352363
let _ = read_cfile_contract () in
353364
let _ = file_contract#collect_file_attributes in
354365
let _ = log_info "Read file-level xml files [%s:%d]" __FILE__ __LINE__ in
366+
let _ = pr_timing [STR cfilename; STR ": finished loading files"] in
355367
let functions = fenv#get_application_functions in
368+
let _ =
369+
pr_timing [
370+
STR cfilename;
371+
STR ": Analyzing ";
372+
INT (List.length functions);
373+
STR " functions"] in
356374
let _ =
357375
log_info "Processing %d functions [%s:%d]"
358376
(List.length functions) __FILE__ __LINE__ in
@@ -363,6 +381,7 @@ let generate_and_check_process_file (domains: string list) =
363381
let _ = save_cfile_interface_dictionary () in
364382
let _ = save_cfile_predicate_dictionary () in
365383
let _ = log_info "Saved file-level xml files [%s:%d]" __FILE__ __LINE__ in
384+
let _ = pr_timing [STR cfilename; STR ": finished saving files"] in
366385
()
367386
with
368387
| CHXmlReader.IllFormed ->

CodeHawk/CHC/cchcil/cCHXParseFile.ml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ open CHCilWriteXml
5252
let projectpath = ref ""
5353
let targetdirectory = ref ""
5454
let filename = ref ""
55-
let filterfiles = ref true
55+
let keep_system_includes = ref false
5656
let keepUnused = ref false
5757

5858
let version = "CP1.1"
@@ -70,8 +70,8 @@ let speclist = [
7070
"path to the project base directory");
7171
("-targetdirectory", Arg.String set_targetdirectory,
7272
"directory to store the generated xml files");
73-
("-nofilter", Arg.Unit (fun () -> filterfiles := false),
74-
"don't filter out functions in files starting with slash");
73+
("-keep_system_includes", Arg.Unit (fun () -> keep_system_includes := true),
74+
"don't filter out functions in files with an absolute path name");
7575
("-keepUnused",
7676
Arg.Set keepUnused, "keep unused type and function definitions")]
7777

@@ -241,11 +241,12 @@ let save_xml_file f =
241241
match g with
242242
| GFun (fdec, _loc) -> fdec :: a | _ -> a) [] f.globals in
243243
let fns =
244-
if !filterfiles then
245-
List.filter (fun fdec ->
246-
not ((String.get fdec.svar.vdecl.file 0) = '/')) fns
244+
if !keep_system_includes then
245+
fns
247246
else
248-
fns in
247+
(* filter out functions with an absolute path names *)
248+
List.filter (fun fdec ->
249+
not ((String.get fdec.svar.vdecl.file 0) = '/')) fns in
249250
let fnsTarget = Filename.concat (Filename.dirname absoluteTarget) "functions" in
250251
begin
251252
List.iter (fun f -> cil_function_to_file target f fnsTarget) fns;

CodeHawk/CHC/cchcmdline/cCHXCAnalyzer.ml

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ open CHPretty
3333
(* chutil *)
3434
open CHGc
3535
open CHLogger
36+
open CHTiming
3637
open CHTimingLog
3738
open CHXmlDocument
3839

@@ -128,14 +129,15 @@ let speclist = [
128129
"print status on proof obligations and invariants");
129130
("-projectname", Arg.String system_settings#set_projectname,
130131
"name of the project (determines name of results directory)");
131-
("-nofilter", Arg.Unit (fun () -> system_settings#set_filterabspathfiles false),
132-
"do not filter out functions in files with absolute path names");
133-
("-unreachability", Arg.Unit (fun () -> system_settings#set_use_unreachability),
134-
"use unreachability as a justification for discharging proof obligations");
135-
("-wordsize", Arg.Int system_settings#set_wordsize,
136-
"set word size (e.g., 16, 32, or 64)");
137-
("-contractpath", Arg.String system_settings#set_contractpath,
138-
"path to contract files")
132+
("-keep_system_includes",
133+
Arg.Unit (fun () -> system_settings#set_keep_system_includes true),
134+
"do not filter out functions in files with absolute path names");
135+
("-unreachability", Arg.Unit (fun () -> system_settings#set_use_unreachability),
136+
"use unreachability as a justification for discharging proof obligations");
137+
("-wordsize", Arg.Int system_settings#set_wordsize,
138+
"set word size (e.g., 16, 32, or 64)");
139+
("-contractpath", Arg.String system_settings#set_contractpath,
140+
"path to contract files")
139141
]
140142

141143
let usage_msg = "chc_analyze <options> <path to analysis directory>"
@@ -153,10 +155,11 @@ let save_log_files (contenttype:string) =
153155

154156
let main () =
155157
try
156-
let _ = set_log_level "DEBUG" in
158+
let _ = set_log_level "WARNING" in
157159
let _ = read_args () in
158160
let _ = chlog#set_max_entry_size 1000 in
159161
let _ = log_info "AIAIAIAIAIAIAIAIAIAIAIAIAIAIAIAIAIAIAIAIAIAIAIAIAIAIAIAI" in
162+
let cfilename = system_settings#get_cfilename in
160163
if !cmd = "version" then
161164
begin
162165
pr_debug [version#toPretty; NL];
@@ -201,13 +204,15 @@ let main () =
201204
else if !cmd = "generate_and_check" then
202205
begin
203206
generate_and_check_process_file (List.rev !domains);
207+
pr_timing [STR cfilename; STR ": finished generate_and_check"];
204208
log_info
205209
"Invariants generated and proof obligations checked [%s:%d]"
206210
__FILE__ __LINE__;
207211
save_log_files "gencheck";
208212
log_info
209213
"Invariant generation and proof obligation check log files saved [%s:%d]"
210-
__FILE__ __LINE__
214+
__FILE__ __LINE__;
215+
pr_timing [STR cfilename; STR ": finished saving log files"]
211216
end
212217

213218
else

CodeHawk/CHC/cchlib/cCHFileEnvironment.ml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,11 @@ object (self)
9898
method initialize (f:file) =
9999
let _ = self#reset in
100100
let is_application_function (v:varinfo) =
101-
if system_settings#filterabspathfiles then
102-
not ((String.get v.vdecl.file 0) = '/')
101+
if system_settings#keep_system_includes then
102+
true
103103
else
104-
true in
104+
(* filter out functions originating from files from system path *)
105+
not ((String.get v.vdecl.file 0) = '/') in
105106
begin
106107
List.iter (fun g ->
107108
match g with

CodeHawk/CHC/cchlib/cCHLibTypes.mli

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -872,8 +872,13 @@ class type system_settings_int =
872872
method set_verbose: bool -> unit
873873
method verbose: bool
874874

875-
method set_filterabspathfiles: bool -> unit
876-
method filterabspathfiles: bool
875+
(* The [keep_system_includes] is set to false by default. If set to [true]
876+
(by command-line option), it assumes that functions from system includes
877+
(specifically, functions from include files whose path starts with '/')
878+
have been parsed by CIL and are to be included in the analysis.
879+
*)
880+
method set_keep_system_includes: bool -> unit
881+
method keep_system_includes: bool
877882

878883
method set_wordsize: int -> unit
879884
method get_wordsize: int

CodeHawk/CHC/cchlib/cCHSettings.ml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ object
4646
val mutable contractpath = ""
4747

4848
val mutable verbose = false
49-
val mutable filterabspathfiles = true
49+
val mutable keep_system_includes = false
5050
val mutable wordsize = Some 32
5151
val mutable use_unreachability = false
5252
val mutable analysis_level = ImplementationDefinedBehavior
@@ -78,7 +78,8 @@ object
7878

7979
method set_verbose (v:bool) = verbose <- v
8080

81-
method set_filterabspathfiles (v:bool) = filterabspathfiles <- v
81+
method set_keep_system_includes (v:bool) = keep_system_includes <- v
82+
method keep_system_includes = keep_system_includes
8283

8384
method set_wordsize (v:int) = wordsize <- Some v
8485

@@ -98,7 +99,7 @@ object
9899

99100
method use_unreachability = use_unreachability
100101
method verbose = verbose
101-
method filterabspathfiles = filterabspathfiles
102+
102103
method has_wordsize = match wordsize with Some _ -> true | _ -> false
103104

104105

CodeHawk/CHC/cchpre/cCHCreatePrimaryProofObligations.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ let process_function (fname:string) =
9393

9494
let primary_process_file () =
9595
try
96+
let cfilename = system_settings#get_cfilename in
9697
let _ = read_cfile_dictionary () in
9798
let _ = read_cfile_interface_dictionary () in
9899
let cfile = read_cfile () in
@@ -101,8 +102,8 @@ let primary_process_file () =
101102
let functions = fenv#get_application_functions in
102103
let _ =
103104
log_info
104-
"Cfile initialized with %d functions [%s:%d]"
105-
(List.length functions)
105+
"Cfile %s initialized with %d functions [%s:%d]"
106+
cfilename (List.length functions)
106107
__FILE__ __LINE__ in
107108
let _ = read_cfile_contract () in
108109
let _ = file_contract#collect_file_attributes in

0 commit comments

Comments
 (0)