@@ -447,19 +447,12 @@ bvt bv_pointerst::convert_pointer_type(const exprt &expr)
447447 CHECK_RETURN (bv.size ()==bits);
448448
449449 typet pointer_base_type = to_pointer_type (op.type ()).base_type ();
450-
451- if (pointer_base_type.id () == ID_empty)
452- {
453- // This is a gcc extension.
454- // https://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Pointer-Arith.html
455- size = 1 ;
456- }
457- else
458- {
459- auto size_opt = pointer_offset_size (pointer_base_type, ns);
460- CHECK_RETURN (size_opt.has_value () && *size_opt >= 0 );
461- size = *size_opt;
462- }
450+ DATA_INVARIANT (
451+ pointer_base_type.id () != ID_empty,
452+ " no pointer arithmetic over void pointers" );
453+ auto size_opt = pointer_offset_size (pointer_base_type, ns);
454+ CHECK_RETURN (size_opt.has_value () && *size_opt >= 0 );
455+ size = *size_opt;
463456 }
464457 }
465458
@@ -519,22 +512,12 @@ bvt bv_pointerst::convert_pointer_type(const exprt &expr)
519512
520513 typet pointer_base_type =
521514 to_pointer_type (minus_expr.lhs ().type ()).base_type ();
522- mp_integer element_size;
523-
524- if (pointer_base_type.id () == ID_empty)
525- {
526- // This is a gcc extension.
527- // https://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Pointer-Arith.html
528- element_size = 1 ;
529- }
530- else
531- {
532- auto element_size_opt = pointer_offset_size (pointer_base_type, ns);
533- CHECK_RETURN (element_size_opt.has_value () && *element_size_opt > 0 );
534- element_size = *element_size_opt;
535- }
536-
537- return offset_arithmetic (type, bv, element_size, neg_op1);
515+ DATA_INVARIANT (
516+ pointer_base_type.id () != ID_empty,
517+ " no pointer arithmetic over void pointers" );
518+ auto element_size_opt = pointer_offset_size (pointer_base_type, ns);
519+ CHECK_RETURN (element_size_opt.has_value () && *element_size_opt > 0 );
520+ return offset_arithmetic (type, bv, *element_size_opt, neg_op1);
538521 }
539522 else if (expr.id ()==ID_byte_extract_little_endian ||
540523 expr.id ()==ID_byte_extract_big_endian)
@@ -641,21 +624,17 @@ bvt bv_pointerst::convert_bitvector(const exprt &expr)
641624
642625 bvt difference = bv_utils.sub (lhs_offset, rhs_offset);
643626
644- // Support for void* is a gcc extension, with the size treated as 1 byte
645- // (no division required below).
646- // https://gcc.gnu.org/onlinedocs/gcc-4.8.0/gcc/Pointer-Arith.html
647- if (lhs_pt.base_type ().id () != ID_empty)
648- {
649- auto element_size_opt = pointer_offset_size (lhs_pt.base_type (), ns);
650- CHECK_RETURN (element_size_opt.has_value () && *element_size_opt > 0 );
627+ DATA_INVARIANT (
628+ lhs_pt.base_type ().id () != ID_empty,
629+ " no pointer arithmetic over void pointers" );
630+ auto element_size_opt = pointer_offset_size (lhs_pt.base_type (), ns);
631+ CHECK_RETURN (element_size_opt.has_value () && *element_size_opt > 0 );
651632
652- if (*element_size_opt != 1 )
653- {
654- bvt element_size_bv =
655- bv_utils.build_constant (*element_size_opt, width);
656- difference = bv_utils.divider (
657- difference, element_size_bv, bv_utilst::representationt::SIGNED);
658- }
633+ if (*element_size_opt != 1 )
634+ {
635+ bvt element_size_bv = bv_utils.build_constant (*element_size_opt, width);
636+ difference = bv_utils.divider (
637+ difference, element_size_bv, bv_utilst::representationt::SIGNED);
659638 }
660639
661640 // test for null object (integer constants)
0 commit comments