Skip to content

Commit 28f8f76

Browse files
committed
Exclude string constant equality invariants from var_eq (issue #1722)
1 parent edfcbd3 commit 28f8f76

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

src/analyses/varEq.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ struct
1717
struct
1818
include PartitionDomain.ExpPartitions
1919

20+
let is_str_constant = function
21+
| Const (CStr _ | CWStr _) -> true
22+
| _ -> false
23+
2024
let invariant ~scope ss =
2125
fold (fun s a ->
2226
if B.mem MyCFG.unknown_exp s then
@@ -25,7 +29,7 @@ struct
2529
let module B_prod = BatSet.Make2 (Exp) (Exp) in
2630
let s_prod = B_prod.cartesian_product s s in
2731
let i = B_prod.Product.fold (fun (x, y) a ->
28-
if Exp.compare x y < 0 && not (InvariantCil.exp_contains_tmp x) && not (InvariantCil.exp_contains_tmp y) && InvariantCil.exp_is_in_scope scope x && InvariantCil.exp_is_in_scope scope y then (* each equality only one way, no self-equalities *)
32+
if Exp.compare x y < 0 && not (InvariantCil.exp_contains_tmp x) && not (InvariantCil.exp_contains_tmp y) && InvariantCil.exp_is_in_scope scope x && InvariantCil.exp_is_in_scope scope y && not (is_str_constant x) && not (is_str_constant y) then (* each equality only one way, no self-equalities *)
2933
let eq = BinOp (Eq, x, y, intType) in
3034
Invariant.(a && of_exp eq)
3135
else

tests/regression/56-witness/71-var_eq-str-invariant.t

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
dead: 0
55
total lines: 3
66
[Info][Witness] witness generation summary:
7-
location invariants: 1
7+
location invariants: 0
88
loop invariants: 0
99
flow-insensitive invariants: 0
1010
total generation entries: 1
@@ -13,13 +13,4 @@ Should not contain invariant with string literal equality:
1313

1414
$ yamlWitnessStrip < witness.yml
1515
- entry_type: invariant_set
16-
content:
17-
- invariant:
18-
type: location_invariant
19-
location:
20-
file_name: 71-var_eq-str-invariant.c
21-
line: 4
22-
column: 3
23-
function: main
24-
value: '"foobar" == text'
25-
format: c_expression
16+
content: []

0 commit comments

Comments
 (0)