Description: simplify big-endian byte updates
 .
 cbmc (5.12-4) unstable; urgency=low
 .
   * __float128 is not available on ppc64el (again)
   * Fix acceptable test input
   * Simplify big-endian byte updates
Author: Michael Tautschnig <mt@debian.org>

---
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: 2020-05-01

--- cbmc-5.12.orig/regression/cbmc/array-cell-sensitivity8/test.desc
+++ cbmc-5.12/regression/cbmc/array-cell-sensitivity8/test.desc
@@ -10,7 +10,7 @@ main::1::array!0@1#2\[\[6\]\] = main::1:
 main::1::array!0@1#2\[\[7\]\] = main::1::array!0@1#1\[7\]
 main::1::array!0@1#2\[\[8\]\] = main::1::array!0@1#1\[8\]
 main::1::array!0@1#2\[\[9\]\] = main::1::array!0@1#1\[9\]
-main::1::array!0@1#2 =.*byte_extract_little_endian
+main::1::array!0@1#2 =.*byte_extract_(big|little)_endian
 main::1::array!0@1#3\[\[0\]\] = main::1::array!0@1#2\[0\]
 main::1::array!0@1#3\[\[1\]\] = main::1::array!0@1#2\[1\]
 main::1::array!0@1#3\[\[2\]\] = main::1::array!0@1#2\[2\]
--- cbmc-5.12.orig/src/util/simplify_expr.cpp
+++ cbmc-5.12/src/util/simplify_expr.cpp
@@ -2062,16 +2062,17 @@ simplify_exprt::simplify_byte_update(con
   const auto val_size = pointer_offset_bits(value.type(), ns);
   const auto root_size = pointer_offset_bits(root.type(), ns);
 
+  const auto matching_byte_extract_id = 
+      expr.id()==ID_byte_update_little_endian ?
+        ID_byte_extract_little_endian :
+        ID_byte_extract_big_endian;
+
   // byte update of full object is byte_extract(new value)
   if(
     offset.is_zero() && val_size.has_value() && *val_size > 0 &&
     root_size.has_value() && *root_size > 0 && *val_size >= *root_size)
   {
-    byte_extract_exprt be(
-      expr.id()==ID_byte_update_little_endian ?
-        ID_byte_extract_little_endian :
-        ID_byte_extract_big_endian,
-      value, offset, expr.type());
+    byte_extract_exprt be(matching_byte_extract_id, value, offset, expr.type());
 
     return changed(simplify_byte_extract(be));
   }
@@ -2084,14 +2085,11 @@ simplify_exprt::simplify_byte_update(con
    *             value)
    */
 
-  if(expr.id()!=ID_byte_update_little_endian)
-    return unchanged(expr);
-
   if(value.id()==ID_with)
   {
     const with_exprt &with=to_with_expr(value);
 
-    if(with.old().id()==ID_byte_extract_little_endian)
+    if(with.old().id()==matching_byte_extract_id)
     {
       const byte_extract_exprt &extract=to_byte_extract_expr(with.old());
 
@@ -2230,7 +2228,7 @@ simplify_exprt::simplify_byte_update(con
          *update_size > 0 && m_size_bytes > *update_size))
       {
         byte_update_exprt v(
-          ID_byte_update_little_endian,
+          expr.id(),
           member_exprt(root, component.get_name(), component.type()),
           from_integer(*offset_int - *m_offset, offset.type()),
           value);
@@ -2248,7 +2246,7 @@ simplify_exprt::simplify_byte_update(con
       else
       {
         byte_extract_exprt v(
-          ID_byte_extract_little_endian,
+          matching_byte_extract_id,
           value,
           from_integer(*m_offset - *offset_int, offset.type()),
           component.type());
