@@ -1055,22 +1055,6 @@ std::set<exprt> collect_decisions(const goto_programt::const_targett t)
1055
1055
return std::set<exprt>();
1056
1056
}
1057
1057
1058
- void instrument_cover_goals (
1059
- const symbol_tablet &symbol_table,
1060
- goto_programt &goto_program,
1061
- coverage_criteriont criterion,
1062
- message_handlert &message_handler,
1063
- bool function_only)
1064
- {
1065
- instrument_cover_goals (
1066
- symbol_table,
1067
- goto_program,
1068
- criterion,
1069
- message_handler,
1070
- function_only,
1071
- false );
1072
- }
1073
-
1074
1058
// / Call a goto_program trivial unless it has: * Any declarations * At least 2
1075
1059
// / branches * At least 5 assignments
1076
1060
// / \par parameters: Program `goto_program`
@@ -1101,14 +1085,8 @@ void instrument_cover_goals(
1101
1085
const symbol_tablet &symbol_table,
1102
1086
goto_programt &goto_program,
1103
1087
coverage_criteriont criterion,
1104
- message_handlert &message_handler,
1105
- bool function_only,
1106
- bool ignore_trivial)
1088
+ message_handlert &message_handler)
1107
1089
{
1108
- // exclude trivial coverage goals of a goto program
1109
- if (ignore_trivial && program_is_trivial (goto_program))
1110
- return ;
1111
-
1112
1090
// ignore if built-in library
1113
1091
if (!goto_program.instructions .empty () &&
1114
1092
goto_program.instructions .front ().source_location .is_built_in ())
@@ -1125,19 +1103,11 @@ void instrument_cover_goals(
1125
1103
1126
1104
Forall_goto_program_instructions (i_it, goto_program)
1127
1105
{
1128
- std::string curr_function=id2string (i_it->function );
1129
-
1130
- // if the --cover-function-only flag is set, then we only add coverage
1131
- // instrumentation for the entry function
1132
- bool cover_curr_function=
1133
- !function_only ||
1134
- curr_function.find (config.main )!=std::string::npos;
1135
-
1136
1106
switch (criterion)
1137
1107
{
1138
1108
case coverage_criteriont::ASSERTION:
1139
1109
// turn into 'assert(false)' to avoid simplification
1140
- if (i_it->is_assert () && cover_curr_function )
1110
+ if (i_it->is_assert ())
1141
1111
{
1142
1112
i_it->guard =false_exprt ();
1143
1113
i_it->source_location .set (ID_coverage_criterion, coverage_criterion);
@@ -1148,7 +1118,7 @@ void instrument_cover_goals(
1148
1118
1149
1119
case coverage_criteriont::COVER:
1150
1120
// turn __CPROVER_cover(x) into 'assert(!x)'
1151
- if (i_it->is_function_call () && cover_curr_function )
1121
+ if (i_it->is_function_call ())
1152
1122
{
1153
1123
const code_function_callt &code_function_call=
1154
1124
to_code_function_call (i_it->code );
@@ -1190,7 +1160,7 @@ void instrument_cover_goals(
1190
1160
// check whether the current goal needs to be covered
1191
1161
if (
1192
1162
!source_location.get_file ().empty () &&
1193
- !source_location.is_built_in () && cover_curr_function )
1163
+ !source_location.is_built_in ())
1194
1164
{
1195
1165
std::string comment=" block " +b;
1196
1166
const irep_idt function=i_it->function ;
@@ -1213,8 +1183,7 @@ void instrument_cover_goals(
1213
1183
if (i_it->is_assert ())
1214
1184
i_it->make_skip ();
1215
1185
1216
- if (i_it==goto_program.instructions .begin () &&
1217
- cover_curr_function)
1186
+ if (i_it == goto_program.instructions .begin ())
1218
1187
{
1219
1188
// we want branch coverage to imply 'entry point of function'
1220
1189
// coverage
@@ -1232,8 +1201,9 @@ void instrument_cover_goals(
1232
1201
t->function =i_it->function ;
1233
1202
}
1234
1203
1235
- if (i_it->is_goto () && !i_it->guard .is_true () && cover_curr_function &&
1236
- !i_it->source_location .is_built_in ())
1204
+ if (
1205
+ i_it->is_goto () && !i_it->guard .is_true () &&
1206
+ !i_it->source_location .is_built_in ())
1237
1207
{
1238
1208
std::string b=
1239
1209
std::to_string (basic_blocks.block_of (i_it)+1 ); // start with 1
@@ -1271,7 +1241,7 @@ void instrument_cover_goals(
1271
1241
i_it->make_skip ();
1272
1242
1273
1243
// Conditions are all atomic predicates in the programs.
1274
- if (cover_curr_function && !i_it->source_location .is_built_in ())
1244
+ if (!i_it->source_location .is_built_in ())
1275
1245
{
1276
1246
const std::set<exprt> conditions=collect_conditions (i_it);
1277
1247
@@ -1313,7 +1283,7 @@ void instrument_cover_goals(
1313
1283
i_it->make_skip ();
1314
1284
1315
1285
// Decisions are maximal Boolean combinations of conditions.
1316
- if (cover_curr_function && !i_it->source_location .is_built_in ())
1286
+ if (!i_it->source_location .is_built_in ())
1317
1287
{
1318
1288
const std::set<exprt> decisions=collect_decisions (i_it);
1319
1289
@@ -1359,7 +1329,7 @@ void instrument_cover_goals(
1359
1329
// 3. Each condition in a decision takes every possible outcome
1360
1330
// 4. Each condition in a decision is shown to independently
1361
1331
// affect the outcome of the decision.
1362
- if (cover_curr_function && !i_it->source_location .is_built_in ())
1332
+ if (!i_it->source_location .is_built_in ())
1363
1333
{
1364
1334
const std::set<exprt> conditions=collect_conditions (i_it);
1365
1335
const std::set<exprt> decisions=collect_decisions (i_it);
@@ -1459,7 +1429,6 @@ void instrument_cover_goals(
1459
1429
goto_functionst &goto_functions,
1460
1430
coverage_criteriont criterion,
1461
1431
message_handlert &message_handler,
1462
- bool function_only,
1463
1432
bool ignore_trivial,
1464
1433
const std::string &cover_include_pattern)
1465
1434
{
@@ -1480,28 +1449,21 @@ void instrument_cover_goals(
1480
1449
continue ;
1481
1450
1482
1451
instrument_cover_goals (
1483
- symbol_table,
1484
- f_it->second .body ,
1485
- criterion,
1486
- message_handler,
1487
- function_only,
1488
- ignore_trivial);
1452
+ symbol_table, f_it->second .body , criterion, message_handler);
1489
1453
}
1490
1454
}
1491
1455
1492
1456
void instrument_cover_goals (
1493
1457
const symbol_tablet &symbol_table,
1494
1458
goto_functionst &goto_functions,
1495
1459
coverage_criteriont criterion,
1496
- message_handlert &message_handler,
1497
- bool function_only)
1460
+ message_handlert &message_handler)
1498
1461
{
1499
1462
instrument_cover_goals (
1500
1463
symbol_table,
1501
1464
goto_functions,
1502
1465
criterion,
1503
1466
message_handler,
1504
- function_only,
1505
1467
false ,
1506
1468
" " );
1507
1469
}
@@ -1575,6 +1537,17 @@ bool instrument_cover_goals(
1575
1537
}
1576
1538
}
1577
1539
1540
+ // cover entry point function only
1541
+ std::string cover_include_pattern =
1542
+ cmdline.get_value (" cover-include-pattern" );
1543
+ if (cmdline.isset (" cover-function-only" ))
1544
+ {
1545
+ std::regex special_characters (
1546
+ " \\ .|\\\\ |\\ *|\\ +|\\ ?|\\ {|\\ }|\\ [|\\ ]|\\ (|\\ )|\\ ^|\\ $|\\ |" );
1547
+ cover_include_pattern =
1548
+ " .*" + std::regex_replace (config.main , special_characters, " \\ $&" ) + " .*" ;
1549
+ }
1550
+
1578
1551
msg.status () << " Instrumenting coverage goals" << messaget::eom;
1579
1552
1580
1553
for (const auto &criterion : criteria)
@@ -1584,9 +1557,8 @@ bool instrument_cover_goals(
1584
1557
goto_functions,
1585
1558
criterion,
1586
1559
message_handler,
1587
- cmdline.isset (" cover-function-only" ),
1588
1560
cmdline.isset (" no-trivial-tests" ),
1589
- cmdline. get_value ( " cover-include-pattern " ) );
1561
+ cover_include_pattern );
1590
1562
}
1591
1563
1592
1564
if (cmdline.isset (" cover-traces-must-terminate" ))
0 commit comments