-
Notifications
You must be signed in to change notification settings - Fork 284
Include pointer offset in counterexample output #3135
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
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
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,22 @@ | ||
| #include <assert.h> | ||
|
|
||
| typedef struct | ||
| { | ||
| int inta; | ||
| int intb; | ||
| } struct_t; | ||
|
|
||
| typedef union { | ||
| int intaa; | ||
| struct_t structbb; | ||
| } union_struct_t; | ||
|
|
||
| int main() | ||
| { | ||
| union_struct_t uuu; | ||
| char *ptr = (char *)&uuu.structbb.intb; | ||
| int A[2]; | ||
| int *ip = &A[1]; | ||
| uuu.structbb.intb = 1; | ||
| assert(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,10 @@ | ||
| CORE | ||
| main.c | ||
| --trace | ||
| ^EXIT=10$ | ||
| ^SIGNAL=0$ | ||
| ptr=\(char \*\)&uuu!0@1 \+ 4(l+)? \(.*\)$ | ||
| ip=A!0@1 \+ 1(l+)? \(.*\)$ | ||
| ^VERIFICATION FAILED$ | ||
| -- | ||
| ^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 |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ Author: Daniel Kroening, [email protected] | |
| #include <util/invariant.h> | ||
| #include <util/pointer_offset_size.h> | ||
| #include <util/prefix.h> | ||
| #include <util/simplify_expr.h> | ||
| #include <util/std_expr.h> | ||
|
|
||
| bool pointer_logict::is_dynamic_object(const exprt &expr) const | ||
|
|
@@ -104,29 +105,40 @@ exprt pointer_logict::pointer_expr( | |
| // https://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Pointer-Arith.html | ||
| if(subtype.id() == ID_empty) | ||
| subtype = char_type(); | ||
| const exprt deep_object = | ||
| exprt deep_object = | ||
| get_subexpression_at_offset(object_expr, pointer.offset, subtype, ns); | ||
| CHECK_RETURN(deep_object.is_not_nil()); | ||
| simplify(deep_object, ns); | ||
| if(deep_object.id() != byte_extract_id()) | ||
| return address_of_exprt(deep_object, type); | ||
| return typecast_exprt::conditional_cast( | ||
| address_of_exprt(deep_object), type); | ||
|
|
||
| const byte_extract_exprt &be = to_byte_extract_expr(deep_object); | ||
| const address_of_exprt base(be.op()); | ||
| if(be.offset().is_zero()) | ||
| return address_of_exprt(be.op(), type); | ||
| return typecast_exprt::conditional_cast(base, type); | ||
|
|
||
| const auto subtype_bytes = pointer_offset_size(subtype, ns); | ||
| CHECK_RETURN(subtype_bytes.has_value() && *subtype_bytes > 0); | ||
| if(*subtype_bytes > pointer.offset) | ||
| const auto object_size = pointer_offset_size(be.op().type(), ns); | ||
| if(object_size.has_value() && *object_size <= 1) | ||
| { | ||
| return plus_exprt( | ||
| address_of_exprt(be.op(), pointer_type(char_type())), | ||
| from_integer(pointer.offset, index_type())); | ||
| return typecast_exprt::conditional_cast( | ||
| plus_exprt(base, from_integer(pointer.offset, pointer_diff_type())), | ||
| type); | ||
| } | ||
| else if(object_size.has_value() && pointer.offset % *object_size == 0) | ||
| { | ||
| return typecast_exprt::conditional_cast( | ||
| plus_exprt( | ||
| base, from_integer(pointer.offset / *object_size, pointer_diff_type())), | ||
| type); | ||
| } | ||
| else | ||
| { | ||
| return plus_exprt( | ||
| address_of_exprt(be.op(), pointer_type(char_type())), | ||
| from_integer(pointer.offset / *subtype_bytes, index_type())); | ||
| return typecast_exprt::conditional_cast( | ||
| plus_exprt( | ||
| typecast_exprt(base, pointer_type(char_type())), | ||
| from_integer(pointer.offset, pointer_diff_type())), | ||
| type); | ||
| } | ||
| } | ||
|
|
||
|
|
||
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.
You probably meant pointer.offset / *object_size
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.
Ooops - that clearly shows that my test case is not good enough. Thanks for catching that! I'll extend my test.