-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
} | ||
} |
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 |
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; | ||
} |
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 |
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; | ||
} |
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 |
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; | ||
} | ||
} |
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 |
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; | ||
} |
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 | ||
-- |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <assert.h> | ||
#include <stddef.h> | ||
#include <string.h> | ||
|
||
int test(char *string, size_t size) | ||
{ | ||
for(size_t ix = 0; ix + 1 < size; ++ix) | ||
{ | ||
char c = string[ix]; | ||
// characters except the last should fall in printable range | ||
assert(c == '\n' | c == '\r' | c == '\t' | (c >= 32 && c <= 126)); | ||
} | ||
assert(strlen(string) + 1 == size); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
CORE | ||
test.c | ||
--function test --pointers-to-treat-as-string string --associated-array-sizes string:size --pointer-check --unwind 10 | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^VERIFICATION SUCCESSFUL$ | ||
-- |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,13 +22,30 @@ 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):" \ | ||
"(pointers-to-treat-as-string):" | ||
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. Missing help 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.
|
||
|
||
#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 | ||
|
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)