Skip to content

Commit 9a6e16f

Browse files
committed
Change data_invariants to invariants_with_diagnostics
Change some data_invariants to invariants_with_diagnostics where they are more appropriate, and remove some duplicate invariants, where they are guaranteed by construction of the types themselves.
1 parent 031c9f9 commit 9a6e16f

File tree

1 file changed

+52
-60
lines changed

1 file changed

+52
-60
lines changed

src/goto-programs/goto_convert.cpp

Lines changed: 52 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ void goto_convertt::finish_computed_gotos(goto_programt &goto_program)
196196
{
197197
goto_programt::instructiont &i=*g_it;
198198
dereference_exprt destination = to_dereference_expr(i.code.op0());
199-
exprt pointer = destination.op();
199+
const exprt pointer = destination.pointer();
200200

201201
// remember the expression for later checks
202202
i.type=OTHER;
@@ -303,11 +303,6 @@ void goto_convertt::convert_label(
303303
goto_programt &dest,
304304
const irep_idt &mode)
305305
{
306-
DATA_INVARIANT(
307-
code.operands().size() == 1,
308-
code.find_source_location().as_string() +
309-
": label statement expected to have one operand");
310-
311306
// grab the label
312307
const irep_idt &label=code.get_label();
313308

@@ -320,8 +315,8 @@ void goto_convertt::convert_label(
320315
{
321316
// the body of the thread is expected to be
322317
// 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");
325320

326321
// replace the magic thread creation label with a
327322
// thread block (START_THREAD...END_THREAD).
@@ -386,18 +381,18 @@ void goto_convertt::convert_gcc_switch_case_range(
386381
goto_programt &dest,
387382
const irep_idt &mode)
388383
{
389-
DATA_INVARIANT(
384+
INVARIANT_WITH_DIAGNOSTICS(
390385
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());
393388

394389
const auto lb = numeric_cast<mp_integer>(code.op0());
395390
const auto ub = numeric_cast<mp_integer>(code.op1());
396391

397-
DATA_INVARIANT(
392+
INVARIANT_WITH_DIAGNOSTICS(
398393
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());
401396

402397
if(*lb > *ub)
403398
{
@@ -513,10 +508,10 @@ void goto_convertt::convert(
513508
exprt assertion=code.op0();
514509
assertion.make_typecast(bool_typet());
515510
simplify(assertion, ns);
516-
INVARIANT(
511+
INVARIANT_WITH_DIAGNOSTICS(
517512
!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());
520515
}
521516
else if(statement==ID_dead)
522517
copy(code, DEAD, dest);
@@ -689,10 +684,10 @@ void goto_convertt::convert_assign(
689684
if(rhs.id()==ID_side_effect &&
690685
rhs.get(ID_statement)==ID_function_call)
691686
{
692-
INVARIANT(
687+
INVARIANT_WITH_DIAGNOSTICS(
693688
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());
696691

697692
Forall_operands(it, rhs)
698693
clean_expr(*it, dest, mode);
@@ -781,10 +776,10 @@ void goto_convertt::convert_init(
781776
goto_programt &dest,
782777
const irep_idt &mode)
783778
{
784-
INVARIANT(
779+
INVARIANT_WITH_DIAGNOSTICS(
785780
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());
788783

789784
// make it an assignment
790785
codet assignment=code;
@@ -797,10 +792,10 @@ void goto_convertt::convert_cpp_delete(
797792
const codet &code,
798793
goto_programt &dest)
799794
{
800-
DATA_INVARIANT(
795+
INVARIANT_WITH_DIAGNOSTICS(
801796
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());
804799

805800
exprt tmp_op=code.op0();
806801

@@ -909,10 +904,10 @@ void goto_convertt::convert_loop_invariant(
909904
goto_programt no_sideeffects;
910905
clean_expr(invariant, no_sideeffects, mode);
911906

912-
INVARIANT(
907+
INVARIANT_WITH_DIAGNOSTICS(
913908
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());
916911

917912
PRECONDITION(loop->is_goto());
918913
loop->guard.add(ID_C_spec_loop_invariant).swap(invariant);
@@ -1084,9 +1079,10 @@ void goto_convertt::convert_dowhile(
10841079
goto_programt &dest,
10851080
const irep_idt &mode)
10861081
{
1087-
INVARIANT(
1082+
INVARIANT_WITH_DIAGNOSTICS(
10881083
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());
10901086

10911087
// save source location
10921088
source_locationt condition_location=code.cond().find_source_location();
@@ -1290,9 +1286,8 @@ void goto_convertt::convert_break(
12901286
goto_programt &dest,
12911287
const irep_idt &mode)
12921288
{
1293-
DATA_INVARIANT(
1294-
targets.break_set,
1295-
code.find_source_location().as_string() + ": break without target");
1289+
INVARIANT_WITH_DIAGNOSTICS(
1290+
targets.break_set, "break without target", code.find_source_location());
12961291

12971292
// need to process destructor stack
12981293
unwind_destructor_stack(
@@ -1315,10 +1310,10 @@ void goto_convertt::convert_return(
13151310
"return without target", code.find_source_location());
13161311
}
13171312

1318-
DATA_INVARIANT(
1313+
INVARIANT_WITH_DIAGNOSTICS(
13191314
code.operands().empty() || code.operands().size() == 1,
1320-
code.find_source_location().as_string() +
1321-
": return takes none or one operand");
1315+
"return takes none or one operand",
1316+
code.find_source_location());
13221317

13231318
code_returnt new_code(code);
13241319

@@ -1338,10 +1333,10 @@ void goto_convertt::convert_return(
13381333

13391334
if(targets.has_return_value)
13401335
{
1341-
INVARIANT(
1336+
INVARIANT_WITH_DIAGNOSTICS(
13421337
new_code.has_return_value(),
1343-
new_code.find_source_location().as_string() +
1344-
": function must return value");
1338+
"function must return value",
1339+
new_code.find_source_location());
13451340

13461341
// Now add a return node to set the return value.
13471342
goto_programt::targett t=dest.add_instruction();
@@ -1351,11 +1346,11 @@ void goto_convertt::convert_return(
13511346
}
13521347
else
13531348
{
1354-
INVARIANT(
1349+
INVARIANT_WITH_DIAGNOSTICS(
13551350
!new_code.has_return_value() ||
13561351
new_code.return_value().type().id() == ID_empty,
1357-
code.find_source_location().as_string() +
1358-
": function must not return value");
1352+
"function must not return value",
1353+
code.find_source_location());
13591354
}
13601355

13611356
// Need to process _entire_ destructor stack.
@@ -1372,9 +1367,10 @@ void goto_convertt::convert_continue(
13721367
goto_programt &dest,
13731368
const irep_idt &mode)
13741369
{
1375-
DATA_INVARIANT(
1370+
INVARIANT_WITH_DIAGNOSTICS(
13761371
targets.continue_set,
1377-
code.find_source_location().as_string() + ": continue without target");
1372+
"continue without target",
1373+
code.find_source_location());
13781374

13791375
// need to process destructor stack
13801376
unwind_destructor_stack(
@@ -1428,10 +1424,10 @@ void goto_convertt::convert_end_thread(
14281424
const codet &code,
14291425
goto_programt &dest)
14301426
{
1431-
DATA_INVARIANT(
1427+
INVARIANT_WITH_DIAGNOSTICS(
14321428
code.operands().empty(),
1433-
code.find_source_location().as_string() +
1434-
": end_thread expects no operands");
1429+
"end_thread expects no operands",
1430+
code.find_source_location());
14351431

14361432
copy(code, END_THREAD, dest);
14371433
}
@@ -1440,10 +1436,10 @@ void goto_convertt::convert_atomic_begin(
14401436
const codet &code,
14411437
goto_programt &dest)
14421438
{
1443-
DATA_INVARIANT(
1439+
INVARIANT_WITH_DIAGNOSTICS(
14441440
code.operands().empty(),
1445-
code.find_source_location().as_string() +
1446-
": atomic_begin expects no operands");
1441+
"atomic_begin expects no operands",
1442+
code.find_source_location());
14471443

14481444
copy(code, ATOMIC_BEGIN, dest);
14491445
}
@@ -1452,10 +1448,10 @@ void goto_convertt::convert_atomic_end(
14521448
const codet &code,
14531449
goto_programt &dest)
14541450
{
1455-
DATA_INVARIANT(
1451+
INVARIANT_WITH_DIAGNOSTICS(
14561452
code.operands().empty(),
1457-
code.find_source_location().as_string() +
1458-
": atomic_end expects no operands");
1453+
": atomic_end expects no operands",
1454+
code.find_source_location());
14591455

14601456
copy(code, ATOMIC_END, dest);
14611457
}
@@ -1465,11 +1461,6 @@ void goto_convertt::convert_ifthenelse(
14651461
goto_programt &dest,
14661462
const irep_idt &mode)
14671463
{
1468-
DATA_INVARIANT(
1469-
code.operands().size() == 3,
1470-
code.find_source_location().as_string() +
1471-
": ifthenelse takes three operands");
1472-
14731464
DATA_INVARIANT(code.then_case().is_not_nil(), "cannot accept an empty body");
14741465

14751466
bool has_else=
@@ -1868,7 +1859,8 @@ irep_idt goto_convertt::get_string_constant(const exprt &expr)
18681859
bool res = get_string_constant(expr, result);
18691860
INVARIANT_WITH_DIAGNOSTICS(
18701861
!res,
1871-
expr.find_source_location().as_string() + ": expected string constant",
1862+
"expected string constant",
1863+
expr.find_source_location(),
18721864
expr.pretty());
18731865

18741866
return result;

0 commit comments

Comments
 (0)