This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix PRs 52080, 52097 and 48124, rewrite bitfield expansion, enable the C++ memory model wrt bitfields everywhere


> > May I apply the patch I posted?  It boostrapped/regtested fine on
> > x86-64/Linux.
>
> Yes.

Thanks.  Unfortunately, while this was the last identified problem on x86, 
another issue is visible on x86-64 as a miscompilation of XML/Ada at -O0.
Reduced testcase attached:

 gnat.dg/pack18.adb
 gnat.dg/pack18_pkg.ads

The executable segfaults because it attempts a read at 0x2000000000000000.

The scenario is a follows: Rec is packed record so its fields are bit fields, N 
being at bit offset 129.  The representative is at offset 0.

get_bit_range is invoked on N with a bitpos of 1, because there is variable 
offset and its DECL_FIELD_OFFFSET is added to it instead of bitpos.  Hence

  bitpos - bitoffset

is (unsigned HOST_WIDE_INT) -128.  This value enters unchanged the new code in 
store_bit_field and the division:

     offset = bitregion_start / BITS_PER_UNIT;

yields the problematic big number.

It would therefore appear that bitstart and bitend need to be signed offsets, 
at least until they are adjusted by store_bit_field.

-- 
Eric Botcazou
-- { dg-do run }

with Pack18_Pkg; use Pack18_Pkg;

procedure Pack18 is
   use Pack18_Pkg.Attributes_Tables;
   Table : Instance;
begin
   Init (Table);
   Set_Last (Table, 1);
   Table.Table (Last (Table)).N := 0;
end;
with GNAT.Dynamic_Tables;

package Pack18_Pkg is

   type String_Access is access String;

   type Rec is record
      S : String_Access;
      B : Boolean;
      N : Natural;
   end record;
   pragma Pack (Rec);

   package Attributes_Tables is new GNAT.Dynamic_Tables
     (Table_Component_Type => Rec,
      Table_Index_Type     => Natural,
      Table_Low_Bound      => 1,
      Table_Initial        => 200,
      Table_Increment      => 200);

end Pack18_Pkg;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]