Skip to content

Commit bab63df

Browse files
Merge pull request #493 from goblint/annotations_via_options
Annotations via options
2 parents 666f68d + a95089a commit bab63df

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+425
-161
lines changed

src/analyses/base.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,8 +1100,8 @@ struct
11001100
| `Struct _
11011101
| `Union _ ->
11021102
begin
1103-
let vars_in_paritioning = VD.affecting_vars value in
1104-
let dep_new = List.fold_left (fun dep var -> add_one_dep x var dep) st.deps vars_in_paritioning in
1103+
let vars_in_partitioning = VD.affecting_vars value in
1104+
let dep_new = List.fold_left (fun dep var -> add_one_dep x var dep) st.deps vars_in_partitioning in
11051105
{ st with deps = dep_new }
11061106
end
11071107
(* `List and `Blob cannot contain arrays *)
@@ -1282,7 +1282,7 @@ struct
12821282
{ st with cpa = List.fold_left f st.cpa v_list; deps = List.fold_left g st.deps v_list }
12831283

12841284
(* Removes all partitionings done according to this variable *)
1285-
let rem_many_paritioning a (st:store) (v_list: varinfo list):store =
1285+
let rem_many_partitioning a (st:store) (v_list: varinfo list):store =
12861286
(* Removes the partitioning information from all affected arrays, call before removing locals *)
12871287
let rem_partitioning a (st:store) (x:varinfo):store =
12881288
let affected_arrays =
@@ -1849,7 +1849,7 @@ struct
18491849
Priv.enter_multithreaded (Analyses.ask_of_ctx ctx) (priv_getg ctx.global) (priv_sideg ctx.sideg) st
18501850
| _ ->
18511851
let locals = List.filter (fun v -> not (WeakUpdates.mem v st.weak)) (fundec.sformals @ fundec.slocals) in
1852-
let nst_part = rem_many_paritioning (Analyses.ask_of_ctx ctx) ctx.local locals in
1852+
let nst_part = rem_many_partitioning (Analyses.ask_of_ctx ctx) ctx.local locals in
18531853
let nst: store = rem_many (Analyses.ask_of_ctx ctx) nst_part locals in
18541854
match exp with
18551855
| None -> nst

src/util/contextUtil.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
open Cil
22

3-
(** Definition of Goblint specific user defined C attributes **)
3+
(** Definition of Goblint specific user defined C attributes and their alternatives via options **)
44

55
type attribute =
66
| GobContext
@@ -19,10 +19,14 @@ let has_attribute s1 s2 al =
1919
| _ -> false
2020
) al
2121

22+
let has_option s1 s2 fd =
23+
List.mem fd.svar.vname (GobConfig.get_string_list ("annotation." ^ s1 ^ "." ^ s2))
24+
2225
let should_keep ~isAttr ~keepOption ~removeAttr ~keepAttr fd =
2326
let al = fd.svar.vattr in
2427
let s = attribute_to_string isAttr in
25-
match GobConfig.get_bool keepOption, has_attribute s removeAttr al, has_attribute s keepAttr al with
28+
let has_annot a = has_option s a fd || has_attribute s a al in
29+
match GobConfig.get_bool keepOption, has_annot removeAttr, has_annot keepAttr with
2630
| _, true, true ->
2731
failwith (Printf.sprintf "ContextUtil.should_remove: conflicting context attributes %s and %s on %s" removeAttr keepAttr (CilType.Fundec.show fd))
2832
| _, false, true

src/util/defaults.ml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type category = Std (** Parsing input, includes, standard stuff, etc
1212
| Incremental (** Incremental features *)
1313
| Semantics (** Semantics *)
1414
| Transformations (** Transformations *)
15-
| Annotation (** Features for annotations *)
15+
| Annotation (** Features for annotations *)
1616
| Experimental (** Experimental features of analyses *)
1717
| Debugging (** Debugging, tracing, etc. *)
1818
| Warnings (** Filtering warnings *)
@@ -181,6 +181,24 @@ let _ = ()
181181
let _ = ()
182182
; reg Annotation "annotation.int.enabled" "false" "Enable manual annotation of functions with desired precision, i.e. the activated IntDomains."
183183
; reg Annotation "annotation.int.privglobs" "true" "Enables handling of privatized globals, by setting the precision to the heighest value, when annotation.int.enabled is true."
184+
; reg Annotation "annotation.goblint_context.base.no-non-ptr" "[]" ""
185+
; reg Annotation "annotation.goblint_context.base.non-ptr" "[]" ""
186+
; reg Annotation "annotation.goblint_context.base.no-int" "[]" ""
187+
; reg Annotation "annotation.goblint_context.base.int" "[]" ""
188+
; reg Annotation "annotation.goblint_context.base.no-interval" "[]" ""
189+
; reg Annotation "annotation.goblint_context.base.interval" "[]" ""
190+
; reg Annotation "annotation.goblint_context.apron.no-context" "[]" ""
191+
; reg Annotation "annotation.goblint_context.apron.context" "[]" ""
192+
; reg Annotation "annotation.goblint_context.no-widen" "[]" ""
193+
; reg Annotation "annotation.goblint_context.widen" "[]" ""
194+
; reg Annotation "annotation.goblint_precision.no-def_exc" "[]" ""
195+
; reg Annotation "annotation.goblint_precision.def_exc" "[]" ""
196+
; reg Annotation "annotation.goblint_precision.no-interval" "[]" ""
197+
; reg Annotation "annotation.goblint_precision.interval" "[]" ""
198+
; reg Annotation "annotation.goblint_precision.no-enums" "[]" ""
199+
; reg Annotation "annotation.goblint_precision.enums" "[]" ""
200+
; reg Annotation "annotation.goblint_precision.no-congruence" "[]" ""
201+
; reg Annotation "annotation.goblint_precision.congruence" "[]" ""
184202

185203
(* {4 category [Experimental]} *)
186204
let _ = ()
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// PARAM: --enable ana.int.interval --disable ana.context.widen --enable ana.base.context.int --set annotation.goblint_context.base.no-int[+] f
2+
#include <assert.h>
3+
4+
int f(int x) {
5+
if (x)
6+
return f(x+1);
7+
else
8+
return x;
9+
}
10+
11+
int main () {
12+
int a = f(1);
13+
assert(!a);
14+
return 0;
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// PARAM: --enable ana.int.interval --disable ana.context.widen --disable ana.base.context.int --set annotation.goblint_context.base.int[+] f
2+
#include <assert.h>
3+
4+
int f(int x) {
5+
if (x)
6+
return x * f(x - 1);
7+
else
8+
return 1;
9+
}
10+
11+
int main () {
12+
int a = f(10);
13+
assert(a == 3628800);
14+
return 0;
15+
}

tests/regression/23-partitioned_arrays_last/01-simple_array.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ void example7(void) {
156156
assert(a[top] == 0); // UNKNOWN
157157
}
158158

159-
// Check that the global variable is not used for paritioning
159+
// Check that the global variable is not used for partitioning
160160
void example8() {
161161
int a[10];
162162

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
// PARAM: --enable annotation.int.enabled --set ana.int.refinement fixpoint
22
#include<assert.h>
33

4-
int f(int in) __attribute__ ((goblint_precision("def_exc", "interval"))) {
4+
int f(int in) __attribute__ ((goblint_precision("def_exc", "interval")));
5+
int main() __attribute__ ((goblint_precision("def_exc")));
6+
7+
int f(int in) {
58
in++;
69
return in;
710
}
811

9-
int main() __attribute__ ((goblint_precision("def_exc"))) {
12+
int main() {
1013
int a = 0;
1114
assert(a); // FAIL!
1215
a = f(a);
1316
assert(a);
1417
return 0;
15-
}
18+
}
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
// PARAM: --enable annotation.int.enabled --set ana.int.refinement fixpoint
22
#include<assert.h>
33

4-
int f(int in) __attribute__ ((goblint_precision("no-def_exc","interval"))) {
4+
int f(int in) __attribute__ ((goblint_precision("no-def_exc","interval")));
5+
int main() __attribute__ ((goblint_precision("def_exc", "interval"))) ;
6+
7+
int f(int in) {
58
in++;
69
return in;
710
}
811

9-
int main() __attribute__ ((goblint_precision("def_exc", "interval"))) {
12+
int main() {
1013
int a = 0;
1114
assert(a); // FAIL!
1215
a = f(a);
1316
assert(a);
1417
return 0;
15-
}
18+
}
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
// PARAM: --enable annotation.int.enabled --set ana.int.refinement fixpoint
22
#include<assert.h>
33

4-
int f(int in) __attribute__ ((goblint_precision("no-def_exc","interval"))) {
4+
int f(int in) __attribute__ ((goblint_precision("no-def_exc","interval")));
5+
int main() __attribute__ ((goblint_precision("no-def_exc","congruence")));
6+
7+
int f(int in) {
58
in++;
69
return in;
710
}
811

9-
int main() __attribute__ ((goblint_precision("no-def_exc","congruence"))) {
12+
int main() {
1013
int a = 0;
1114
int b = f(a);
1215
assert(b);
1316
a = b % 2;
1417
b = f(a);
1518
assert(b == 2);
1619
return 0;
17-
}
20+
}

tests/regression/42-annotated-precision/04-struct.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ struct a {
66
int i;
77
};
88

9-
void f(struct a *in) __attribute__ ((goblint_precision("no-def_exc","interval", "congruence"))) {
9+
void f(struct a *in) __attribute__ ((goblint_precision("no-def_exc","interval", "congruence")));
10+
int main() __attribute__ ((goblint_precision("congruence")));
11+
12+
void f(struct a *in) {
1013
in->i += 4;
1114
return;
1215
}
1316

14-
int main() __attribute__ ((goblint_precision("congruence"))) {
17+
int main() {
1518
struct a a1, b1 = {"Jane", 3};
1619

1720
a1.name = "John";
@@ -24,4 +27,4 @@ int main() __attribute__ ((goblint_precision("congruence"))) {
2427
b1.i = a1.i % 5;
2528
assert(b1.i); // FAIL!
2629
return 0;
27-
}
30+
}

0 commit comments

Comments
 (0)