Skip to content

Do not instrument built-ins #292

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 2 commits into from
May 12, 2017
Merged
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
17 changes: 17 additions & 0 deletions regression/cbmc-cover/built-ins1/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
int main()
{
char a[10];
__CPROVER_input("a[3]", a[3]);

int len = strlen(a);

if(len==3)
{
return 0;
}
else if(len==4)
{
return -1;
}
return 1;
}
9 changes: 9 additions & 0 deletions regression/cbmc-cover/built-ins1/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
main.c
--cover location --unwind 1
^EXIT=0$
^SIGNAL=0$
^\*\* 4 of 7 covered
--
^warning: ignoring
^\[.*<builtin-library-
19 changes: 19 additions & 0 deletions regression/cbmc-cover/built-ins2/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
struct mystruct {
int x;
char y;
};

int main()
{
struct mystruct s;
char c;
__CPROVER_input("c", c);

memset(&s,c,sizeof(struct mystruct));

if(s.y=='A')
{
return 0;
}
return 1;
}
9 changes: 9 additions & 0 deletions regression/cbmc-cover/built-ins2/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
main.c
--cover location --unwind 10
^EXIT=0$
^SIGNAL=0$
^\*\* 4 of 4 covered
--
^warning: ignoring
^\[.*<builtin-library-
14 changes: 14 additions & 0 deletions regression/cbmc-cover/built-ins3/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <stdio.h>

int main()
{
const char *s="test";
int ret=puts(s); //return value is nondet (internal to built-in, thus non-controllable)

if(ret<0)
{
return 1;
}

return 0;
}
9 changes: 9 additions & 0 deletions regression/cbmc-cover/built-ins3/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
main.c
--cover location --unwind 10
^EXIT=0$
^SIGNAL=0$
^\*\* 4 of 4 covered
--
^warning: ignoring
^\[.*<builtin-library-
17 changes: 17 additions & 0 deletions regression/cbmc-cover/built-ins4/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
int main()
{
char a[10];
__CPROVER_input("a[3]", a[3]);

int len = strlen(a);

if(len==3)
{
return 0;
}
else if(len==4)
{
return -1;
}
return 1;
}
9 changes: 9 additions & 0 deletions regression/cbmc-cover/built-ins4/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
main.c
--cover branch --unwind 5
^EXIT=0$
^SIGNAL=0$
^\*\* 5 of 5 covered
--
^warning: ignoring
^\[.*<builtin-library-
17 changes: 17 additions & 0 deletions regression/cbmc-cover/built-ins5/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
int main()
{
char a[10];
__CPROVER_input("a[3]", a[3]);

int len = strlen(a);

if(len==3)
{
return 0;
}
else if(len==4)
{
return -1;
}
return 1;
}
9 changes: 9 additions & 0 deletions regression/cbmc-cover/built-ins5/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
main.c
--cover condition --unwind 5
^EXIT=0$
^SIGNAL=0$
^\*\* 4 of 4 covered
--
^warning: ignoring
^\[.*<builtin-library-
17 changes: 17 additions & 0 deletions regression/cbmc-cover/built-ins6/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
int main()
{
char a[10];
__CPROVER_input("a[3]", a[3]);

int len = strlen(a);

if(len==3)
{
return 0;
}
else if(len==4)
{
return -1;
}
return 1;
}
9 changes: 9 additions & 0 deletions regression/cbmc-cover/built-ins6/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
main.c
--cover decision --unwind 5
^EXIT=0$
^SIGNAL=0$
^\*\* 4 of 4 covered
--
^warning: ignoring
^\[.*<builtin-library-
17 changes: 17 additions & 0 deletions regression/cbmc-cover/built-ins7/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
int main()
{
char a[10];
__CPROVER_input("a[3]", a[3]);

int len = strlen(a);

if(len==3)
{
return 0;
}
else if(len==4)
{
return -1;
}
return 1;
}
9 changes: 9 additions & 0 deletions regression/cbmc-cover/built-ins7/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
main.c
--cover mcdc --unwind 5
^EXIT=0$
^SIGNAL=0$
^\*\* 4 of 4 covered
--
^warning: ignoring
^\[.*<builtin-library-
12 changes: 9 additions & 3 deletions src/goto-instrument/cover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,7 @@ Function: eval_expr
the atomic expr values

\*******************************************************************/

bool eval_expr(
const std::map<exprt, signed> &atomic_exprs,
const exprt &src)
Expand Down Expand Up @@ -1141,7 +1142,7 @@ void instrument_cover_goals(
basic_blocks.source_location_map[block_nr];

if(!source_location.get_file().empty() &&
source_location.get_file()[0]!='<')
!source_location.is_built_in())
{
std::string comment="block "+b;
goto_program.insert_before_swap(i_it);
Expand Down Expand Up @@ -1179,7 +1180,8 @@ void instrument_cover_goals(
t->source_location.set_property_class(property_class);
}

if(i_it->is_goto() && !i_it->guard.is_true())
if(i_it->is_goto() && !i_it->guard.is_true() &&
!i_it->source_location.is_built_in())
{
std::string b=std::to_string(basic_blocks[i_it]);
std::string true_comment=
Expand Down Expand Up @@ -1214,6 +1216,7 @@ void instrument_cover_goals(
i_it->make_skip();

// Conditions are all atomic predicates in the programs.
if(!i_it->source_location.is_built_in())
{
const std::set<exprt> conditions=collect_conditions(i_it);

Expand Down Expand Up @@ -1250,6 +1253,7 @@ void instrument_cover_goals(
i_it->make_skip();

// Decisions are maximal Boolean combinations of conditions.
if(!i_it->source_location.is_built_in())
{
const std::set<exprt> decisions=collect_decisions(i_it);

Expand Down Expand Up @@ -1290,6 +1294,7 @@ void instrument_cover_goals(
// 3. Each condition in a decision takes every possible outcome
// 4. Each condition in a decision is shown to independently
// affect the outcome of the decision.
if(!i_it->source_location.is_built_in())
{
const std::set<exprt> conditions=collect_conditions(i_it);
const std::set<exprt> decisions=collect_decisions(i_it);
Expand Down Expand Up @@ -1392,7 +1397,8 @@ void instrument_cover_goals(
Forall_goto_functions(f_it, goto_functions)
{
if(f_it->first==goto_functions.entry_point() ||
f_it->first=="__CPROVER_initialize")
f_it->first=="__CPROVER_initialize" ||
f_it->second.is_hidden())
continue;

instrument_cover_goals(symbol_table, f_it->second.body, criterion);
Expand Down