@@ -1407,24 +1407,31 @@ void goto_check_ct::pointer_overflow_check(
14071407 if (object_type.id () != ID_empty)
14081408 {
14091409 auto size_of_expr_opt = size_of_expr (object_type, ns);
1410- CHECK_RETURN (size_of_expr_opt.has_value ());
1411- exprt object_size = size_of_expr_opt.value ();
1412-
1413- const binary_exprt &binary_expr = to_binary_expr (expr);
1414- exprt offset_operand = binary_expr.lhs ().type ().id () == ID_pointer
1415- ? binary_expr.rhs ()
1416- : binary_expr.lhs ();
1417- mult_exprt mul{
1418- offset_operand,
1419- typecast_exprt::conditional_cast (object_size, offset_operand.type ())};
1420- mul.add_source_location () = offset_operand.source_location ();
1421-
1422- flag_overridet override_overflow (offset_operand.source_location ());
1423- override_overflow.set_flag (
1424- enable_signed_overflow_check, true , " signed_overflow_check" );
1425- override_overflow.set_flag (
1426- enable_unsigned_overflow_check, true , " unsigned_overflow_check" );
1427- integer_overflow_check (mul, guard);
1410+
1411+ // For incomplete types (e.g., incomplete arrays), we cannot perform
1412+ // overflow checking since the size is unknown. We skip the overflow check
1413+ // for such types.
1414+ if (size_of_expr_opt.has_value ())
1415+ {
1416+ exprt object_size = size_of_expr_opt.value ();
1417+
1418+ const binary_exprt &binary_expr = to_binary_expr (expr);
1419+ exprt offset_operand = binary_expr.lhs ().type ().id () == ID_pointer
1420+ ? binary_expr.rhs ()
1421+ : binary_expr.lhs ();
1422+ mult_exprt mul{
1423+ offset_operand,
1424+ typecast_exprt::conditional_cast (object_size, offset_operand.type ())};
1425+ mul.add_source_location () = offset_operand.source_location ();
1426+
1427+ flag_overridet override_overflow (offset_operand.source_location ());
1428+ override_overflow.set_flag (
1429+ enable_signed_overflow_check, true , " signed_overflow_check" );
1430+ override_overflow.set_flag (
1431+ enable_unsigned_overflow_check, true , " unsigned_overflow_check" );
1432+ integer_overflow_check (mul, guard);
1433+ }
1434+ // else: incomplete type - cannot check overflow
14281435 }
14291436
14301437 // the result must be within object bounds or one past the end
@@ -1467,8 +1474,19 @@ void goto_check_ct::pointer_validity_check(
14671474 else
14681475 {
14691476 auto size_of_expr_opt = size_of_expr (expr.type (), ns);
1470- CHECK_RETURN (size_of_expr_opt.has_value ());
1471- size = size_of_expr_opt.value ();
1477+
1478+ // For incomplete array types (e.g., when dereferencing int (*p)[]),
1479+ // size_of_expr returns an empty optional since the size is not known.
1480+ // In this case, we perform a minimal validity check similar to void pointers.
1481+ if (!size_of_expr_opt.has_value ())
1482+ {
1483+ // Cannot determine size for incomplete types; use minimal check
1484+ size = from_integer (1 , size_type ());
1485+ }
1486+ else
1487+ {
1488+ size = size_of_expr_opt.value ();
1489+ }
14721490 }
14731491
14741492 auto conditions = get_pointer_dereferenceable_conditions (pointer, size);
0 commit comments