Skip to content

Commit 4952e78

Browse files
authored
Merge pull request #1834 from goblint/autotune-octagon-fun
Fix octagon autotuner choosing non-integer variables
2 parents 2697fbe + e0c7e32 commit 4952e78

File tree

8 files changed

+75
-23
lines changed

8 files changed

+75
-23
lines changed

src/autoTune.ml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,17 +334,16 @@ type option = {
334334
(*Option for activating the octagon apron domain on selected vars*)
335335
module VariableMap = Map.Make(CilType.Varinfo)
336336
module VariableSet = Set.Make(CilType.Varinfo)
337+
module OctagonTracked = RelationCil.AutotuneTracked
337338

338339
let isComparison = function
339340
| Lt | Gt | Le | Ge | Ne | Eq -> true
340341
| _ -> false
341342

342-
let isGoblintStub v = List.exists (fun (Attr(s,_)) -> s = "goblint_stub") v.vattr
343-
344343
let rec extractVar = function
345344
| UnOp (Neg, e, _)
346345
| CastE (_, e) -> extractVar e
347-
| Lval ((Var info),_) when not (isGoblintStub info) -> Some info
346+
| Lval ((Var info),_) when OctagonTracked.varinfo_tracked info -> Some info
348347
| _ -> None
349348

350349
let extractBinOpVars e1 e2 =
@@ -376,7 +375,7 @@ class octagonVariableVisitor(varMap, globals) = object
376375
List.iter (fun var -> addOrCreateVarMapping varMap var 5 globals) (extractOctagonVars e2);
377376
DoChildren
378377
)
379-
| Lval ((Var info),_) when not (isGoblintStub info) -> addOrCreateVarMapping varMap info 1 globals; SkipChildren
378+
| Lval ((Var info),_) when OctagonTracked.varinfo_tracked info -> addOrCreateVarMapping varMap info 1 globals; SkipChildren
380379
(*Traverse down only operations fitting for linear equations*)
381380
| UnOp (LNot, _,_)
382381
| UnOp (Neg, _,_)

src/cdomains/apron/relationDomain.apron.ml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,7 @@ struct
8181
| _ -> None
8282
end
8383

84-
module type Tracked =
85-
sig
86-
val type_tracked: typ -> bool
87-
val varinfo_tracked: varinfo -> bool
88-
end
84+
module type Tracked = RelationCil.Tracked
8985

9086
module type S2 =
9187
sig

src/cdomains/apron/sharedFunctions.apron.ml

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -518,20 +518,7 @@ sig
518518
val eval_interval : Queries.ask -> t -> Texpr1.t -> Z.t option * Z.t option
519519
end
520520

521-
module Tracked: RelationDomain.Tracked =
522-
struct
523-
let is_pthread_int_type = function
524-
| TNamed ({tname = ("pthread_t" | "pthread_key_t" | "pthread_once_t" | "pthread_spinlock_t"); _}, _) -> true (* on Linux these pthread types are integral *)
525-
| _ -> false
526-
527-
let type_tracked typ =
528-
isIntegralType typ && not (is_pthread_int_type typ)
529-
530-
let varinfo_tracked vi =
531-
(* no vglob check here, because globals are allowed in relation, but just have to be handled separately *)
532-
let hasTrackAttribute = List.exists (fun (Attr(s,_)) -> s = "goblint_relation_track") in
533-
type_tracked vi.vtype && (not @@ GobConfig.get_bool "annotation.goblint_relation_track" || hasTrackAttribute vi.vattr)
534-
end
521+
module Tracked = RelationCil.Tracked
535522

536523
module AssertionModule (V: SV) (AD: AssertionRelS) (Arg: ConvertArg) =
537524
struct

src/goblint_lib.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ module SparseVector = SparseVector
455455
module ListMatrix = ListMatrix
456456
module RatOps = RatOps
457457

458+
module RelationCil = RelationCil
458459
module SharedFunctions = SharedFunctions
459460
module GobApron = GobApron
460461

src/util/relationCil.ml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
(** CIL utilities for relational analyses. *)
2+
3+
open GoblintCil
4+
5+
module type Tracked =
6+
sig
7+
val type_tracked: typ -> bool
8+
val varinfo_tracked: varinfo -> bool
9+
end
10+
11+
module TypeTracked =
12+
struct
13+
let is_pthread_int_type = function
14+
| TNamed ({tname = ("pthread_t" | "pthread_key_t" | "pthread_once_t" | "pthread_spinlock_t"); _}, _) -> true (* on Linux these pthread types are integral *)
15+
| _ -> false
16+
17+
let type_tracked typ =
18+
isIntegralType typ && not (is_pthread_int_type typ)
19+
end
20+
21+
(** To be used in relational analyses. *)
22+
module Tracked: Tracked =
23+
struct
24+
include TypeTracked
25+
26+
let varinfo_tracked vi =
27+
(* no vglob check here, because globals are allowed in relation, but just have to be handled separately *)
28+
let hasTrackAttribute = List.exists (fun (Attr(s,_)) -> s = "goblint_relation_track") in
29+
type_tracked vi.vtype && (not (GobConfig.get_bool "annotation.goblint_relation_track") || hasTrackAttribute vi.vattr)
30+
end
31+
32+
(** To be used in autotuner. *)
33+
module AutotuneTracked: Tracked =
34+
struct
35+
include TypeTracked
36+
37+
let isGoblintStub v = List.exists (fun (Attr(s,_)) -> s = "goblint_stub") v.vattr
38+
39+
let varinfo_tracked vi = type_tracked vi.vtype && not (isGoblintStub vi) (* must not check for goblint_relation_track because the autotuner wants to add them based on this *)
40+
end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// CRAM
2+
3+
#include <pthread.h>
4+
5+
void *t_fun(void *arg) {
6+
return NULL;
7+
}
8+
9+
int main() {
10+
pthread_t id;
11+
pthread_create(&id, NULL, t_fun, NULL);
12+
13+
return 0;
14+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Should not annotate functions for octagon.
2+
3+
$ goblint --enable ana.autotune.enabled --set ana.autotune.activated[*] octagon 38-autotune-octagon-fun.c
4+
[Info] Enabled octagon domain ONLY for:
5+
[Info] i, count, tmp, count, i, j, i___0, j___0, k, size, r
6+
[Info][Deadcode] Logical lines of code (LLoC) summary:
7+
live: 5
8+
dead: 0
9+
total lines: 5
10+

tests/regression/29-svcomp/dune

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,8 @@
1818
(cram
1919
(applies_to 36-svcomp-arch)
2020
(enabled_if %{read:../../util/multilibAvailable})) ; https://dune.readthedocs.io/en/stable/reference/boolean-language.html
21+
22+
(cram
23+
(alias runaprontest)
24+
(applies_to 38-autotune-octagon-fun)
25+
(enabled_if %{lib-available:apron}))

0 commit comments

Comments
 (0)