Skip to content

Vsd value set implementation #5793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 30 commits into from
Feb 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
158bb26
Improve interval_abstract_objectt::expression_transform
jezhiggins Jan 19, 2021
2d925bc
value_set_abstract_objectt::set_value must mark not top
jezhiggins Jan 19, 2021
e524b04
More value-set behaviour tests
jezhiggins Jan 20, 2021
ed0b73b
value_set_abstract_objectt correctly evaluates n-ary expressions
jezhiggins Jan 20, 2021
59cef52
Made resolve_new_values private rather than protected
jezhiggins Jan 20, 2021
b20595e
Removed get_as_interval() - not used
jezhiggins Jan 20, 2021
9e90a7c
Moved set_values body into cpp file
jezhiggins Jan 20, 2021
be437f9
Private static member functions moved to free functions in the cpp
jezhiggins Jan 20, 2021
6595b3b
Private template member functions moved to free template in cpp
jezhiggins Jan 20, 2021
42028f4
Pull out a few clarifying functions in value_set_abstract_objectt
jezhiggins Jan 20, 2021
9a8f370
Array access with value-sets works!
jezhiggins Jan 20, 2021
7b7308b
Array read with multi-value value-set index and multi-value value-set…
jezhiggins Jan 20, 2021
58b3912
Factor out interval_abstract_valuet::evaluate_conditional
jezhiggins Jan 26, 2021
837df22
Value set ternary operator evaluation
jezhiggins Jan 26, 2021
c2a8fd0
Make value_set_abstract_objectt compatible with context tracking
jezhiggins Jan 26, 2021
e80ee3b
Pass operands vector by ref into value_set evaluate_conditional
jezhiggins Jan 27, 2021
7f8e7ba
Reworked object creation in variable_sensitivity_object_factoryt
jezhiggins Jan 27, 2021
37c32e3
Ensure returned value_set objects have correct context
jezhiggins Jan 27, 2021
4366e75
Large value-sets are converted to intervals
jezhiggins Jan 27, 2021
50bb92e
Use make_shared - preferable to constructing by hand
jezhiggins Jan 27, 2021
d245ab9
Simplifiy interval_abstract_valuet::expression_transform
jezhiggins Jan 29, 2021
0e06d2a
Clean up warnings in interval_abstract_valuet
jezhiggins Jan 29, 2021
033acbb
Clean up warnings in constant_abstract_valuet
jezhiggins Jan 29, 2021
7fed622
Remove default arguments from abstract_environmentt::abstract_object_…
jezhiggins Jan 29, 2021
6d0085c
Small fixes in abstract_environmentt
jezhiggins Jan 29, 2021
a488b3c
Sort value-set output
jezhiggins Jan 30, 2021
bf90f75
clang-format fixes
jezhiggins Jan 30, 2021
5ad0c9d
value-set and data-dependencies is a valid combination
jezhiggins Feb 2, 2021
f9b2f93
Combine all the ternary-operator tests into one directory
jezhiggins Feb 2, 2021
f363e38
Remove interval_abstract_objectt::merge_count
jezhiggins Feb 3, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions regression/goto-analyzer/ternary-operator/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <stdbool.h>

extern int x;

int main(void)
{
bool b1;
bool b2;

b1 = true;
b2 = !b1;

bool b3 = x ? true : false;
int i = b1 ? 10 : 20;
int j = b2 ? 10 : 20;
int k = b3 ? 10 : 20;

return 0;
}
12 changes: 12 additions & 0 deletions regression/goto-analyzer/ternary-operator/test-constants.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CORE
main.c
--variable-sensitivity --vsd-values constants --show
^EXIT=0$
^SIGNAL=0$
main::1::b1 \(\) -> TRUE @ \[2\]
main::1::b2 \(\) -> FALSE @ \[3\]
main::1::b3 \(\) -> TOP @ \[5\]
main::1::i \(\) -> 10 @ \[7\]
main::1::j \(\) -> 20 @ \[9\]
main::1::k \(\) -> TOP @ \[11\]
--
12 changes: 12 additions & 0 deletions regression/goto-analyzer/ternary-operator/test-intervals.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CORE
main.c
--variable-sensitivity --vsd-values intervals --show
^EXIT=0$
^SIGNAL=0$
main::1::b1 \(\) -> \[1, 1\] @ \[2\]
main::1::b2 \(\) -> \[0, 0\] @ \[3\]
main::1::b3 \(\) -> \[0, 1\] @ \[5\]
main::1::i \(\) -> \[A, A\] @ \[7\]
main::1::j \(\) -> \[14, 14\] @ \[9\]
main::1::k \(\) -> \[A, 14\] @ \[11\]
--
12 changes: 12 additions & 0 deletions regression/goto-analyzer/ternary-operator/test-value-sets.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CORE
main.c
--variable-sensitivity --vsd-values set-of-constants --show
^EXIT=0$
^SIGNAL=0$
main::1::b1 \(\) -> value-set-begin: TRUE :value-set-end
main::1::b2 \(\) -> value-set-begin: FALSE :value-set-end
main::1::b3 \(\) -> value-set-begin: TRUE, FALSE :value-set-end
main::1::i \(\) -> value-set-begin: 10 :value-set-end
main::1::j \(\) -> value-set-begin: 20 :value-set-end
main::1::k \(\) -> value-set-begin: 10, 20 :value-set-end
--
6 changes: 6 additions & 0 deletions regression/goto-analyzer/value-set-addition-01/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
int main(int argc, char argv[])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting fixes to code which has been added as part of this PR should ideally be merged into the commit where it is added. Only fixes to code which isn't changed/added by your PR really needs to be in separate commits. This fixing of formatting in these commits can be automated using - git filter-branch --tree-filter 'git-clang-format develop' -- develop..HEAD. Assuming that your PR is already based on develop.

{
int p = 1;

int q = p + 2;
}
8 changes: 8 additions & 0 deletions regression/goto-analyzer/value-set-addition-01/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
--variable-sensitivity --vsd-values set-of-constants --show
^EXIT=0$
^SIGNAL=0$
main::1::p .* value-set-begin: 1 :value-set-end
main::1::q .* value-set-begin: 3 :value-set-end
--
7 changes: 7 additions & 0 deletions regression/goto-analyzer/value-set-addition-02/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
int main(int argc, char argv[])
{
int p = 2;
int q = 3;

int t = p + q;
}
9 changes: 9 additions & 0 deletions regression/goto-analyzer/value-set-addition-02/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
main.c
--variable-sensitivity --vsd-values set-of-constants --show
^EXIT=0$
^SIGNAL=0$
main::1::p .* value-set-begin: 2 :value-set-end
main::1::q .* value-set-begin: 3 :value-set-end
main::1::t .* value-set-begin: 5 :value-set-end
--
11 changes: 11 additions & 0 deletions regression/goto-analyzer/value-set-addition-03/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
int unknown();

int main(int argc, char argv[])
{
int p = 2;

if(unknown())
p += 2;
else
p += 3;
}
7 changes: 7 additions & 0 deletions regression/goto-analyzer/value-set-addition-03/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CORE
main.c
--variable-sensitivity --vsd-values set-of-constants --show
^EXIT=0$
^SIGNAL=0$
main::1::p .* value-set-begin: 4, 5 :value-set-end
--
14 changes: 14 additions & 0 deletions regression/goto-analyzer/value-set-addition-04/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
int unknown();

int main(int argc, char argv[])
{
int p = 2;
int q = 3;

if(unknown())
p += 2;
else
p += 3;

int t = p + q;
}
10 changes: 10 additions & 0 deletions regression/goto-analyzer/value-set-addition-04/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE
main.c
--variable-sensitivity --vsd-values set-of-constants --show
^EXIT=0$
^SIGNAL=0$
main::1::p .* value-set-begin: 2 :value-set-end
main::1::q .* value-set-begin: 3 :value-set-end
main::1::p .* value-set-begin: 4, 5 :value-set-end
main::1::t .* value-set-begin: 7, 8 :value-set-end
--
20 changes: 20 additions & 0 deletions regression/goto-analyzer/value-set-addition-05/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
int unknown();

int main(int argc, char argv[])
{
int p;
int q;

if(unknown())
{
p = 2;
q = 5;
}
else
{
p = 3;
q = 10;
}

int t = p + q;
}
9 changes: 9 additions & 0 deletions regression/goto-analyzer/value-set-addition-05/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
main.c
--variable-sensitivity --vsd-values set-of-constants --show
^EXIT=0$
^SIGNAL=0$
main::1::p .* value-set-begin: 2, 3 :value-set-end
main::1::q .* value-set-begin: 5, 10 :value-set-end
main::1::t .* value-set-begin: 7, 8, 12, 13 :value-set-end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is especially interesting as it shows that the abstraction is not relational; the link between p and q is not maintained after the merge at the end of the if, so you wind up with false alarms like 12.

--
21 changes: 21 additions & 0 deletions regression/goto-analyzer/value-set-addition-06/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
int unknown();

int main(int argc, char argv[])
{
int p;
int q;
int r = 20;

if(unknown())
{
p = 2;
q = 5;
}
else
{
p = 3;
q = 10;
}

int t = p + q + r;
}
9 changes: 9 additions & 0 deletions regression/goto-analyzer/value-set-addition-06/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
main.c
--variable-sensitivity --vsd-values set-of-constants --show
^EXIT=0$
^SIGNAL=0$
main::1::p .* value-set-begin: 2, 3 :value-set-end
main::1::q .* value-set-begin: 5, 10 :value-set-end
main::1::t .* value-set-begin: 27, 28, 32, 33 :value-set-end
--
23 changes: 23 additions & 0 deletions regression/goto-analyzer/value-set-addition-07/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
int unknown();

int main(int argc, char argv[])
{
int p;
int q;
int r = 20;

if(unknown())
p = 2;
else
p = 3;
if(unknown())
q = 5;
else
q = 10;
if(unknown())
r = 20;
else
r = 30;

int t = p + q + r;
}
10 changes: 10 additions & 0 deletions regression/goto-analyzer/value-set-addition-07/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE
main.c
--variable-sensitivity --vsd-values set-of-constants --show
^EXIT=0$
^SIGNAL=0$
main::1::p .* value-set-begin: 2, 3 :value-set-end
main::1::q .* value-set-begin: 5, 10 :value-set-end
main::1::r .* value-set-begin: 20, 30 :value-set-end
main::1::t .* value-set-begin: 27, 28, 32, 33, 37, 38, 42, 43 :value-set-end
--
22 changes: 22 additions & 0 deletions regression/goto-analyzer/value-set-addition-08/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
int unknown();

int main(int argc, char argv[])
{
int p;
int q;
int r = 20;
;

if(unknown())
p = 2;
else
p = 3;
if(unknown())
p = 4;
if(unknown())
q = 5;
else
q = 10;

int t = p + q + r;
}
10 changes: 10 additions & 0 deletions regression/goto-analyzer/value-set-addition-08/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE
main.c
--variable-sensitivity --vsd-values set-of-constants --show
^EXIT=0$
^SIGNAL=0$
main::1::p .* value-set-begin: 2, 3, 4 :value-set-end
main::1::q .* value-set-begin: 5, 10 :value-set-end
main::1::r .* value-set-begin: 20 :value-set-end
main::1::t .* value-set-begin: 27, 28, 29, 32, 33, 34 :value-set-end
--
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CORE
main.c
--show --variable-sensitivity --vsd-values set-of-constants --vsd-arrays every-element
^EXIT=0$
^SIGNAL=0$
main::1::second_value \(\) -> value-set-begin: 2 :value-set-end
main::1::second_value_after_write \(\) -> value-set-begin: 10 :value-set-end
38 changes: 38 additions & 0 deletions regression/goto-analyzer/value-set-convert-to-interval/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <stdbool.h>

extern int x;

int main(void)
{
int a = 0;
int b = 20;
switch(x)
{
case 1:
a = 1;
b = 21;
break;
case 2:
a = 2;
b = 22;
break;
case 3:
a = 3;
b = 23;
break;
case 4:
a = 4;
b = 24;
break;
case 5:
a = 5;
break;
case 6:
a = 6;
break;
}

int c = a + b;

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
main.c
--variable-sensitivity --vsd-values set-of-constants --show
^EXIT=0$
^SIGNAL=0$
main::1::a .* value-set-begin: 0, 1, 2, 3, 4, 5, 6 :value-set-end @ \[1, 12, 15, 18, 21, 24, 26\]
main::1::b .* value-set-begin: 20, 21, 22, 23, 24 :value-set-end @ \[3, 13, 16, 19, 22\]
main::1::c .* \[14, 1E\] @ \[30\]
--
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ main.c
--variable-sensitivity --vsd-structs every-field --vsd-arrays every-element --vsd-pointers value-set --vsd-values set-of-constants --show --pointer-check --three-way-merge
^file main.c line 29 function main: replacing function pointer by 2 possible targets$
^file main.c line 40 function main: replacing function pointer by 2 possible targets$
^main::1::fun1 \(\) -> value-set-begin: ptr ->\([fg]\), ptr ->\([fg]\), :value-set-end$
^main::1::fun_array3 \(\) -> \{\[0\] = value-set-begin: ptr ->\([fg]\), ptr ->\([fg]\), :value-set-end$
^main::1::fun1 \(\) -> value-set-begin: ptr ->\(f\), ptr ->\(g\) :value-set-end
^main::1::fun_array3 \(\) -> \{\[0\] = value-set-begin: ptr ->\(f\), ptr ->\(g\) :value-set-end
^EXIT=0$
^SIGNAL=0$
--
^warning: ignoring
^main::1::fun1 \(\) -> value-set-begin: .*ptr ->\(h\).* :value-set-end$
^main::1::fun_array3 \(\) -> \{\[0\] = value-set-begin: .*ptr ->\(h\).* :value-set-end$
^main::1::fun1 \(\) -> value-set-begin: .*ptr ->\(h\).* :value-set-end
^main::1::fun_array3 \(\) -> \{\[0\] = value-set-begin: .*ptr ->\(h\).* :value-set-end
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ CORE
main.c
--variable-sensitivity --vsd-values set-of-constants --vsd-structs every-field --vsd-arrays every-element --vsd-pointers value-set --show --pointer-check
^file main.c line 28 function main: replacing function pointer by 2 possible targets$
^main::1::fun_incremented_show \(\) -> TOP$
^main::1::fun_incremented_show \(\) -> value-set-begin: TOP :value-set-end
^EXIT=0$
^SIGNAL=0$
--
^warning: ignoring
^main::1::fun_incremented_show \(\) -> value-set-begin: .* :value-set-end$
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <assert.h>

typedef int (*fptr_t)(int);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that, as things stand, function pointers are removed before analysis.

fptr_t fun_global, fun_global_show;

int f(int x)
{
return x + 1;
}
int g(int x)
{
return x;
}
int h(int x)
{
return x - 1;
}

int main(void)
{
int i;
// This line is needed so that g is considered as a possibility for the TOP
// value
fptr_t dummy = g;

// function pointer incremented should be top
fptr_t fun_incremented = f;
if(i)
++fun_incremented;
else
fun_incremented = h;
fun_incremented(5);
fptr_t fun_incremented_show = fun_incremented;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
--variable-sensitivity --vsd-values set-of-constants --vsd-structs every-field --vsd-arrays every-element --vsd-pointers value-set --show --pointer-check
^file main.c line 32 function main: replacing function pointer by 3 possible targets$
^main::1::fun_incremented_show \(\) -> value-set-begin: TOP, ptr ->\(h\) :value-set-end
^EXIT=0$
^SIGNAL=0$
--
Loading