On Wed, 12 Oct 2022, Andre Vieira (lists) wrote: > Hi, > > The bitposition calculation for the bitfield lowering in loop if conversion > was not > taking DECL_FIELD_OFFSET into account, which meant that it would result in > wrong bitpositions for bitfields that did not end up having representations > starting at the beginning of the struct. > > Bootstrappend and regression tested on aarch64-none-linux-gnu and > x86_64-pc-linux-gnu.
+ { + tree bf_pos = fold_build2 (MULT_EXPR, bitsizetype, + DECL_FIELD_OFFSET (field_decl), + build_int_cst (bitsizetype, 8)); + bf_pos = fold_build2 (PLUS_EXPR, bitsizetype, bf_pos, + DECL_FIELD_BIT_OFFSET (field_decl)); + tree rep_pos = fold_build2 (MULT_EXPR, bitsizetype, + DECL_FIELD_OFFSET (rep_decl), + build_int_cst (bitsizetype, 8)); + rep_pos = fold_build2 (PLUS_EXPR, bitsizetype, rep_pos, + DECL_FIELD_BIT_OFFSET (rep_decl)); you can use the invariant that DECL_FIELD_OFFSET of rep_decl and field_decl are always the same. Also please use BITS_PER_UNIT instead of '8'. Richard.