-
Notifications
You must be signed in to change notification settings - Fork 273
Symex-dereference: simplify after deref [blocks: #2574, #4056] #3725
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 not shown.
Binary file added
BIN
+311 Bytes
jbmc/regression/jbmc-generics/constant_propagation/GenericSub.class
Binary file not shown.
Binary file not shown.
27 changes: 27 additions & 0 deletions
27
jbmc/regression/jbmc-generics/constant_propagation/Test.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,27 @@ | ||
public class Test { | ||
public static void main() { | ||
Generic<Integer> g = new GenericSub<Integer>(); | ||
|
||
int x = 0; | ||
for(int i = 0; i < 1000; ++i) | ||
x += g.get(); | ||
|
||
assert x == 0; | ||
} | ||
} | ||
|
||
class Generic<T> { | ||
T key; | ||
int x; | ||
|
||
public int get() { return 0; } | ||
|
||
public Generic() { | ||
key = null; | ||
x = 5; | ||
} | ||
} | ||
|
||
class GenericSub<S> extends Generic<S> { | ||
public int get() { return x; } | ||
} |
12 changes: 12 additions & 0 deletions
12
jbmc/regression/jbmc-generics/constant_propagation/test.desc
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,12 @@ | ||
CORE | ||
Test.class | ||
--function Test.main --show-vcc | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^\{-\d+\} symex_dynamic::dynamic_object1#3 = \{ \{ \{ "java::GenericSub" \}, NULL, 0 \} \}$ | ||
^\{-\d+\} symex_dynamic::dynamic_object1#4 = \{ \{ \{ "java::GenericSub" \}, NULL, 5 \} \}$ | ||
-- | ||
byte_extract_(big|little)_endian | ||
-- | ||
The use of generics should not result in any byte_extract operations being | ||
generated for this test. |
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,12 @@ | ||
CORE | ||
main.c | ||
|
||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
-- | ||
^warning: ignoring | ||
: dynamic_object1#\d+\) WITH | ||
-- | ||
The above pattern makes sure we don't have a conditional choice of objects | ||
within a "with" expression. We avoid having this by running the simplifier after | ||
dereferencing. |
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 |
---|---|---|
|
@@ -16,6 +16,7 @@ Author: Daniel Kroening, [email protected] | |
#include <util/byte_operators.h> | ||
#include <util/c_types.h> | ||
#include <util/exception_utils.h> | ||
#include <util/expr_util.h> | ||
#include <util/invariant.h> | ||
#include <util/pointer_offset_size.h> | ||
|
||
|
@@ -363,4 +364,30 @@ void goto_symext::dereference(exprt &expr, statet &state) | |
// dereferencing may introduce new symbol_exprt | ||
// (like __CPROVER_memory) | ||
expr = state.rename<L1>(std::move(l1_expr), ns); | ||
|
||
// Dereferencing is likely to introduce new member-of-if constructs -- | ||
// for example, "x->field" may have become "(x == &o1 ? o1 : o2).field." | ||
// Run expression simplification, which converts that to | ||
// (x == &o1 ? o1.field : o2.field)) | ||
// before applying field sensitivity. Field sensitivity can then turn such | ||
// field-of-symbol expressions into atomic SSA expressions instead of having | ||
// to rewrite all of 'o1' otherwise. | ||
// Even without field sensitivity this can be beneficial: for example, | ||
// "(b ? s1 : s2).member := X" results in | ||
// (b ? s1 : s2) := (b ? s1 : s2) with (member := X) | ||
// and then | ||
// s1 := b ? ((b ? s1 : s2) with (member := X)) : s1 | ||
// when all we need is | ||
// s1 := s1 with (member := X) [and guard b] | ||
// s2 := s2 with (member := X) [and guard !b] | ||
do_simplify(expr); | ||
|
||
if(symex_config.run_validation_checks) | ||
{ | ||
// make sure simplify has not re-introduced any dereferencing that | ||
// had previously been cleaned away | ||
INVARIANT( | ||
!has_subexpr(expr, ID_dereference), | ||
"simplify re-introduced dereferencing"); | ||
} | ||
} |
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.
I'm curious to see what the impact on performance this change has.
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.
I will benchmark (and I hope @romainbrenguier can do his benchmarking as well) once the dependencies #2068 and #3770 are merged so that we have a precise analysis.
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.
This could maybe be made faster with a simplify method which would focus on the conversions that are mentioned above.
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.
That is certainly one option - are there particular patterns that affect Java? (@smowton maybe?)
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.
Update: this appears to be causing performance degradation; we may need to look into a specialised simplifier to achieve this.