-
Notifications
You must be signed in to change notification settings - Fork 278
Simplify byte_extract(constant, o, t) when sizeof(t) < sizeof(constant) #3974
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
tautschnig
merged 1 commit into
diffblue:develop
from
tautschnig:simplify-byte-extract-ext
Jan 30, 2019
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,51 @@ | ||
#include <assert.h> | ||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
void sort_items_by_criteria(int *item, int left, int right) | ||
{ | ||
int lidx = left, ridx = (left + right) / 2 + 1, | ||
lsize = (left + right) / 2 - left + 1; | ||
int tmp; | ||
|
||
if(right - left < 1) | ||
return; | ||
sort_items_by_criteria(item, left, (left + right) / 2); | ||
sort_items_by_criteria(item, (left + right) / 2 + 1, right); | ||
|
||
while(ridx <= right && lidx < ridx) | ||
{ | ||
if(item[lidx] > item[ridx]) | ||
{ | ||
tmp = item[ridx]; | ||
memmove(item + lidx + 1, item + lidx, lsize * sizeof(int)); | ||
item[lidx] = tmp; | ||
++ridx; | ||
++lsize; | ||
} | ||
++lidx; | ||
--lsize; | ||
} | ||
} | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
int a[7] = {0}; | ||
|
||
// CBMC in some past version reported wrong results for 256, -2147221455, | ||
// -2147221455, -2147221455, 16, -2147483600, 16384 | ||
a[0] = 256; | ||
a[1] = -2147221455; | ||
a[2] = -2147221455; | ||
a[3] = -2147221455; | ||
a[4] = 16; | ||
a[5] = -2147483600; | ||
a[6] = 16384; | ||
|
||
sort_items_by_criteria(a, 0, 6); | ||
|
||
printf("%d %d %d %d %d %d %d\n", a[0], a[1], a[2], a[3], a[4], a[5], a[6]); | ||
|
||
assert(a[0] == -2147483600); | ||
return 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,9 @@ | ||
CORE | ||
constant.c | ||
--unwind 17 | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^VERIFICATION SUCCESSFUL$ | ||
^Generated \d+ VCC\(s\), 0 remaining after simplification$ | ||
-- | ||
^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
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
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.
⛏ Might be worth factoring that out into a utility to avoid someone recoding that at the next occasion...
Uh oh!
There was an error while loading. Please reload this page.
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'll in this case not follow the advice for two reasons: 1) This is an over-approximating check, even
struct_has_flexible_array_member == true
need not mean that there genuinely are flexible array members (which is ok in this context, it just mean we don't simplify although we possibly could); 2) I haven't found any other bits of the code outside the C type checker that currently try to deal with this special case. Should a need for that arise, of course, we should refactor. I hope that's ok!