@@ -1831,41 +1831,44 @@ simplify_exprt::simplify_byte_extract(const byte_extract_exprt &expr)
18311831 const auto bits =
18321832 expr2bits (expr.op (), expr.id () == ID_byte_extract_little_endian, ns);
18331833
1834- // make sure we don't lose bits with structs containing flexible array members
1835- const bool struct_has_flexible_array_member = has_subtype (
1836- expr.type (),
1837- [&](const typet &type) {
1838- if (type.id () != ID_struct && type.id () != ID_struct_tag)
1839- return false ;
1840-
1841- const struct_typet &st = to_struct_type (ns.follow (type));
1842- const auto &comps = st.components ();
1843- if (comps.empty () || comps.back ().type ().id () != ID_array)
1844- return false ;
1845-
1846- if (comps.back ().type ().get_bool (ID_C_flexible_array_member))
1847- return true ;
1848-
1849- const auto size =
1850- numeric_cast<mp_integer>(to_array_type (comps.back ().type ()).size ());
1851- return !size.has_value () || *size <= 1 ;
1852- },
1853- ns);
18541834 if (
18551835 bits.has_value () &&
1856- mp_integer (bits->size ()) >= *el_size + *offset * expr.get_bits_per_byte () &&
1857- !struct_has_flexible_array_member)
1858- {
1859- std::string bits_cut = std::string (
1860- bits.value (),
1861- numeric_cast_v<std::size_t >(*offset * expr.get_bits_per_byte ()),
1862- numeric_cast_v<std::size_t >(*el_size));
1836+ mp_integer (bits->size ()) >= *el_size + *offset * expr.get_bits_per_byte ())
1837+ {
1838+ // make sure we don't lose bits with structs containing flexible array
1839+ // members
1840+ const bool struct_has_flexible_array_member = has_subtype (
1841+ expr.type (),
1842+ [&](const typet &type) {
1843+ if (type.id () != ID_struct && type.id () != ID_struct_tag)
1844+ return false ;
1845+
1846+ const struct_typet &st = to_struct_type (ns.follow (type));
1847+ const auto &comps = st.components ();
1848+ if (comps.empty () || comps.back ().type ().id () != ID_array)
1849+ return false ;
1850+
1851+ if (comps.back ().type ().get_bool (ID_C_flexible_array_member))
1852+ return true ;
1853+
1854+ const auto size =
1855+ numeric_cast<mp_integer>(to_array_type (comps.back ().type ()).size ());
1856+ return !size.has_value () || *size <= 1 ;
1857+ },
1858+ ns);
1859+ if (!struct_has_flexible_array_member)
1860+ {
1861+ std::string bits_cut = std::string (
1862+ bits.value (),
1863+ numeric_cast_v<std::size_t >(*offset * expr.get_bits_per_byte ()),
1864+ numeric_cast_v<std::size_t >(*el_size));
18631865
1864- auto tmp = bits2expr (
1865- bits_cut, expr.type (), expr.id () == ID_byte_extract_little_endian, ns);
1866+ auto tmp = bits2expr (
1867+ bits_cut, expr.type (), expr.id () == ID_byte_extract_little_endian, ns);
18661868
1867- if (tmp.has_value ())
1868- return std::move (*tmp);
1869+ if (tmp.has_value ())
1870+ return std::move (*tmp);
1871+ }
18691872 }
18701873
18711874 // push byte extracts into struct or union expressions, just like
0 commit comments