@@ -557,20 +557,49 @@ TEST_CASE(
557
557
smt_term_four_32bit));
558
558
}
559
559
560
- SECTION (
561
- " Ensure that conversion of a minus node with only one operand"
562
- " being a pointer fails" )
560
+ SECTION (" Subtraction of an integer value from a pointer" )
563
561
{
564
562
// (*int32_t)a - 2
565
- const cbmc_invariants_should_throwt invariants_throw;
566
- // We don't support that - look at the test above.
563
+
564
+ // NOTE: This may look similar to the above, but the above test
565
+ // is a desugared version of this construct - with the difference
566
+ // being that there exist cases where the construct is not desugared,
567
+ // so we can still come across this expression as an input to
568
+ // convert_expr_to_smt.
569
+ const auto two_bvint = from_integer (2 , signedbv_typet{pointer_width});
567
570
const auto pointer_arith_expr = minus_exprt{pointer_a, two_bvint};
571
+
572
+ const symbol_tablet symbol_table;
573
+ const namespacet ns{symbol_table};
574
+ track_expression_objects (pointer_arith_expr, ns, test.object_map );
575
+ associate_pointer_sizes (
576
+ pointer_arith_expr,
577
+ ns,
578
+ test.pointer_sizes ,
579
+ test.object_map ,
580
+ test.object_size_function .make_application );
581
+ INFO (" Input expr: " + pointer_arith_expr.pretty (2 , 0 ));
582
+ const auto constructed_term = test.convert (pointer_arith_expr);
583
+ const auto expected_term = smt_bit_vector_theoryt::subtract (
584
+ smt_term_a,
585
+ smt_bit_vector_theoryt::multiply (
586
+ smt_term_two_32bit, smt_term_four_32bit));
587
+ REQUIRE (constructed_term == expected_term);
588
+ }
589
+
590
+ SECTION (" Subtraction of pointer from integer" )
591
+ {
592
+ // 2 - (*int32_t)a -- Semantically void expression, need to make sure
593
+ // we throw in this case.
594
+ const cbmc_invariants_should_throwt invariants_throw;
595
+
596
+ const auto pointer_arith_expr = minus_exprt{two_bvint, pointer_a};
597
+
568
598
REQUIRE_THROWS_MATCHES (
569
599
test.convert (pointer_arith_expr),
570
600
invariant_failedt,
571
- invariant_failure_containing (
572
- " convert_expr_to_smt::minus_exprt doesn't handle expressions where"
573
- " only one operand is a pointer - this is because these expressions" ));
601
+ invariant_failure_containing (" minus expressions of pointer and integer "
602
+ " expect lhs to be the pointer" ));
574
603
}
575
604
576
605
SECTION (" Subtraction of two pointer arguments" )
0 commit comments