Skip to content

Instrument strchr to use the string refinement solver #5200

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

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions regression/cbmc/string-refinement-strchr1/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <assert.h>
#include <string.h>

int main()
{
char test[] = "foo";

char *first_o = strchr(test, 'o');
assert(*first_o == test[1]);
assert(*first_o == test[0]);
char *first_t = strchr(test, 't');
assert(*first_t == test[1]);
assert(*first_t == test[0]);
return 0;
}
12 changes: 12 additions & 0 deletions regression/cbmc/string-refinement-strchr1/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CORE broken-smt-backend
test.c
--refine-strings --max-nondet-string-length 10
^EXIT=10$
^SIGNAL=0$
^\[main.assertion.\d+\] line \d+ assertion \*first_o == test\[1\]: SUCCESS$
^\[main.assertion.\d+\] line \d+ assertion \*first_o == test\[0\]: FAILURE$
^\[main.assertion.\d+\] line \d+ assertion \*first_t == test\[1\]: FAILURE$
^\[main.assertion.\d+\] line \d+ assertion \*first_t == test\[0\]: FAILURE$
^VERIFICATION FAILED$
--
^warning: ignoring
13 changes: 13 additions & 0 deletions regression/cbmc/string-refinement-strchr2/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <assert.h>
#include <string.h>

int main()
{
int i;
char *test = i ? "fo\0tis" : "notfoti";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a test for the case when a character can’t be found as well, e.g. in this case 't' may or may not be found depending on i.


char *first_o = strchr(test, 'o');
assert(first_o != NULL);
assert(*first_o == test[0]);
return 0;
}
10 changes: 10 additions & 0 deletions regression/cbmc/string-refinement-strchr2/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CORE broken-smt-backend
test.c
--refine-strings
^EXIT=10$
^SIGNAL=0$
^\[main.assertion.\d+\] line \d+ assertion first_o != (NULL|\(\(void \*\)0\)): SUCCESS$
^\[main.assertion.\d+\] line \d+ assertion \*first_o == test\[0\]: FAILURE$
^VERIFICATION FAILED$
--
^warning: ignoring
12 changes: 10 additions & 2 deletions src/cbmc/cbmc_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,9 @@ void cbmc_parse_optionst::get_command_line_options(optionst &options)
{
options.set_option("refine-strings", true);
options.set_option("string-printable", cmdline.isset("string-printable"));
options.set_option(
"max-nondet-string-length",
cmdline.get_value("max-nondet-string-length"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need a default value as is in jbmc? MAX_CONCRETE_STRING_SIZE - 1

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also note jbmc throws an error if you use this option without --refine-strings

}

if(cmdline.isset("max-node-refinement"))
Expand Down Expand Up @@ -830,8 +833,13 @@ bool cbmc_parse_optionst::process_goto_program(
link_to_library(
goto_model, log.get_message_handler(), cprover_c_library_factory);

if(options.get_bool_option("string-abstraction"))
string_instrumentation(goto_model, log.get_message_handler());
if(
options.get_bool_option("string-abstraction") ||
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I am getting mixed up but I thought the "string-abstraction" options did something very different? Maybe that was in goto-instrument.

options.get_bool_option("refine-strings"))
string_instrumentation(
goto_model,
log.get_message_handler(),
options.get_option("max-nondet-string-length"));

// remove function pointers
log.status() << "Removal of function pointers and virtual functions"
Expand Down
Loading