Skip to content

Commit

Permalink
Merge pull request #1612 from goblint/svcomp-auto-malloc
Browse files Browse the repository at this point in the history
Autotune for `ana.malloc.unique_address_count` for NoOverflows in SV-Comp
  • Loading branch information
sim642 authored Nov 7, 2024
2 parents e8b56ec + 72bf7d6 commit 06e0554
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 21 deletions.
1 change: 1 addition & 0 deletions conf/svcomp-validate.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"wideningThresholds",
"loopUnrollHeuristic",
"memsafetySpecification",
"noOverflows",
"termination",
"tmpSpecialAnalysis"
]
Expand Down
1 change: 1 addition & 0 deletions conf/svcomp.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"wideningThresholds",
"loopUnrollHeuristic",
"memsafetySpecification",
"noOverflows",
"termination",
"tmpSpecialAnalysis"
]
Expand Down
64 changes: 47 additions & 17 deletions src/autoTune.ml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,34 @@ class functionVisitor(calling, calledBy, argLists, dynamicallyCalled) = object
DoChildren
end

exception Found
class findAllocsInLoops = object
inherit nopCilVisitor

val mutable inloop = false

method! vstmt stmt =
let outOfLoop stmt =
match stmt.skind with
| Loop _ -> inloop <- false; stmt
| _ -> stmt
in
match stmt.skind with
| Loop _ -> inloop <- true; ChangeDoChildrenPost(stmt, outOfLoop)
| _ -> DoChildren

method! vinst = function
| Call (_, Lval (Var f, NoOffset), args,_,_) when LibraryFunctions.is_special f ->
Goblint_backtrace.protect ~mark:(fun () -> Cilfacade.FunVarinfo f) ~finally:Fun.id @@ fun () ->
let desc = LibraryFunctions.find f in
begin match desc.special args with
| Malloc _
| Alloca _ when inloop -> raise Found
| _ -> DoChildren
end
| _ -> DoChildren
end

type functionCallMaps = {
calling: FunctionSet.t FunctionCallMap.t;
calledBy: (FunctionSet.t * int) FunctionCallMap.t;
Expand Down Expand Up @@ -230,18 +258,28 @@ let focusOnTermination (spec: Svcomp.Specification.t) =
let focusOnTermination () =
List.iter focusOnTermination (Svcomp.Specification.of_option ())

let focusOnSpecification (spec: Svcomp.Specification.t) =
let concurrencySafety (spec: Svcomp.Specification.t) =
match spec with
| UnreachCall s -> ()
| NoDataRace -> (*enable all thread analyses*)
Logs.info "Specification: NoDataRace -> enabling thread analyses \"%s\"" (String.concat ", " notNeccessaryThreadAnalyses);
enableAnalyses notNeccessaryThreadAnalyses;
| NoOverflow -> (*We focus on integer analysis*)
set_bool "ana.int.def_exc" true
| _ -> ()

let focusOnSpecification () =
List.iter focusOnSpecification (Svcomp.Specification.of_option ())
let noOverflows (spec: Svcomp.Specification.t) =
match spec with
| NoOverflow ->
(*We focus on integer analysis*)
set_bool "ana.int.def_exc" true;
begin
try
ignore @@ visitCilFileSameGlobals (new findAllocsInLoops) (!Cilfacade.current_file);
set_int "ana.malloc.unique_address_count" 1
with Found -> set_int "ana.malloc.unique_address_count" 0;
end
| _ -> ()

let focusOn (f : SvcompSpec.t -> unit) =
List.iter f (Svcomp.Specification.of_option ())

(*Detect enumerations and enable the "ana.int.enums" option*)
exception EnumFound
Expand Down Expand Up @@ -489,15 +527,6 @@ let isActivated a = get_bool "ana.autotune.enabled" && List.mem a @@ get_string_

let isTerminationTask () = List.mem Svcomp.Specification.Termination (Svcomp.Specification.of_option ())

let specificationIsActivated () =
isActivated "specification" && get_string "ana.specification" <> ""

let specificationTerminationIsActivated () =
isActivated "termination"

let specificationMemSafetyIsActivated () =
isActivated "memsafetySpecification"

let chooseConfig file =
let factors = collectFactors visitCilFileSameGlobals file in
let fileCompplexity = estimateComplexity factors file in
Expand All @@ -517,8 +546,9 @@ let chooseConfig file =
if isActivated "mallocWrappers" then
findMallocWrappers ();

if specificationIsActivated () then
focusOnSpecification ();
if isActivated "concurrencySafetySpecification" then focusOn concurrencySafety;

if isActivated "noOverflows" then focusOn noOverflows;

if isActivated "enums" && hasEnums file then
set_bool "ana.int.enums" true;
Expand Down
6 changes: 4 additions & 2 deletions src/config/options.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,6 @@
"enum": [
"congruence",
"singleThreaded",
"specification",
"mallocWrappers",
"noRecursiveIntervals",
"enums",
Expand All @@ -545,14 +544,15 @@
"octagon",
"wideningThresholds",
"memsafetySpecification",
"concurrencySafetySpecification",
"noOverflows",
"termination",
"tmpSpecialAnalysis"
]
},
"default": [
"congruence",
"singleThreaded",
"specification",
"mallocWrappers",
"noRecursiveIntervals",
"enums",
Expand All @@ -561,6 +561,8 @@
"octagon",
"wideningThresholds",
"memsafetySpecification",
"concurrencySafetySpecification",
"noOverflows",
"termination",
"tmpSpecialAnalysis"
]
Expand Down
2 changes: 1 addition & 1 deletion src/goblint.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ let main () =
Logs.debug "%s" GobSys.command_line;
(* When analyzing a termination specification, activate the termination analysis before pre-processing. *)
if get_string "ana.specification" <> "" then AutoSoundConfig.enableAnalysesForTerminationSpecification ();
if AutoTune.specificationTerminationIsActivated () then AutoTune.focusOnTermination ();
if AutoTune.isActivated "termination" then AutoTune.focusOnTermination ();
let file = lazy (Fun.protect ~finally:GoblintDir.finalize preprocess_parse_merge) in
if get_bool "server.enabled" then (
let file =
Expand Down
2 changes: 1 addition & 1 deletion src/maingoblint.ml
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ let handle_options () =
Sys.set_signal (GobSys.signal_of_string (get_string "dbg.solver-signal")) Signal_ignore; (* Ignore solver-signal before solving (e.g. MyCFG), otherwise exceptions self-signal the default, which crashes instead of printing backtrace. *)
if get_string "ana.specification" <> "" then
AutoSoundConfig.enableAnalysesForMemSafetySpecification ();
if AutoTune.specificationMemSafetyIsActivated () then
if AutoTune.isActivated "memsafetySpecification" then
AutoTune.focusOnMemSafetySpecification ();
AfterConfig.run ();
Cilfacade.init_options ();
Expand Down

0 comments on commit 06e0554

Please sign in to comment.