Description: Do not hardcode pointer bit width
 Several unit tests hard coded pointer width to 64.
 .
 cbmc (5.84.0-1) unstable; urgency=low
 .
   * New upstream release
   * Includes bugfix for unintentional copy (Closes: #984008)
   * Updated Standards version to 4.6.0 (no changes required)
Author: Michael Tautschnig <mt@debian.org>
Bug-Debian: https://bugs.debian.org/984008

---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: https://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: 2023-05-31

--- cbmc-5.84.0.orig/unit/goto-programs/goto_program_validate.cpp
+++ cbmc-5.84.0/unit/goto-programs/goto_program_validate.cpp
@@ -23,6 +23,8 @@
 #include <goto-programs/goto_model.h>
 #include <goto-programs/validate_goto_model.h>
 
+#include <climits>
+
 SCENARIO("Validation of a goto program", "[core][goto-programs][validate]")
 {
   goto_modelt goto_model;
@@ -55,7 +57,7 @@ SCENARIO("Validation of a goto program",
 
   // pointer to fn call
   symbolt fn_ptr{
-    "fn_ptr", pointer_typet(code_typet{{}, empty_typet()}, 64), ID_C};
+    "fn_ptr", pointer_typet(code_typet{{}, empty_typet()}, sizeof(void (*)(void)) * CHAR_BIT), ID_C};
   goto_model.symbol_table.add(fn_ptr);
 
   symbolt entry_point{
--- cbmc-5.84.0.orig/unit/interpreter/interpreter.cpp
+++ cbmc-5.84.0/unit/interpreter/interpreter.cpp
@@ -17,6 +17,8 @@ Author: Diffblue Ltd.
 
 #include <testing-utils/use_catch.h>
 
+#include <climits>
+
 typedef interpretert::mp_vectort mp_vectort;
 
 class interpreter_testt
@@ -46,7 +48,7 @@ SCENARIO("interpreter evaluation null po
   THEN("null pointer without operands")
   {
     unsignedbv_typet java_char(16);
-    pointer_typet pointer_type(java_char, 64);
+    pointer_typet pointer_type(java_char, sizeof(void *) * CHAR_BIT);
 
     null_pointer_exprt constant_expr{pointer_type};
 
@@ -56,13 +58,13 @@ SCENARIO("interpreter evaluation null po
   }
   THEN("null pointer with operands")
   {
-    pointer_typet outer_pointer_type(empty_typet(), 64);
+    pointer_typet outer_pointer_type(empty_typet(), sizeof(void *) * CHAR_BIT);
     constant_exprt outer_expression(
       "0000000000000000000000000000000000000000000000000000000000000000",
       outer_pointer_type);
 
     outer_expression.add_to_operands(
-      null_pointer_exprt(pointer_typet(empty_typet(), 64)));
+      null_pointer_exprt(pointer_typet(empty_typet(), sizeof(void *) * CHAR_BIT)));
 
     mp_vectort mp_vector = interpreter_test.evaluate(outer_expression);
 
--- cbmc-5.84.0.orig/unit/pointer-analysis/value_set.cpp
+++ cbmc-5.84.0/unit/pointer-analysis/value_set.cpp
@@ -17,6 +17,8 @@ Author: Diffblue Ltd.
 #include <pointer-analysis/value_set.h>
 #include <testing-utils/use_catch.h>
 
+#include <climits>
+
 static bool object_descriptor_matches(
   const exprt &descriptor_expr, const exprt &target)
 {
@@ -49,8 +51,8 @@ SCENARIO(
   {
     // Create struct A { A *x; A *y }
 
-    struct_typet struct_A({{"x", pointer_typet(struct_tag_typet("A"), 64)},
-                           {"y", pointer_typet(struct_tag_typet("A"), 64)}});
+    struct_typet struct_A({{"x", pointer_typet(struct_tag_typet("A"), sizeof(void *) * CHAR_BIT)},
+                           {"y", pointer_typet(struct_tag_typet("A"), sizeof(void *) * CHAR_BIT)}});
     struct_A.set_tag("A");
 
     auto &A_x = struct_A.components()[0];
@@ -225,7 +227,7 @@ SCENARIO(
   {
     // Make some global integers i1, i2, i3:
     signedbv_typet int32_type(32);
-    pointer_typet int32_ptr(int32_type, 64);
+    pointer_typet int32_ptr(int32_type, sizeof(void *) * CHAR_BIT);
 
     symbolt i1{"i1", int32_type, irep_idt{}};
     i1.base_name = "i1";
--- cbmc-5.84.0.orig/unit/solvers/smt2_incremental/construct_value_expr_from_smt.cpp
+++ cbmc-5.84.0/unit/solvers/smt2_incremental/construct_value_expr_from_smt.cpp
@@ -13,6 +13,7 @@
 #include <testing-utils/invariant.h>
 #include <testing-utils/use_catch.h>
 
+#include <climits>
 #include <string>
 
 static mp_integer power2(unsigned exponent)
@@ -68,15 +69,15 @@ TEST_CASE("Value expr construction from
     rowt{smt_bit_vector_constant_termt{0, 8}, from_integer(0, c_bool_typet(8))},
     rowt{smt_bit_vector_constant_termt{1, 8}, from_integer(1, c_bool_typet(8))},
     rowt{
-      smt_bit_vector_constant_termt{0, 64},
-      from_integer(0, pointer_typet(void_type(), 64 /* bits */))},
+      smt_bit_vector_constant_termt{0, sizeof(void *) * CHAR_BIT},
+      from_integer(0, pointer_typet(void_type(), sizeof(void *) * CHAR_BIT))},
     // The reason for the more intricate elaboration of a pointer with a value
     // of 12 is a limitation in the design of from_integer, which only handles
     // pointers with value 0 (null pointers).
     rowt{
-      smt_bit_vector_constant_termt{12, 64},
+      smt_bit_vector_constant_termt{12, sizeof(void *) * CHAR_BIT},
       constant_exprt(
-        integer2bvrep(12, 64), pointer_typet(void_type(), 64 /* bits */))},
+        integer2bvrep(12, sizeof(void *) * CHAR_BIT), pointer_typet(void_type(), sizeof(void *) * CHAR_BIT))},
     UNSIGNED_BIT_VECTOR_TESTS(8),
     SIGNED_BIT_VECTOR_TESTS(8),
     UNSIGNED_BIT_VECTOR_TESTS(16),
--- cbmc-5.84.0.orig/unit/solvers/smt2_incremental/convert_expr_to_smt.cpp
+++ cbmc-5.84.0/unit/solvers/smt2_incremental/convert_expr_to_smt.cpp
@@ -22,6 +22,8 @@
 #include <testing-utils/invariant.h>
 #include <testing-utils/use_catch.h>
 
+#include <climits>
+
 TEST_CASE("\"typet\" to smt sort conversion", "[core][smt2_incremental]")
 {
   SECTION("Boolean type")
@@ -1530,7 +1532,7 @@ TEST_CASE(
     }
     SECTION("Pointer should be wide enough to encode offset")
     {
-      config.bv_encoding.object_bits = 64;
+      config.bv_encoding.object_bits = sizeof(void *) * CHAR_BIT;
       const address_of_exprt address_of_foo{foo};
       track_expression_objects(address_of_foo, ns, test.object_map);
       test.object_map.at(foo).unique_id = 256;
@@ -1567,7 +1569,8 @@ TEST_CASE(
     expr_to_smt_conversion_test_environmentt::make(test_archt::x86_64);
   CHECK(config.bv_encoding.object_bits == 8);
 
-  const auto pointer_type = pointer_typet(unsigned_int_type(), 64 /* bits */);
+  constexpr std::size_t ptr_width = sizeof(void *) * CHAR_BIT;
+  const auto pointer_type = pointer_typet(unsigned_int_type(), ptr_width);
   const pointer_object_exprt foo{
     symbol_exprt{"foo", pointer_type}, pointer_type};
   const pointer_object_exprt foobar{
@@ -1577,8 +1580,8 @@ TEST_CASE(
   {
     const auto converted = test.convert(foo);
     const auto expected =
-      smt_bit_vector_theoryt::zero_extend(56)(smt_bit_vector_theoryt::extract(
-        63, 56)(smt_identifier_termt("foo", smt_bit_vector_sortt(64))));
+      smt_bit_vector_theoryt::zero_extend(ptr_width - 8)(smt_bit_vector_theoryt::extract(
+        ptr_width - 1, ptr_width - 8)(smt_identifier_termt("foo", smt_bit_vector_sortt(ptr_width))));
     CHECK(converted == expected);
   }
 
@@ -1603,11 +1606,11 @@ TEST_CASE(
     INFO("Expression " + comparison.pretty(1, 0));
     const auto converted = test.convert(comparison);
     const auto bv1 =
-      smt_bit_vector_theoryt::zero_extend(56)(smt_bit_vector_theoryt::extract(
-        63, 56)(smt_identifier_termt("foo", smt_bit_vector_sortt(64))));
+      smt_bit_vector_theoryt::zero_extend(ptr_width - 8)(smt_bit_vector_theoryt::extract(
+        ptr_width - 1, ptr_width - 8)(smt_identifier_termt("foo", smt_bit_vector_sortt(ptr_width))));
     const auto bv2 =
-      smt_bit_vector_theoryt::zero_extend(56)(smt_bit_vector_theoryt::extract(
-        63, 56)(smt_identifier_termt("foobar", smt_bit_vector_sortt(64))));
+      smt_bit_vector_theoryt::zero_extend(ptr_width - 8)(smt_bit_vector_theoryt::extract(
+        ptr_width - 1, ptr_width - 8)(smt_identifier_termt("foobar", smt_bit_vector_sortt(ptr_width))));
     const auto expected = smt_core_theoryt::distinct(bv2, bv1);
     CHECK(converted == expected);
   }
@@ -1619,7 +1622,8 @@ TEST_CASE("pointer_offset_exprt to SMT c
     expr_to_smt_conversion_test_environmentt::make(test_archt::x86_64);
   CHECK(config.bv_encoding.object_bits == 8);
 
-  const auto pointer_type = pointer_typet(unsigned_int_type(), 64 /* bits */);
+  constexpr std::size_t ptr_width = sizeof(void *) * CHAR_BIT;
+  const auto pointer_type = pointer_typet(unsigned_int_type(), ptr_width);
   const pointer_offset_exprt pointer_offset{
     symbol_exprt{"foo", pointer_type}, pointer_type};
 
@@ -1628,7 +1632,7 @@ TEST_CASE("pointer_offset_exprt to SMT c
     const auto converted = test.convert(pointer_offset);
     const auto expected =
       smt_bit_vector_theoryt::sign_extend(8)(smt_bit_vector_theoryt::extract(
-        55, 0)(smt_identifier_termt("foo", smt_bit_vector_sortt(64))));
+        ptr_width - 9, 0)(smt_identifier_termt("foo", smt_bit_vector_sortt(ptr_width))));
     CHECK(converted == expected);
   }
 
--- cbmc-5.84.0.orig/unit/util/lower_byte_operators.cpp
+++ cbmc-5.84.0/unit/util/lower_byte_operators.cpp
@@ -279,7 +279,7 @@ SCENARIO("byte_extract_lowering", "[core
       signedbv_typet(128),
       ieee_float_spect::single_precision().to_type(),
       // generates the correct value, but remains wrapped in a typecast
-      // pointer_typet(u64, 64),
+      // pointer_typet(u64, sizeof(void *) * CHAR_BIT),
       vector_typet(size_type(), u8, size),
       vector_typet(size_type(), u64, size),
       complex_typet(s16),
@@ -435,7 +435,7 @@ SCENARIO("byte_update_lowering", "[core]
       signedbv_typet(128),
       ieee_float_spect::single_precision().to_type(),
       // generates the correct value, but remains wrapped in a typecast
-      // pointer_typet(u64, 64),
+      // pointer_typet(u64, sizeof(void *) * CHAR_BIT),
       vector_typet(size_type(), u8, size),
       vector_typet(size_type(), u64, size),
       // complex_typet(s16),
