-
Notifications
You must be signed in to change notification settings - Fork 273
[TG-1523] fix removed required virtual calls #1666
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
mgudemann
merged 3 commits into
diffblue:develop
from
mgudemann:bugfix/removed_required_virtual_calls
Jan 4, 2018
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file added
BIN
+752 Bytes
regression/cbmc-java/removed_virtual_functions/AbstractList$Itr.class
Binary file not shown.
Binary file not shown.
42 changes: 42 additions & 0 deletions
42
regression/cbmc-java/removed_virtual_functions/AbstractList.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
public abstract class AbstractList<E> | ||
implements List<E> | ||
{ | ||
public Iterator<E> iterator() { | ||
return new Itr(); | ||
} | ||
|
||
public ListIterator<E> listIterator() { | ||
return listIterator(0); | ||
} | ||
|
||
public boolean equals(Object o) { | ||
if (o == this) | ||
return true; | ||
if (!(o instanceof List)) | ||
return false; | ||
|
||
ListIterator<E> e1 = listIterator(); | ||
ListIterator<?> e2 = ((List<?>) o).listIterator(); | ||
while (e1.hasNext() && e2.hasNext()) { | ||
E o1 = e1.next(); | ||
Object o2 = e2.next(); | ||
if (!(o1==null ? o2==null : o1.equals(o2))) | ||
return false; | ||
} | ||
return !(e1.hasNext() || e2.hasNext()); | ||
} | ||
|
||
private class Itr implements Iterator<E> { | ||
Itr() { | ||
} | ||
|
||
public boolean hasNext() { | ||
return false; | ||
} | ||
|
||
public E next() { | ||
return null; | ||
} | ||
|
||
} | ||
} |
Binary file not shown.
Binary file added
BIN
+689 Bytes
regression/cbmc-java/removed_virtual_functions/ArrayList$ListItr.class
Binary file not shown.
Binary file not shown.
31 changes: 31 additions & 0 deletions
31
regression/cbmc-java/removed_virtual_functions/ArrayList.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
public class ArrayList<E> extends AbstractList<E> | ||
implements List<E> | ||
{ | ||
public ListIterator<E> listIterator() { | ||
return new ListItr(0); | ||
} | ||
public ListIterator<E> listIterator(int index) { | ||
return new ListItr(index); | ||
} | ||
private class ListItr extends Itr implements ListIterator<E> { | ||
ListItr(int index) { | ||
super(); | ||
} | ||
|
||
public boolean hasPrevious() { | ||
return false; | ||
} | ||
} | ||
|
||
private class Itr implements Iterator<E> { | ||
Itr() { | ||
} | ||
|
||
public boolean hasNext() { | ||
return false; | ||
} | ||
public E next() { | ||
return null; | ||
} | ||
} | ||
} |
Binary file added
BIN
+670 Bytes
regression/cbmc-java/removed_virtual_functions/ArrayListEquals.class
Binary file not shown.
11 changes: 11 additions & 0 deletions
11
regression/cbmc-java/removed_virtual_functions/ArrayListEquals.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
public class ArrayListEquals { | ||
|
||
public int check2(ArrayList<Integer> l1) { | ||
ArrayList<Integer> al = new ArrayList<Integer>(); | ||
if(l1.equals(al)) | ||
return 1; | ||
else | ||
return 0; | ||
} | ||
|
||
} |
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
public interface Iterator<E> { | ||
boolean hasNext(); | ||
E next(); | ||
} |
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
public interface List<E> { | ||
ListIterator<E> listIterator(); | ||
ListIterator<E> listIterator(int index); | ||
} |
Binary file not shown.
5 changes: 5 additions & 0 deletions
5
regression/cbmc-java/removed_virtual_functions/ListIterator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
public interface ListIterator<E> extends Iterator<E> { | ||
boolean hasNext(); | ||
boolean hasPrevious(); | ||
E next(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CORE | ||
ArrayListEquals.class | ||
--lazy-methods --java-max-vla-length 48 --unwind 8 --java-unwind-enum-static --trace --cover location --function ArrayListEquals.check2 --show-goto-functions | ||
e2 . ArrayList\$Itr.hasNext:\(\)Z\(\); | ||
-- | ||
e2 . ListIterator.hasNext:\(\)Z\(\); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ Author: Daniel Kroening, [email protected] | |
|
||
/// \file | ||
/// Remove Virtual Function (Method) Calls | ||
#include <algorithm> | ||
|
||
#include "remove_virtual_functions.h" | ||
#include "class_hierarchy.h" | ||
|
@@ -47,15 +48,20 @@ class remove_virtual_functionst | |
goto_programt::targett target); | ||
|
||
void get_functions(const exprt &, dispatch_table_entriest &); | ||
typedef std::function< | ||
resolve_concrete_function_callt::concrete_function_callt( | ||
const irep_idt &, | ||
const irep_idt &)> | ||
function_call_resolvert; | ||
void get_child_functions_rec( | ||
const irep_idt &, | ||
const symbol_exprt &, | ||
const irep_idt &, | ||
dispatch_table_entriest &, | ||
std::set<irep_idt> &visited) const; | ||
exprt get_method( | ||
const irep_idt &class_id, | ||
const irep_idt &component_name) const; | ||
std::set<irep_idt> &visited, | ||
const function_call_resolvert &) const; | ||
exprt | ||
get_method(const irep_idt &class_id, const irep_idt &component_name) const; | ||
}; | ||
|
||
remove_virtual_functionst::remove_virtual_functionst( | ||
|
@@ -192,6 +198,10 @@ void remove_virtual_functionst::remove_virtual_function( | |
{ | ||
// No definition for this type; shouldn't be possible... | ||
t1->make_assertion(false_exprt()); | ||
t1->source_location.set_comment( | ||
("cannot find calls for " + | ||
id2string(code.function().get(ID_identifier)) + " dispatching " + | ||
id2string(fun.class_id))); | ||
} | ||
insertit.first->second=t1; | ||
// goto final | ||
|
@@ -247,6 +257,7 @@ void remove_virtual_functionst::remove_virtual_function( | |
/// `last_method_defn`: the most-derived parent of `this_id` to define the | ||
/// requested function | ||
/// `component_name`: name of the function searched for | ||
/// `resolve_function_call`: function to resolve abstract method call | ||
/// \return `functions` is assigned a list of {class name, function symbol} | ||
/// pairs indicating that if `this` is of the given class, then the call will | ||
/// target the given function. Thus if A <: B <: C and A and C provide | ||
|
@@ -257,7 +268,8 @@ void remove_virtual_functionst::get_child_functions_rec( | |
const symbol_exprt &last_method_defn, | ||
const irep_idt &component_name, | ||
dispatch_table_entriest &functions, | ||
std::set<irep_idt> &visited) const | ||
std::set<irep_idt> &visited, | ||
const function_call_resolvert &resolve_function_call) const | ||
{ | ||
auto findit=class_hierarchy.class_map.find(this_id); | ||
if(findit==class_hierarchy.class_map.end()) | ||
|
@@ -278,14 +290,30 @@ void remove_virtual_functionst::get_child_functions_rec( | |
{ | ||
function.symbol_expr=last_method_defn; | ||
} | ||
if(function.symbol_expr == symbol_exprt()) | ||
{ | ||
const resolve_concrete_function_callt::concrete_function_callt | ||
&resolved_call = resolve_function_call(child, component_name); | ||
if(resolved_call.is_valid()) | ||
{ | ||
function.class_id = resolved_call.get_class_identifier(); | ||
const symbolt &called_symbol = | ||
symbol_table.lookup_ref(resolved_call.get_virtual_method_name()); | ||
|
||
function.symbol_expr = called_symbol.symbol_expr(); | ||
function.symbol_expr.set( | ||
ID_C_class, resolved_call.get_class_identifier()); | ||
} | ||
} | ||
functions.push_back(function); | ||
|
||
get_child_functions_rec( | ||
child, | ||
function.symbol_expr, | ||
component_name, | ||
functions, | ||
visited); | ||
visited, | ||
resolve_function_call); | ||
} | ||
} | ||
|
||
|
@@ -294,21 +322,30 @@ void remove_virtual_functionst::get_functions( | |
dispatch_table_entriest &functions) | ||
{ | ||
const irep_idt class_id=function.get(ID_C_class); | ||
const std::string class_id_string(id2string(class_id)); | ||
const irep_idt component_name=function.get(ID_component_name); | ||
const std::string component_name_string(id2string(component_name)); | ||
INVARIANT(!class_id.empty(), "All virtual functions must have a class"); | ||
|
||
resolve_concrete_function_callt get_virtual_call_target( | ||
symbol_table, class_hierarchy); | ||
const resolve_concrete_function_callt::concrete_function_callt & | ||
resolved_call=get_virtual_call_target(class_id, component_name); | ||
const function_call_resolvert resolve_function_call = | ||
[&get_virtual_call_target]( | ||
const irep_idt &class_id, const irep_idt &component_name) { | ||
return get_virtual_call_target(class_id, component_name); | ||
}; | ||
|
||
const resolve_concrete_function_callt::concrete_function_callt | ||
&resolved_call = get_virtual_call_target(class_id, component_name); | ||
|
||
dispatch_table_entryt root_function; | ||
|
||
if(resolved_call.is_valid()) | ||
{ | ||
root_function.class_id=resolved_call.get_class_identifier(); | ||
|
||
const symbolt &called_symbol= | ||
*symbol_table.lookup(resolved_call.get_virtual_method_name()); | ||
const symbolt &called_symbol = | ||
symbol_table.lookup_ref(resolved_call.get_virtual_method_name()); | ||
|
||
root_function.symbol_expr=called_symbol.symbol_expr(); | ||
root_function.symbol_expr.set( | ||
|
@@ -327,7 +364,8 @@ void remove_virtual_functionst::get_functions( | |
root_function.symbol_expr, | ||
component_name, | ||
functions, | ||
visited); | ||
visited, | ||
resolve_function_call); | ||
|
||
if(root_function.symbol_expr!=symbol_exprt()) | ||
functions.push_back(root_function); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does an invalid
resolved_call
mean? Should this be an invariant or is this reasonable behaviour? If reasonable, would be good to have a to have a test that explores this path.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an unresolved call should not simply remove the function call, but t least call a non-deterministic function, like it seems to be done when not using
--lazy-methods