Skip to content

Commit bab30f9

Browse files
author
Daniel Kroening
authored
Merge pull request #292 from peterschrammel/do-not-instrument-built-ins
Do not instrument built-ins
2 parents b321b4a + 12d6582 commit bab30f9

File tree

15 files changed

+190
-3
lines changed

15 files changed

+190
-3
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
int main()
2+
{
3+
char a[10];
4+
__CPROVER_input("a[3]", a[3]);
5+
6+
int len = strlen(a);
7+
8+
if(len==3)
9+
{
10+
return 0;
11+
}
12+
else if(len==4)
13+
{
14+
return -1;
15+
}
16+
return 1;
17+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
--cover location --unwind 1
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^\*\* 4 of 7 covered
7+
--
8+
^warning: ignoring
9+
^\[.*<builtin-library-
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
struct mystruct {
2+
int x;
3+
char y;
4+
};
5+
6+
int main()
7+
{
8+
struct mystruct s;
9+
char c;
10+
__CPROVER_input("c", c);
11+
12+
memset(&s,c,sizeof(struct mystruct));
13+
14+
if(s.y=='A')
15+
{
16+
return 0;
17+
}
18+
return 1;
19+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
--cover location --unwind 10
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^\*\* 4 of 4 covered
7+
--
8+
^warning: ignoring
9+
^\[.*<builtin-library-
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <stdio.h>
2+
3+
int main()
4+
{
5+
const char *s="test";
6+
int ret=puts(s); //return value is nondet (internal to built-in, thus non-controllable)
7+
8+
if(ret<0)
9+
{
10+
return 1;
11+
}
12+
13+
return 0;
14+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
--cover location --unwind 10
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^\*\* 4 of 4 covered
7+
--
8+
^warning: ignoring
9+
^\[.*<builtin-library-
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
int main()
2+
{
3+
char a[10];
4+
__CPROVER_input("a[3]", a[3]);
5+
6+
int len = strlen(a);
7+
8+
if(len==3)
9+
{
10+
return 0;
11+
}
12+
else if(len==4)
13+
{
14+
return -1;
15+
}
16+
return 1;
17+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
--cover branch --unwind 5
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^\*\* 5 of 5 covered
7+
--
8+
^warning: ignoring
9+
^\[.*<builtin-library-
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
int main()
2+
{
3+
char a[10];
4+
__CPROVER_input("a[3]", a[3]);
5+
6+
int len = strlen(a);
7+
8+
if(len==3)
9+
{
10+
return 0;
11+
}
12+
else if(len==4)
13+
{
14+
return -1;
15+
}
16+
return 1;
17+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
--cover condition --unwind 5
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^\*\* 4 of 4 covered
7+
--
8+
^warning: ignoring
9+
^\[.*<builtin-library-
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
int main()
2+
{
3+
char a[10];
4+
__CPROVER_input("a[3]", a[3]);
5+
6+
int len = strlen(a);
7+
8+
if(len==3)
9+
{
10+
return 0;
11+
}
12+
else if(len==4)
13+
{
14+
return -1;
15+
}
16+
return 1;
17+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
--cover decision --unwind 5
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^\*\* 4 of 4 covered
7+
--
8+
^warning: ignoring
9+
^\[.*<builtin-library-
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
int main()
2+
{
3+
char a[10];
4+
__CPROVER_input("a[3]", a[3]);
5+
6+
int len = strlen(a);
7+
8+
if(len==3)
9+
{
10+
return 0;
11+
}
12+
else if(len==4)
13+
{
14+
return -1;
15+
}
16+
return 1;
17+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
main.c
3+
--cover mcdc --unwind 5
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^\*\* 4 of 4 covered
7+
--
8+
^warning: ignoring
9+
^\[.*<builtin-library-

src/goto-instrument/cover.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,7 @@ Function: eval_expr
685685
the atomic expr values
686686
687687
\*******************************************************************/
688+
688689
bool eval_expr(
689690
const std::map<exprt, signed> &atomic_exprs,
690691
const exprt &src)
@@ -1142,7 +1143,7 @@ void instrument_cover_goals(
11421143
basic_blocks.source_location_map[block_nr];
11431144

11441145
if(!source_location.get_file().empty() &&
1145-
source_location.get_file()[0]!='<')
1146+
!source_location.is_built_in())
11461147
{
11471148
std::string comment="block "+b;
11481149
goto_program.insert_before_swap(i_it);
@@ -1180,7 +1181,8 @@ void instrument_cover_goals(
11801181
t->source_location.set_property_class(property_class);
11811182
}
11821183

1183-
if(i_it->is_goto() && !i_it->guard.is_true())
1184+
if(i_it->is_goto() && !i_it->guard.is_true() &&
1185+
!i_it->source_location.is_built_in())
11841186
{
11851187
std::string b=std::to_string(basic_blocks[i_it]);
11861188
std::string true_comment=
@@ -1215,6 +1217,7 @@ void instrument_cover_goals(
12151217
i_it->make_skip();
12161218

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

@@ -1251,6 +1254,7 @@ void instrument_cover_goals(
12511254
i_it->make_skip();
12521255

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

@@ -1291,6 +1295,7 @@ void instrument_cover_goals(
12911295
// 3. Each condition in a decision takes every possible outcome
12921296
// 4. Each condition in a decision is shown to independently
12931297
// affect the outcome of the decision.
1298+
if(!i_it->source_location.is_built_in())
12941299
{
12951300
const std::set<exprt> conditions=collect_conditions(i_it);
12961301
const std::set<exprt> decisions=collect_decisions(i_it);
@@ -1393,7 +1398,8 @@ void instrument_cover_goals(
13931398
Forall_goto_functions(f_it, goto_functions)
13941399
{
13951400
if(f_it->first==goto_functions.entry_point() ||
1396-
f_it->first=="__CPROVER_initialize")
1401+
f_it->first=="__CPROVER_initialize" ||
1402+
f_it->second.is_hidden())
13971403
continue;
13981404

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

0 commit comments

Comments
 (0)