Skip to content

Aggressive slicer v2 #2385

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 7 commits into from
Jul 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
36 changes: 36 additions & 0 deletions regression/goto-instrument/aggressive_slicer1/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// test should pass. Shortest path main -> C -> D
void D()
{
__CPROVER_assert(0, "");
}

void C()
{
int nondet;
if(nondet)
D();
}

void B()
{
C();
};

int main()
{
int nondet;

__CPROVER_assume(nondet != 3);
switch(nondet)
{
case 1:
B();
break;
case 3:
C();
break;
default:
break;
}
return 0;
}
8 changes: 8 additions & 0 deletions regression/goto-instrument/aggressive_slicer1/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
--aggressive-slice
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
^warning: ignoring
39 changes: 39 additions & 0 deletions regression/goto-instrument/aggressive_slicer2/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// test should pass. Shortest path is preserved, main -> C -> D,
// but is not a possible counterexample because of assumption that
// nondet != 3

void D()
{
__CPROVER_assert(0, "");
}

void C()
{
int nondet;
if(nondet)
D();
}

void B()
{
C();
};

int main()
{
int nondet;

__CPROVER_assume(nondet != 3);
switch(nondet)
{
case 1:
B();
break;
case 3:
C();
break;
default:
break;
}
return 0;
}
8 changes: 8 additions & 0 deletions regression/goto-instrument/aggressive_slicer2/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
--aggressive-slice --property D.assertion.1
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
^warning: ignoring
35 changes: 35 additions & 0 deletions regression/goto-instrument/aggressive_slicer3/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// test should fail. Shortest path is preserved, main -> C -> D,
void D()
{
__CPROVER_assert(0, "");
}

void C()
{
int nondet;
if(nondet)
D();
}

void B()
{
C();
};

int main()
{
int nondet;

switch(nondet)
{
case 1:
B();
break;
case 3:
C();
break;
default:
break;
}
return 0;
}
8 changes: 8 additions & 0 deletions regression/goto-instrument/aggressive_slicer3/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
--aggressive-slice
^EXIT=10$
^SIGNAL=0$
^VERIFICATION FAILED$
--
^warning: ignoring
39 changes: 39 additions & 0 deletions regression/goto-instrument/aggressive_slicer4/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// test should fail
// shortest path only is not sufficient to violate assertion,
// but we specifically require that function B is kept, which
// allows path main -> B -> C -> D

void D()
{
__CPROVER_assert(0, "");
}

void C()
{
int nondet;
if(nondet)
D();
}

void B()
{
C();
};

int main()
{
int nondet;
__CPROVER_assume(nondet != 3);
switch(nondet)
{
case 1:
B();
break;
case 3:
C();
break;
default:
break;
}
return 0;
}
8 changes: 8 additions & 0 deletions regression/goto-instrument/aggressive_slicer4/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
--aggressive-slice --aggressive-slice-preserve-function B
^EXIT=10$
^SIGNAL=0$
^VERIFICATION FAILED$
--
^warning: ignoring
38 changes: 38 additions & 0 deletions regression/goto-instrument/aggressive_slicer5/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Test should fail. Shortest path only is not sufficient
// due to assumption that nondet !=3, but
// preserve-all-direct-paths preserves the path main -> B -> C -> D.

void D()
Copy link
Contributor

Choose a reason for hiding this comment

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

Similarly for the rest of these tests -- briefly comment stating the intent of the test, either in the source or the desc file

{
__CPROVER_assert(0, "");
}

void C()
{
int nondet;
if(nondet)
D();
}

void B()
{
C();
};

int main()
{
int nondet;
__CPROVER_assume(nondet != 3);
switch(nondet)
{
case 1:
B();
break;
case 3:
C();
break;
default:
break;
}
return 0;
}
8 changes: 8 additions & 0 deletions regression/goto-instrument/aggressive_slicer5/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
Copy link
Member

Choose a reason for hiding this comment

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

The file aggressive_slicer5/test.binary must not be committed.

--aggressive-slice --property D.assertion.1 --aggressive-slice-preserve-all-direct-paths
^EXIT=10$
^SIGNAL=0$
^VERIFICATION FAILED$
--
^warning: ignoring
40 changes: 40 additions & 0 deletions regression/goto-instrument/aggressive_slicer6/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Test should fail
// Assertion in D is reachable when call depth of 1 is preserved,
// Shortest path = main -> C -> D, which is not possible due to assumption
// nondet!=3, but call depth 1 preserves the body of function B, which can also reach
// C.

void D()
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding a test case with more than one property, so specifying a property makes a difference?

{
__CPROVER_assert(0, "");
}

void C()
{
int nondet;
if(nondet)
D();
}

void B()
{
C();
};

int main()
{
int nondet;
__CPROVER_assume(nondet != 3);
switch(nondet)
{
case 1:
B();
break;
case 3:
C();
break;
default:
break;
}
return 0;
}
8 changes: 8 additions & 0 deletions regression/goto-instrument/aggressive_slicer6/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
--aggressive-slice --aggressive-slice-call-depth 1
^EXIT=10$
^SIGNAL=0$
^VERIFICATION FAILED$
--
^warning: ignoring
46 changes: 46 additions & 0 deletions regression/goto-instrument/aggressive_slicer7/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Test should fail
// Assertion in D is reachable by main -> C -> D
// Assertion in E is reachable by main -> E

void D()
{
__CPROVER_assert(0, "");
}

void C()
{
int nondet;
if(nondet)
D();
}

void B()
{
C();
};

void E()
{
__CPROVER_assert(0, "");
}

int main()
{
int nondet;

switch(nondet)
{
case 1:
B();
break;
case 2:
E();
break;
case 3:
C();
break;
default:
break;
}
return 0;
}
8 changes: 8 additions & 0 deletions regression/goto-instrument/aggressive_slicer7/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c
--aggressive-slice
^EXIT=10$
^SIGNAL=0$
^VERIFICATION FAILED$
--
^warning: ignoring
30 changes: 27 additions & 3 deletions src/analyses/call_graph_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ std::set<irep_idt> get_reaching_functions(
std::set<irep_idt> get_functions_reachable_within_n_steps(
const call_grapht::directed_grapht &graph,
const std::set<irep_idt> &start_functions,
std::size_t &n)
std::size_t n)
{
std::vector<std::size_t> start_indices;
std::set<irep_idt> result;
Expand All @@ -91,8 +91,32 @@ std::set<irep_idt> get_functions_reachable_within_n_steps(
std::set<irep_idt> get_functions_reachable_within_n_steps(
const call_grapht::directed_grapht &graph,
const irep_idt &start_function,
std::size_t &n)
std::size_t n)
{
std::set<irep_idt> start_functions({ start_function });
std::set<irep_idt> start_functions({start_function});
return get_functions_reachable_within_n_steps(graph, start_functions, n);
}

void disconnect_unreachable_functions(
call_grapht::directed_grapht &graph,
const irep_idt &function)
{
graph.disconnect_unreachable(*(graph.get_node_index(function)));
}

std::list<irep_idt> get_shortest_function_path(
const call_grapht::directed_grapht &graph,
const irep_idt &src,
const irep_idt &dest)
{
std::list<irep_idt> result;
std::list<std::size_t> path;

graph.shortest_path(
*(graph.get_node_index(src)), *(graph.get_node_index(dest)), path);

for(const auto &n : path)
result.push_back(graph[n].function);

return result;
}
Loading