@@ -196,7 +196,7 @@ void goto_convertt::finish_computed_gotos(goto_programt &goto_program)
196
196
{
197
197
goto_programt::instructiont &i=*g_it;
198
198
dereference_exprt destination = to_dereference_expr (i.code .op0 ());
199
- exprt pointer = destination.op ();
199
+ const exprt pointer = destination.pointer ();
200
200
201
201
// remember the expression for later checks
202
202
i.type =OTHER;
@@ -303,11 +303,6 @@ void goto_convertt::convert_label(
303
303
goto_programt &dest,
304
304
const irep_idt &mode)
305
305
{
306
- DATA_INVARIANT (
307
- code.operands ().size () == 1 ,
308
- code.find_source_location ().as_string () +
309
- " : label statement expected to have one operand" );
310
-
311
306
// grab the label
312
307
const irep_idt &label=code.get_label ();
313
308
@@ -320,8 +315,8 @@ void goto_convertt::convert_label(
320
315
{
321
316
// the body of the thread is expected to be
322
317
// in the operand.
323
- INVARIANT (code. op0 (). is_not_nil (),
324
- " op0 in magic thread creation label is null" );
318
+ DATA_INVARIANT (
319
+ code. op0 (). is_not_nil (), " op0 in magic thread creation label is null" );
325
320
326
321
// replace the magic thread creation label with a
327
322
// thread block (START_THREAD...END_THREAD).
@@ -386,18 +381,18 @@ void goto_convertt::convert_gcc_switch_case_range(
386
381
goto_programt &dest,
387
382
const irep_idt &mode)
388
383
{
389
- DATA_INVARIANT (
384
+ INVARIANT_WITH_DIAGNOSTICS (
390
385
code.operands ().size () == 3 ,
391
- code. find_source_location (). as_string () +
392
- " : GCC's switch-case-range statement expected to have three operands " );
386
+ " GCC's switch-case-range statement expected to have three operands " ,
387
+ code. find_source_location () );
393
388
394
389
const auto lb = numeric_cast<mp_integer>(code.op0 ());
395
390
const auto ub = numeric_cast<mp_integer>(code.op1 ());
396
391
397
- DATA_INVARIANT (
392
+ INVARIANT_WITH_DIAGNOSTICS (
398
393
lb.has_value () && ub.has_value (),
399
- code. find_source_location (). as_string () +
400
- " : GCC's switch-case-range statement requires constant bounds " );
394
+ " GCC's switch-case-range statement requires constant bounds " ,
395
+ code. find_source_location () );
401
396
402
397
if (*lb > *ub)
403
398
{
@@ -513,10 +508,10 @@ void goto_convertt::convert(
513
508
exprt assertion=code.op0 ();
514
509
assertion.make_typecast (bool_typet ());
515
510
simplify (assertion, ns);
516
- INVARIANT (
511
+ INVARIANT_WITH_DIAGNOSTICS (
517
512
!assertion.is_false (),
518
- code. op0 (). find_source_location (). as_string () + " : static assertion " +
519
- id2string ( get_string_constant ( code.op1 ()) ));
513
+ " static assertion " + id2string ( get_string_constant (code. op1 ())),
514
+ code.op0 (). find_source_location ( ));
520
515
}
521
516
else if (statement==ID_dead)
522
517
copy (code, DEAD, dest);
@@ -689,10 +684,10 @@ void goto_convertt::convert_assign(
689
684
if (rhs.id ()==ID_side_effect &&
690
685
rhs.get (ID_statement)==ID_function_call)
691
686
{
692
- INVARIANT (
687
+ INVARIANT_WITH_DIAGNOSTICS (
693
688
rhs.operands ().size () == 2 ,
694
- rhs. find_source_location (). as_string () +
695
- " : function_call sideeffect takes two operands " );
689
+ " function_call sideeffect takes two operands " ,
690
+ rhs. find_source_location () );
696
691
697
692
Forall_operands (it, rhs)
698
693
clean_expr (*it, dest, mode);
@@ -781,10 +776,10 @@ void goto_convertt::convert_init(
781
776
goto_programt &dest,
782
777
const irep_idt &mode)
783
778
{
784
- INVARIANT (
779
+ INVARIANT_WITH_DIAGNOSTICS (
785
780
code.operands ().size () == 2 ,
786
- code. find_source_location (). as_string () +
787
- " : init statement takes two operands " );
781
+ " init statement takes two operands " ,
782
+ code. find_source_location () );
788
783
789
784
// make it an assignment
790
785
codet assignment=code;
@@ -797,10 +792,10 @@ void goto_convertt::convert_cpp_delete(
797
792
const codet &code,
798
793
goto_programt &dest)
799
794
{
800
- DATA_INVARIANT (
795
+ INVARIANT_WITH_DIAGNOSTICS (
801
796
code.operands ().size () == 1 ,
802
- code. find_source_location (). as_string () +
803
- " : cpp_delete statement takes one operand " );
797
+ " cpp_delete statement takes one operand " ,
798
+ code. find_source_location () );
804
799
805
800
exprt tmp_op=code.op0 ();
806
801
@@ -909,10 +904,10 @@ void goto_convertt::convert_loop_invariant(
909
904
goto_programt no_sideeffects;
910
905
clean_expr (invariant, no_sideeffects, mode);
911
906
912
- INVARIANT (
907
+ INVARIANT_WITH_DIAGNOSTICS (
913
908
no_sideeffects.instructions .empty (),
914
- code. find_source_location (). as_string () +
915
- " : loop invariant is not side-effect free " );
909
+ " loop invariant is not side-effect free " ,
910
+ code. find_source_location () );
916
911
917
912
PRECONDITION (loop->is_goto ());
918
913
loop->guard .add (ID_C_spec_loop_invariant).swap (invariant);
@@ -1084,9 +1079,10 @@ void goto_convertt::convert_dowhile(
1084
1079
goto_programt &dest,
1085
1080
const irep_idt &mode)
1086
1081
{
1087
- INVARIANT (
1082
+ INVARIANT_WITH_DIAGNOSTICS (
1088
1083
code.operands ().size () == 2 ,
1089
- code.find_source_location ().as_string () + " : dowhile takes two operands" );
1084
+ " dowhile takes two operands" ,
1085
+ code.find_source_location ());
1090
1086
1091
1087
// save source location
1092
1088
source_locationt condition_location=code.cond ().find_source_location ();
@@ -1253,9 +1249,7 @@ void goto_convertt::convert_switch(
1253
1249
{
1254
1250
const caset &case_ops=case_pair.second ;
1255
1251
1256
- if (case_ops.empty ())
1257
- throw incorrect_goto_program_exceptiont (
1258
- " switch case range cannot be empty" , code.find_source_location ());
1252
+ assert (!case_ops.empty ());
1259
1253
1260
1254
exprt guard_expr=case_guard (argument, case_ops);
1261
1255
@@ -1290,9 +1284,8 @@ void goto_convertt::convert_break(
1290
1284
goto_programt &dest,
1291
1285
const irep_idt &mode)
1292
1286
{
1293
- DATA_INVARIANT (
1294
- targets.break_set ,
1295
- code.find_source_location ().as_string () + " : break without target" );
1287
+ INVARIANT_WITH_DIAGNOSTICS (
1288
+ targets.break_set , " break without target" , code.find_source_location ());
1296
1289
1297
1290
// need to process destructor stack
1298
1291
unwind_destructor_stack (
@@ -1315,10 +1308,10 @@ void goto_convertt::convert_return(
1315
1308
" return without target" , code.find_source_location ());
1316
1309
}
1317
1310
1318
- DATA_INVARIANT (
1311
+ INVARIANT_WITH_DIAGNOSTICS (
1319
1312
code.operands ().empty () || code.operands ().size () == 1 ,
1320
- code. find_source_location (). as_string () +
1321
- " : return takes none or one operand " );
1313
+ " return takes none or one operand " ,
1314
+ code. find_source_location () );
1322
1315
1323
1316
code_returnt new_code (code);
1324
1317
@@ -1338,10 +1331,10 @@ void goto_convertt::convert_return(
1338
1331
1339
1332
if (targets.has_return_value )
1340
1333
{
1341
- INVARIANT (
1334
+ INVARIANT_WITH_DIAGNOSTICS (
1342
1335
new_code.has_return_value (),
1343
- new_code. find_source_location (). as_string () +
1344
- " : function must return value " );
1336
+ " function must return value " ,
1337
+ new_code. find_source_location () );
1345
1338
1346
1339
// Now add a return node to set the return value.
1347
1340
goto_programt::targett t=dest.add_instruction ();
@@ -1351,11 +1344,11 @@ void goto_convertt::convert_return(
1351
1344
}
1352
1345
else
1353
1346
{
1354
- INVARIANT (
1347
+ INVARIANT_WITH_DIAGNOSTICS (
1355
1348
!new_code.has_return_value () ||
1356
1349
new_code.return_value ().type ().id () == ID_empty,
1357
- code. find_source_location (). as_string () +
1358
- " : function must not return value " );
1350
+ " function must not return value " ,
1351
+ code. find_source_location () );
1359
1352
}
1360
1353
1361
1354
// Need to process _entire_ destructor stack.
@@ -1372,9 +1365,10 @@ void goto_convertt::convert_continue(
1372
1365
goto_programt &dest,
1373
1366
const irep_idt &mode)
1374
1367
{
1375
- DATA_INVARIANT (
1368
+ INVARIANT_WITH_DIAGNOSTICS (
1376
1369
targets.continue_set ,
1377
- code.find_source_location ().as_string () + " : continue without target" );
1370
+ " continue without target" ,
1371
+ code.find_source_location ());
1378
1372
1379
1373
// need to process destructor stack
1380
1374
unwind_destructor_stack (
@@ -1428,10 +1422,10 @@ void goto_convertt::convert_end_thread(
1428
1422
const codet &code,
1429
1423
goto_programt &dest)
1430
1424
{
1431
- DATA_INVARIANT (
1425
+ INVARIANT_WITH_DIAGNOSTICS (
1432
1426
code.operands ().empty (),
1433
- code. find_source_location (). as_string () +
1434
- " : end_thread expects no operands " );
1427
+ " end_thread expects no operands " ,
1428
+ code. find_source_location () );
1435
1429
1436
1430
copy (code, END_THREAD, dest);
1437
1431
}
@@ -1440,10 +1434,10 @@ void goto_convertt::convert_atomic_begin(
1440
1434
const codet &code,
1441
1435
goto_programt &dest)
1442
1436
{
1443
- DATA_INVARIANT (
1437
+ INVARIANT_WITH_DIAGNOSTICS (
1444
1438
code.operands ().empty (),
1445
- code. find_source_location (). as_string () +
1446
- " : atomic_begin expects no operands " );
1439
+ " atomic_begin expects no operands " ,
1440
+ code. find_source_location () );
1447
1441
1448
1442
copy (code, ATOMIC_BEGIN, dest);
1449
1443
}
@@ -1452,10 +1446,10 @@ void goto_convertt::convert_atomic_end(
1452
1446
const codet &code,
1453
1447
goto_programt &dest)
1454
1448
{
1455
- DATA_INVARIANT (
1449
+ INVARIANT_WITH_DIAGNOSTICS (
1456
1450
code.operands ().empty (),
1457
- code. find_source_location (). as_string () +
1458
- " : atomic_end expects no operands " );
1451
+ " : atomic_end expects no operands " ,
1452
+ code. find_source_location () );
1459
1453
1460
1454
copy (code, ATOMIC_END, dest);
1461
1455
}
@@ -1465,11 +1459,6 @@ void goto_convertt::convert_ifthenelse(
1465
1459
goto_programt &dest,
1466
1460
const irep_idt &mode)
1467
1461
{
1468
- DATA_INVARIANT (
1469
- code.operands ().size () == 3 ,
1470
- code.find_source_location ().as_string () +
1471
- " : ifthenelse takes three operands" );
1472
-
1473
1462
DATA_INVARIANT (code.then_case ().is_not_nil (), " cannot accept an empty body" );
1474
1463
1475
1464
bool has_else=
@@ -1865,10 +1854,11 @@ irep_idt goto_convertt::get_string_constant(const exprt &expr)
1865
1854
{
1866
1855
irep_idt result;
1867
1856
1868
- bool res = get_string_constant (expr, result);
1857
+ const bool res = get_string_constant (expr, result);
1869
1858
INVARIANT_WITH_DIAGNOSTICS (
1870
1859
!res,
1871
- expr.find_source_location ().as_string () + " : expected string constant" ,
1860
+ " expected string constant" ,
1861
+ expr.find_source_location (),
1872
1862
expr.pretty ());
1873
1863
1874
1864
return result;
0 commit comments