-
Notifications
You must be signed in to change notification settings - Fork 274
Feature nondet string initialization [depends-on: #3750] #3572
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
Closed
hannes-steffenhagen-diffblue
wants to merge
2
commits into
diffblue:develop
from
hannes-steffenhagen-diffblue:feature-nondet-string-initialization
Closed
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions
9
regression/cbmc/pointer-to-array-function-parameters-max-size/test.c
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 @@ | ||
#include <assert.h> | ||
void test(int *arr, int sz) | ||
{ | ||
assert(sz <= 10); | ||
for(int i = 0; i < sz; ++i) | ||
{ | ||
arr[i] = 0; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
regression/cbmc/pointer-to-array-function-parameters-max-size/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.c | ||
--function test --pointers-to-treat-as-array arr --max-dynamic-array-size 20 --pointer-check --unwind 20 --associated-array-sizes arr:sz | ||
\[test.assertion.1\] line \d+ assertion sz <= 10: FAILURE | ||
\[test.pointer_dereference.1\] line \d+ dereference failure: pointer NULL in arr\[\(signed long int\)i\]: SUCCESS | ||
\[test.pointer_dereference.2\] line \d+ dereference failure: pointer invalid in arr\[\(signed long int\)i\]: SUCCESS | ||
\[test.pointer_dereference.3\] line \d+ dereference failure: deallocated dynamic object in arr\[\(signed long int\)i\]: SUCCESS | ||
\[test.pointer_dereference.4\] line \d+ dereference failure: dead object in arr\[\(signed long int\)i\]: SUCCESS | ||
\[test.pointer_dereference.5\] line \d+ dereference failure: pointer outside dynamic object bounds in arr\[\(signed long int\)i\]: SUCCESS | ||
\[test.pointer_dereference.6\] line \d+ dereference failure: pointer outside object bounds in arr\[\(signed long int\)i\]: SUCCESS | ||
EXIT=10 | ||
SIGNAL=0 |
22 changes: 22 additions & 0 deletions
22
regression/cbmc/pointer-to-array-function-parameters-multi-arg-right/test.c
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> | ||
|
||
int is_prefix_of( | ||
const char *string, | ||
int string_size, | ||
const char *prefix, | ||
int prefix_size) | ||
{ | ||
if(string_size < prefix_size) | ||
{ | ||
return 0; | ||
} | ||
|
||
for(int ix = 0; ix < prefix_size; ++ix) | ||
{ | ||
if(string[ix] != prefix[ix]) | ||
{ | ||
return 0; | ||
} | ||
} | ||
return 1; | ||
} |
6 changes: 6 additions & 0 deletions
6
regression/cbmc/pointer-to-array-function-parameters-multi-arg-right/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,6 @@ | ||
CORE | ||
test.c | ||
--function is_prefix_of --pointers-to-treat-as-array string,prefix --associated-array-sizes string:string_size,prefix:prefix_size --pointer-check --unwind 20 | ||
SIGNAL=0 | ||
EXIT=0 | ||
VERIFICATION SUCCESSFUL |
24 changes: 24 additions & 0 deletions
24
regression/cbmc/pointer-to-array-function-parameters-multi-arg-wrong/test.c
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,24 @@ | ||
#include <assert.h> | ||
#include <stddef.h> | ||
|
||
int is_prefix_of( | ||
const char *string, | ||
size_t string_size, | ||
const char *prefix, | ||
size_t prefix_size) | ||
{ | ||
if(string_size < prefix_size) | ||
{ | ||
return 0; | ||
} | ||
assert(prefix_size <= string_size); | ||
// oh no! we should have used prefix_size here | ||
for(int ix = 0; ix < string_size; ++ix) | ||
{ | ||
if(string[ix] != prefix[ix]) | ||
{ | ||
return 0; | ||
} | ||
} | ||
return 1; | ||
} |
7 changes: 7 additions & 0 deletions
7
regression/cbmc/pointer-to-array-function-parameters-multi-arg-wrong/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,7 @@ | ||
CORE | ||
test.c | ||
--function is_prefix_of --pointers-to-treat-as-array string,prefix --associated-array-sizes string:string_size,prefix:prefix_size --pointer-check --unwind 10 | ||
EXIT=10 | ||
SIGNAL=0 | ||
\[is_prefix_of.pointer_dereference.\d+\] line \d+ dereference failure: pointer outside dynamic object bounds in prefix\[\(signed long int\)ix\]: FAILURE | ||
VERIFICATION FAILED |
7 changes: 7 additions & 0 deletions
7
regression/cbmc/pointer-to-array-function-parameters-with-size/test.c
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 @@ | ||
void test(int *arr, int sz) | ||
{ | ||
for(int i = 0; i < sz; ++i) | ||
{ | ||
arr[i] = 0; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
regression/cbmc/pointer-to-array-function-parameters-with-size/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,11 @@ | ||
CORE | ||
test.c | ||
--function test --pointers-to-treat-as-array arr --pointer-check --unwind 10 --associated-array-sizes arr:sz | ||
EXIT=0 | ||
SIGNAL=0 | ||
\[test.pointer_dereference.1\] line \d+ dereference failure: pointer NULL in arr\[\(signed long int\)i\]: SUCCESS | ||
\[test.pointer_dereference.2\] line \d+ dereference failure: pointer invalid in arr\[\(signed long int\)i\]: SUCCESS | ||
\[test.pointer_dereference.3\] line \d+ dereference failure: deallocated dynamic object in arr\[\(signed long int\)i\]: SUCCESS | ||
\[test.pointer_dereference.4\] line \d+ dereference failure: dead object in arr\[\(signed long int\)i\]: SUCCESS | ||
\[test.pointer_dereference.5\] line \d+ dereference failure: pointer outside dynamic object bounds in arr\[\(signed long int\)i\]: SUCCESS | ||
\[test.pointer_dereference.6\] line \d+ dereference failure: pointer outside object bounds in arr\[\(signed long int\)i\]: SUCCESS |
10 changes: 10 additions & 0 deletions
10
regression/cbmc/pointer-to-array-function-parameters/test.c
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 @@ | ||
#include <assert.h> | ||
|
||
void test(int *arr) | ||
{ | ||
// works because the arrays we generate have at least one element | ||
arr[0] = 5; | ||
|
||
// doesn't work because our arrays have at most ten elements | ||
arr[10] = 10; | ||
} |
6 changes: 6 additions & 0 deletions
6
regression/cbmc/pointer-to-array-function-parameters/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,6 @@ | ||
CORE | ||
test.c | ||
--function test --pointers-to-treat-as-array arr --pointer-check --unwind 20 | ||
\[test.pointer_dereference.5\] line \d+ dereference failure: pointer outside dynamic object bounds in arr\[\(signed long int\)0\]: SUCCESS | ||
\[test.pointer_dereference.12\] line \d+ dereference failure: pointer outside dynamic object bounds in arr\[\(signed long int\)10\]: FAILURE | ||
-- |
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
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 |
---|---|---|
|
@@ -22,13 +22,29 @@ Author: Daniel Kroening, [email protected] | |
// clang-format off | ||
#define OPT_ANSI_C_LANGUAGE \ | ||
"(max-nondet-tree-depth):" \ | ||
"(min-null-tree-depth):" | ||
"(min-null-tree-depth):" \ | ||
"(pointers-to-treat-as-array):" \ | ||
"(associated-array-sizes):" \ | ||
"(max-dynamic-array-size):" \ | ||
|
||
#define HELP_ANSI_C_LANGUAGE \ | ||
" --max-nondet-tree-depth N limit size of nondet (e.g. input) object tree;\n" /* NOLINT(*) */\ | ||
" at level N pointers are set to null\n" \ | ||
" --min-null-tree-depth N minimum level at which a pointer can first be\n" /* NOLINT(*) */\ | ||
" NULL in a recursively nondet initialized struct\n" /* NOLINT(*) */ | ||
" NULL in a recursively nondet initialized struct\n" /* NOLINT(*) */\ | ||
" --pointers-to-treat-as-array <identifier,...> Comma separated list of\n" \ | ||
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. Nit pick: we seem to start help messages with a lowercase letter. |
||
" identifiers that should be initialized as arrays\n" /* NOLINT(*) */ \ | ||
" --associated-array-sizes <identifier:identifier...>\n" \ | ||
" comma separated list of colon separated pairs\n" /* NOLINT(*) */ \ | ||
" of identifiers; The first should be the name\n" /* NOLINT(*) */ \ | ||
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 first" ... what? |
||
" of an array pointer \n" \ | ||
" (see --pointers-to-treat-as-array),\n" \ | ||
" the second an integer parameter that\n" \ | ||
" should hold its size\n" \ | ||
" --max-dynamic-array-size <size> max size for dynamically allocated arrays\n" /* NOLINT(*) */ \ | ||
" --pointers-to-treat-as-string <identifier,...>\n" \ | ||
" comma separated list of identifiers that\n" \ | ||
" should be treated like C strings\n" | ||
// clang-format on | ||
|
||
class ansi_c_languaget:public languaget | ||
|
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.
pointers-to-treat-as-array
->pointers-to-treat-as-arrays
(and throughout the PR)