@@ -1190,18 +1190,15 @@ void instrument_cover_goals(
1190
1190
const symbol_tablet &symbol_table,
1191
1191
goto_programt &goto_program,
1192
1192
coverage_criteriont criterion,
1193
- message_handlert &message_handler,
1194
- bool function_only)
1193
+ message_handlert &message_handler)
1195
1194
{
1196
1195
coverage_goalst goals; // empty already covered goals
1197
1196
instrument_cover_goals (
1198
1197
symbol_table,
1199
1198
goto_program,
1200
1199
criterion,
1201
1200
message_handler,
1202
- goals,
1203
- function_only,
1204
- false );
1201
+ goals);
1205
1202
}
1206
1203
1207
1204
// / Call a goto_program trivial unless it has: * Any declarations * At least 2
@@ -1235,14 +1232,8 @@ void instrument_cover_goals(
1235
1232
goto_programt &goto_program,
1236
1233
coverage_criteriont criterion,
1237
1234
message_handlert &message_handler,
1238
- coverage_goalst &goals,
1239
- bool function_only,
1240
- bool ignore_trivial)
1235
+ coverage_goalst &goals)
1241
1236
{
1242
- // exclude trivial coverage goals of a goto program
1243
- if (ignore_trivial && program_is_trivial (goto_program))
1244
- return ;
1245
-
1246
1237
// ignore if built-in library
1247
1238
if (!goto_program.instructions .empty () &&
1248
1239
goto_program.instructions .front ().source_location .is_built_in ())
@@ -1259,19 +1250,11 @@ void instrument_cover_goals(
1259
1250
1260
1251
Forall_goto_program_instructions (i_it, goto_program)
1261
1252
{
1262
- std::string curr_function=id2string (i_it->function );
1263
-
1264
- // if the --cover-function-only flag is set, then we only add coverage
1265
- // instrumentation for the entry function
1266
- bool cover_curr_function=
1267
- !function_only ||
1268
- curr_function.find (config.main )!=std::string::npos;
1269
-
1270
1253
switch (criterion)
1271
1254
{
1272
1255
case coverage_criteriont::ASSERTION:
1273
1256
// turn into 'assert(false)' to avoid simplification
1274
- if (i_it->is_assert () && cover_curr_function )
1257
+ if (i_it->is_assert ())
1275
1258
{
1276
1259
i_it->guard =false_exprt ();
1277
1260
i_it->source_location .set (ID_coverage_criterion, coverage_criterion);
@@ -1282,7 +1265,7 @@ void instrument_cover_goals(
1282
1265
1283
1266
case coverage_criteriont::COVER:
1284
1267
// turn __CPROVER_cover(x) into 'assert(!x)'
1285
- if (i_it->is_function_call () && cover_curr_function )
1268
+ if (i_it->is_function_call ())
1286
1269
{
1287
1270
const code_function_callt &code_function_call=
1288
1271
to_code_function_call (i_it->code );
@@ -1324,8 +1307,7 @@ void instrument_cover_goals(
1324
1307
// check whether the current goal already exists
1325
1308
if (!goals.is_existing_goal (source_location) &&
1326
1309
!source_location.get_file ().empty () &&
1327
- !source_location.is_built_in () &&
1328
- cover_curr_function)
1310
+ !source_location.is_built_in ())
1329
1311
{
1330
1312
std::string comment=" block " +b;
1331
1313
const irep_idt function=i_it->function ;
@@ -1348,8 +1330,7 @@ void instrument_cover_goals(
1348
1330
if (i_it->is_assert ())
1349
1331
i_it->make_skip ();
1350
1332
1351
- if (i_it==goto_program.instructions .begin () &&
1352
- cover_curr_function)
1333
+ if (i_it==goto_program.instructions .begin ())
1353
1334
{
1354
1335
// we want branch coverage to imply 'entry point of function'
1355
1336
// coverage
@@ -1367,7 +1348,7 @@ void instrument_cover_goals(
1367
1348
t->function =i_it->function ;
1368
1349
}
1369
1350
1370
- if (i_it->is_goto () && !i_it->guard .is_true () && cover_curr_function &&
1351
+ if (i_it->is_goto () && !i_it->guard .is_true () &&
1371
1352
!i_it->source_location .is_built_in ())
1372
1353
{
1373
1354
std::string b=
@@ -1406,7 +1387,7 @@ void instrument_cover_goals(
1406
1387
i_it->make_skip ();
1407
1388
1408
1389
// Conditions are all atomic predicates in the programs.
1409
- if (cover_curr_function && !i_it->source_location .is_built_in ())
1390
+ if (!i_it->source_location .is_built_in ())
1410
1391
{
1411
1392
const std::set<exprt> conditions=collect_conditions (i_it);
1412
1393
@@ -1448,7 +1429,7 @@ void instrument_cover_goals(
1448
1429
i_it->make_skip ();
1449
1430
1450
1431
// Decisions are maximal Boolean combinations of conditions.
1451
- if (cover_curr_function && !i_it->source_location .is_built_in ())
1432
+ if (!i_it->source_location .is_built_in ())
1452
1433
{
1453
1434
const std::set<exprt> decisions=collect_decisions (i_it);
1454
1435
@@ -1494,7 +1475,7 @@ void instrument_cover_goals(
1494
1475
// 3. Each condition in a decision takes every possible outcome
1495
1476
// 4. Each condition in a decision is shown to independently
1496
1477
// affect the outcome of the decision.
1497
- if (cover_curr_function && !i_it->source_location .is_built_in ())
1478
+ if (!i_it->source_location .is_built_in ())
1498
1479
{
1499
1480
const std::set<exprt> conditions=collect_conditions (i_it);
1500
1481
const std::set<exprt> decisions=collect_decisions (i_it);
@@ -1594,7 +1575,6 @@ void instrument_cover_goals(
1594
1575
coverage_criteriont criterion,
1595
1576
message_handlert &message_handler,
1596
1577
coverage_goalst &goals,
1597
- bool function_only,
1598
1578
bool ignore_trivial,
1599
1579
const std::string &cover_include_pattern)
1600
1580
{
@@ -1604,6 +1584,10 @@ void instrument_cover_goals(
1604
1584
1605
1585
Forall_goto_functions (f_it, goto_functions)
1606
1586
{
1587
+ // exclude trivial coverage goals of a goto program
1588
+ if (ignore_trivial && program_is_trivial (f_it->second .body ))
1589
+ return ;
1590
+
1607
1591
if (f_it->first ==goto_functions.entry_point () ||
1608
1592
f_it->first ==(CPROVER_PREFIX " initialize" ) ||
1609
1593
f_it->second .is_hidden () ||
@@ -1619,18 +1603,15 @@ void instrument_cover_goals(
1619
1603
f_it->second .body ,
1620
1604
criterion,
1621
1605
message_handler,
1622
- goals,
1623
- function_only,
1624
- ignore_trivial);
1606
+ goals);
1625
1607
}
1626
1608
}
1627
1609
1628
1610
void instrument_cover_goals (
1629
1611
const symbol_tablet &symbol_table,
1630
1612
goto_functionst &goto_functions,
1631
1613
coverage_criteriont criterion,
1632
- message_handlert &message_handler,
1633
- bool function_only)
1614
+ message_handlert &message_handler)
1634
1615
{
1635
1616
// empty set of existing goals
1636
1617
coverage_goalst goals;
@@ -1640,7 +1621,6 @@ void instrument_cover_goals(
1640
1621
criterion,
1641
1622
message_handler,
1642
1623
goals,
1643
- function_only,
1644
1624
false ,
1645
1625
" " );
1646
1626
}
@@ -1714,6 +1694,16 @@ bool instrument_cover_goals(
1714
1694
}
1715
1695
}
1716
1696
1697
+ // cover entry point function only
1698
+ std::string cover_include_pattern=cmdline.get_value (" cover-include-pattern" );
1699
+ if (cmdline.isset (" cover-function-only" ))
1700
+ {
1701
+ std::regex special_characters (
1702
+ " \\ .|\\\\ |\\ *|\\ +|\\ ?|\\ {|\\ }|\\ [|\\ ]|\\ (|\\ )|\\ ^|\\ $|\\ |" );
1703
+ cover_include_pattern=
1704
+ std::regex_replace (config.main , special_characters, " \\ $&" );
1705
+ }
1706
+
1717
1707
// check existing test goals
1718
1708
coverage_goalst existing_goals;
1719
1709
if (cmdline.isset (" existing-coverage" ))
@@ -1744,9 +1734,8 @@ bool instrument_cover_goals(
1744
1734
criterion,
1745
1735
message_handler,
1746
1736
existing_goals,
1747
- cmdline.isset (" cover-function-only" ),
1748
1737
cmdline.isset (" no-trivial-tests" ),
1749
- cmdline. get_value ( " cover-include-pattern " ) );
1738
+ cover_include_pattern );
1750
1739
}
1751
1740
1752
1741
// check whether all existing goals match with instrumented goals
0 commit comments