-
Notifications
You must be signed in to change notification settings - Fork 273
Improve performance and fix limitations of flatten_byte_operators [blocks: #3725] #2068
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
6 commits
Select commit
Hold shift + click to select a range
02a6b8b
Rewrite byte_update lowering to respect endianness, support composite…
tautschnig 3c9900c
Do not introduce byte_extract_exprt during flattening
tautschnig 6ab3311
Lower byte_{extract,update} over pointers and unbounded arrays
tautschnig f906b43
Use byte_update lowering in SMT2 conversion
tautschnig ce49794
Byte-operator lowering: support void-typed updates
tautschnig 4ada4bf
Byte-operator lowering: support structs containing bit-fields
tautschnig 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.
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,13 @@ | ||
public class andNot_Bug { | ||
public static void main(int capacity) { | ||
if(capacity < 1) | ||
return; | ||
boolean b1 = true; | ||
boolean b2[] = new boolean[capacity]; | ||
b2[0] = false; | ||
|
||
for (int i = 0; i < b2.length; i++) { | ||
b1 = b1 && !b2[i]; | ||
} | ||
} | ||
} |
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,7 @@ | ||
CORE | ||
andNot_Bug.class | ||
--depth 1600 --java-unwind-enum-static --java-max-vla-length 48 --unwind 4 --max-nondet-string-length 100 --function andNot_Bug.main | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
-- | ||
-- |
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,16 @@ | ||
#include <assert.h> | ||
#include <string.h> | ||
|
||
int main() | ||
{ | ||
char foo[1]; | ||
char result = 0; | ||
int size; | ||
__CPROVER_assume(size == 1); | ||
|
||
memset(&result, 42, size); | ||
__CPROVER_assert(result == 42, "should succeed"); | ||
result = 42; | ||
memcpy(&result, foo, size); | ||
__CPROVER_assert(result == 42, "should fail"); | ||
} |
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,10 @@ | ||
CORE | ||
main.c | ||
|
||
^EXIT=10$ | ||
^SIGNAL=0$ | ||
^VERIFICATION FAILED$ | ||
^\[main.assertion.1\] line 12 should succeed: SUCCESS$ | ||
^\[main.assertion.2\] line 15 should fail: FAILURE$ | ||
-- | ||
^warning: ignoring |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
CORE broken-smt-backend | ||
CORE | ||
main.c | ||
|
||
^EXIT=0$ | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
CORE broken-smt-backend | ||
CORE | ||
main.c | ||
--big-endian | ||
^EXIT=0$ | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
CORE broken-smt-backend | ||
CORE | ||
main.i | ||
--bounds-check --32 --no-simplify | ||
^EXIT=10$ | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
CORE broken-smt-backend | ||
CORE | ||
main.i | ||
--bounds-check --32 | ||
^EXIT=10$ | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
CORE | ||
CORE broken-smt-backend | ||
main.c | ||
|
||
^EXIT=0$ | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
CORE broken-smt-backend | ||
CORE | ||
main.c | ||
--unwind 2 --pointer-check | ||
^EXIT=10$ | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
CORE broken-smt-backend | ||
CORE | ||
main.c | ||
--little-endian | ||
^EXIT=0$ | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
CORE broken-smt-backend | ||
CORE | ||
main.c | ||
--little-endian | ||
^EXIT=0$ | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
CORE broken-smt-backend | ||
CORE | ||
main.c | ||
--little-endian | ||
^EXIT=0$ | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
CORE broken-smt-backend | ||
CORE | ||
main.c | ||
--little-endian | ||
^EXIT=0$ | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
CORE broken-smt-backend | ||
CORE | ||
main.c | ||
--little-endian | ||
^EXIT=0$ | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
CORE broken-smt-backend | ||
CORE | ||
main.c | ||
--big-endian | ||
^EXIT=0$ | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
CORE | ||
CORE broken-smt-backend | ||
c99-bool-1.c | ||
|
||
^EXIT=0$ | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
CORE broken-smt-backend | ||
CORE | ||
main.c | ||
--pointer-check | ||
^EXIT=10$ | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
CORE broken-smt-backend | ||
CORE | ||
main.i | ||
--little-endian | ||
^EXIT=10$ | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
CORE broken-smt-backend | ||
CORE | ||
main.c | ||
--bounds-check --pointer-check | ||
^EXIT=0$ | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
CORE broken-smt-backend | ||
CORE | ||
main.c | ||
--pointer-check | ||
^EXIT=10$ | ||
|
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 |
---|---|---|
@@ -1,8 +1,11 @@ | ||
CORE | ||
CORE broken-smt-backend | ||
main.c | ||
--little-endian | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^VERIFICATION SUCCESSFUL$ | ||
-- | ||
^warning: ignoring | ||
-- | ||
This test reports a VERIFICATION ERROR when running with the SMT2 solver on | ||
Windows only. |
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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
CORE broken-smt-backend | ||
CORE | ||
main.c | ||
|
||
^EXIT=0$ | ||
|
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 |
---|---|---|
|
@@ -12,6 +12,7 @@ Author: Daniel Kroening, [email protected] | |
|
||
#include <util/arith_tools.h> | ||
#include <util/byte_operators.h> | ||
#include <util/expr_util.h> | ||
#include <util/pointer_offset_size.h> | ||
#include <util/std_expr.h> | ||
#include <util/throw_with_nested.h> | ||
|
@@ -40,7 +41,8 @@ bvt map_bv(const bv_endianness_mapt &map, const bvt &src) | |
|
||
bvt boolbvt::convert_byte_extract(const byte_extract_exprt &expr) | ||
{ | ||
// if we extract from an unbounded array, call the flattening code | ||
// array logic does not handle byte operators, thus lower when operating on | ||
// unbounded arrays | ||
if(is_unbounded_array(expr.op().type())) | ||
{ | ||
try | ||
|
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,16 +8,37 @@ Author: Daniel Kroening, [email protected] | |
|
||
#include "boolbv.h" | ||
|
||
#include <iostream> | ||
|
||
#include <util/arith_tools.h> | ||
#include <util/byte_operators.h> | ||
#include <util/expr_util.h> | ||
#include <util/invariant.h> | ||
#include <util/throw_with_nested.h> | ||
|
||
#include <solvers/lowering/expr_lowering.h> | ||
#include <solvers/lowering/flatten_byte_extract_exceptions.h> | ||
|
||
#include "bv_conversion_exceptions.h" | ||
#include "bv_endianness_map.h" | ||
|
||
bvt boolbvt::convert_byte_update(const byte_update_exprt &expr) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the fact that the method can throw an exception should probably be documented |
||
{ | ||
// if we update (from) an unbounded array, lower the expression as the array | ||
// logic does not handle byte operators | ||
if( | ||
is_unbounded_array(expr.op().type()) || | ||
is_unbounded_array(expr.value().type())) | ||
{ | ||
try | ||
{ | ||
return convert_bv(lower_byte_update(expr, ns)); | ||
} | ||
catch(const flatten_byte_extract_exceptiont &byte_extract_flatten_exception) | ||
{ | ||
util_throw_with_nested( | ||
bitvector_conversion_exceptiont("Can't convert byte_update", expr)); | ||
} | ||
} | ||
|
||
const exprt &op = expr.op(); | ||
const exprt &offset_expr=expr.offset(); | ||
const exprt &value=expr.value(); | ||
|
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,8 @@ Author: Daniel Kroening, [email protected] | |
#include <util/simplify_expr.h> | ||
#include <util/std_expr.h> | ||
|
||
#include <solvers/lowering/expr_lowering.h> | ||
|
||
bvt boolbvt::convert_index(const index_exprt &expr) | ||
{ | ||
const exprt &array=expr.array(); | ||
|
@@ -47,7 +49,10 @@ bvt boolbvt::convert_index(const index_exprt &expr) | |
for(std::size_t i=0; i<width; i++) | ||
bv[i]=prop.new_variable(); | ||
|
||
record_array_index(expr); | ||
if(has_byte_operator(expr)) | ||
record_array_index(to_index_expr(lower_byte_operators(expr, ns))); | ||
else | ||
record_array_index(expr); | ||
|
||
// record type if array is a symbol | ||
|
||
|
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 |
---|---|---|
|
@@ -9,9 +9,6 @@ Author: Daniel Kroening, [email protected] | |
#include "boolbv.h" | ||
|
||
#include <util/base_type.h> | ||
#include <util/byte_operators.h> | ||
#include <util/arith_tools.h> | ||
#include <util/c_types.h> | ||
|
||
bvt boolbvt::convert_member(const member_exprt &expr) | ||
{ | ||
|
@@ -20,59 +17,40 @@ bvt boolbvt::convert_member(const member_exprt &expr) | |
|
||
const bvt &struct_bv=convert_bv(struct_op); | ||
|
||
if(struct_op_type.id()==ID_union) | ||
{ | ||
return convert_bv( | ||
byte_extract_exprt(byte_extract_id(), | ||
struct_op, | ||
from_integer(0, index_type()), | ||
expr.type())); | ||
} | ||
else | ||
{ | ||
INVARIANT( | ||
struct_op_type.id() == ID_struct, | ||
"member_exprt should denote access to a union or struct"); | ||
const irep_idt &component_name = expr.get_component_name(); | ||
const struct_union_typet::componentst &components = | ||
to_struct_union_type(struct_op_type).components(); | ||
|
||
const irep_idt &component_name=expr.get_component_name(); | ||
const struct_typet::componentst &components= | ||
to_struct_type(struct_op_type).components(); | ||
std::size_t offset = 0; | ||
|
||
std::size_t offset=0; | ||
for(const auto &c : components) | ||
{ | ||
const typet &subtype = c.type(); | ||
const std::size_t sub_width = boolbv_width(subtype); | ||
|
||
for(const auto &c : components) | ||
if(c.get_name() == component_name) | ||
{ | ||
const typet &subtype = c.type(); | ||
std::size_t sub_width=boolbv_width(subtype); | ||
|
||
if(c.get_name() == component_name) | ||
{ | ||
DATA_INVARIANT_WITH_DIAGNOSTICS( | ||
base_type_eq(subtype, expr.type(), ns), | ||
"struct component type shall match the member expression type", | ||
subtype.pretty(), | ||
expr.type().pretty()); | ||
|
||
bvt bv; | ||
bv.resize(sub_width); | ||
INVARIANT( | ||
offset + sub_width <= struct_bv.size(), | ||
"bitvector part corresponding to struct element shall be contained " | ||
"within the full struct bitvector"); | ||
|
||
for(std::size_t i=0; i<sub_width; i++) | ||
bv[i]=struct_bv[offset+i]; | ||
|
||
return bv; | ||
} | ||
|
||
offset+=sub_width; | ||
DATA_INVARIANT_WITH_DIAGNOSTICS( | ||
base_type_eq(subtype, expr.type(), ns), | ||
"component type shall match the member expression type", | ||
subtype.pretty(), | ||
expr.type().pretty()); | ||
INVARIANT( | ||
offset + sub_width <= struct_bv.size(), | ||
"bitvector part corresponding to element shall be contained within the " | ||
"full aggregate bitvector"); | ||
|
||
return bvt( | ||
struct_bv.begin() + offset, struct_bv.begin() + offset + sub_width); | ||
} | ||
|
||
INVARIANT_WITH_DIAGNOSTICS( | ||
false, | ||
"struct type shall contain component accessed by member expression", | ||
expr.find_source_location(), | ||
id2string(component_name)); | ||
if(struct_op_type.id() != ID_union) | ||
offset += sub_width; | ||
} | ||
|
||
INVARIANT_WITH_DIAGNOSTICS( | ||
false, | ||
"struct type shall contain component accessed by member expression", | ||
expr.find_source_location(), | ||
id2string(component_name)); | ||
} |
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
Oops, something went wrong.
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's the rationale for that, actually?
Is the alternative to always use the flattening code?
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.
The rationale for lowering byte-operators when pointers are involved? Given that there is another commit that does lowering when encountering a pointer I can check whether that's still necessary (without the latter it would certainly lead to an exception)
, it's a matter of whether the SMT back-end now needs this or not(edit: this code is not for SMT).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.
Very good call, this is now unnecessary. Commit (for both byte extract and byte update) and commit message amended.