35 const exprt &given_alignment=
36 static_cast<const exprt &
>(type.
find(ID_C_alignment));
41 if(given_alignment.
is_nil() ||
46 if(a_int>0 && !type.
get_bool(ID_C_packed))
49 else if(a_int==0 && type.
get_bool(ID_C_packed))
55 if(type.
id()==ID_array)
57 else if(type.
id()==ID_struct || type.
id()==ID_union)
66 for(struct_union_typet::componentst::const_iterator
67 it=components.begin();
70 result=std::max(result,
alignment(it->type(), ns));
72 else if(type.
id()==ID_unsignedbv ||
73 type.
id()==ID_signedbv ||
74 type.
id()==ID_fixedbv ||
75 type.
id()==ID_floatbv ||
76 type.
id()==ID_c_bool ||
77 type.
id()==ID_pointer)
81 else if(type.
id()==ID_c_enum)
83 else if(type.
id()==ID_c_enum_tag)
85 else if(type.
id()==ID_symbol)
87 else if(type.
id()==ID_c_bit_field)
97 if(a_int>0 && a_int<result)
108 if(subtype.
id() == ID_bool)
114 subtype.
id() == ID_signedbv || subtype.
id() == ID_unsignedbv ||
115 subtype.
id() == ID_c_bool)
119 else if(subtype.
id() == ID_c_enum_tag)
126 if(c_enum_type.
id() == ID_c_enum)
137 struct_typet::componentst::iterator where,
138 std::size_t pad_bits)
149 return std::next(components.insert(where, component));
152 static struct_typet::componentst::iterator
pad(
154 struct_typet::componentst::iterator where,
155 std::size_t pad_bits)
165 return std::next(components.insert(where, component));
172 std::size_t bit_field_bits = 0, underlying_bits = 0;
175 bool is_packed = type.
get_bool(ID_C_packed);
177 for(struct_typet::componentst::iterator it = components.begin();
178 it != components.end();
185 it->type().id() == ID_c_bit_field &&
192 bit_field_bits += width;
197 if(underlying_bits != 0 && (bit_field_bits % underlying_bits) != 0)
199 const std::size_t pad_bits =
200 underlying_bits - (bit_field_bits % underlying_bits);
203 underlying_bits = bit_field_bits = 0;
214 if(displacement != 0)
216 const mp_integer pad_bytes = a - displacement;
217 std::size_t pad_bits =
219 it =
pad(components, it, pad_bits);
226 if(it->type().id() == ID_c_bit_field)
231 bit_field_bits += width;
245 if(underlying_bits != 0 && (bit_field_bits % underlying_bits) != 0)
247 const std::size_t
pad =
248 underlying_bits - (bit_field_bits % underlying_bits);
258 if(displacement != 0)
260 const mp_integer pad_bytes = a - displacement;
261 const std::size_t pad_bits =
263 pad(components, components.end(), pad_bits);
274 std::size_t bit_field_bits=0;
276 for(struct_typet::componentst::iterator
277 it=components.begin();
278 it!=components.end();
281 if(it->type().id()==ID_c_bit_field &&
286 bit_field_bits+=width;
288 else if(bit_field_bits!=0)
305 const std::size_t
pad =
318 std::size_t bit_field_bits=0;
320 for(struct_typet::componentst::iterator
321 it=components.begin();
322 it!=components.end();
325 const typet it_type=it->type();
328 const bool packed=it_type.
get_bool(ID_C_packed) ||
331 if(it_type.
id()==ID_c_bit_field)
358 bit_field_bits == 0,
"padding ensures offset at byte boundaries");
374 const mp_integer pad_bytes = a - displacement;
375 const std::size_t pad_bits =
377 it =
pad(components, it, pad_bits);
392 static_cast<const exprt &
>(type.
find(ID_C_alignment));
398 if(!
to_integer(tmp, tmp_i) && tmp_i>max_alignment)
416 mp_integer pad_bytes = max_alignment - displacement;
417 std::size_t pad_bits =
419 pad(components, components.end(), pad_bits);
444 size_bits=std::max(size_bits, s);
459 if(c.type().id() == ID_c_bit_field)
462 if(w.has_value() && w.value() > max_alignment_bits)
463 max_alignment_bits = w.value();
470 if(size_bits%max_alignment_bits!=0)
473 max_alignment_bits-(size_bits%max_alignment_bits);
479 component.
type()=padding_type;
The type of an expression.
struct configt::ansi_ct ansi_c
Fixed-width bit-vector with unsigned binary interpretation.
static struct_typet::componentst::iterator pad_bit_field(struct_typet::componentst &components, struct_typet::componentst::iterator where, std::size_t pad_bits)
const bitvector_typet & to_bitvector_type(const typet &type)
Cast a generic typet to a bitvector_typet.
void set_name(const irep_idt &name)
signed int get_int(const irep_namet &name) const
static optionalt< std::size_t > underlying_width(const c_bit_field_typet &type, const namespacet &ns)
static void add_padding_msvc(struct_typet &type, const namespacet &ns)
std::vector< componentt > componentst
const componentst & components() const
static void add_padding_gcc(struct_typet &type, const namespacet &ns)
mp_integer pointer_offset_bits(const typet &type, const namespacet &ns)
bool get_bool(const irep_namet &name) const
const typet & follow_tag(const union_tag_typet &) const
mp_integer pointer_offset_size(const typet &type, const namespacet &ns)
Compute the size of a type in bytes, rounding up to full bytes.
const irep_idt & id() const
void set_is_padding(bool is_padding)
void add_padding(struct_typet &type, const namespacet &ns)
static struct_typet::componentst::iterator pad(struct_typet::componentst &components, struct_typet::componentst::iterator where, std::size_t pad_bits)
ANSI-C Language Type Checking.
nonstd::optional< T > optionalt
mp_integer alignment(const typet &type, const namespacet &ns)
const typet & follow(const typet &) const
std::size_t get_width() const
const c_enum_tag_typet & to_c_enum_tag_type(const typet &type)
Cast a generic typet to a c_enum_tag_typet.
Base class for all expressions.
const struct_union_typet & to_struct_union_type(const typet &type)
Cast a generic typet to a struct_union_typet.
std::string to_string(const string_constraintt &expr)
Used for debug printing.
const c_bit_field_typet & to_c_bit_field_type(const typet &type)
Cast a generic typet to a c_bit_field_typet.
std::size_t integer2size_t(const mp_integer &n)
const typet & subtype() const
#define DATA_INVARIANT(CONDITION, REASON)
const irept & find(const irep_namet &name) const
bool simplify(exprt &expr, const namespacet &ns)