]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix oversight about big-endian targets in latest change
authorEric Botcazou <ebotcazou@adacore.com>
Thu, 22 May 2025 14:25:07 +0000 (16:25 +0200)
committerEric Botcazou <ebotcazou@adacore.com>
Thu, 22 May 2025 20:18:03 +0000 (22:18 +0200)
Bit-fields are stored left-justified for big-endian targets.

gcc/
* dwarf2out.cc (loc_list_from_tree_1) <COMPONENT_REF>: Add specific
handling of bit-fields for big-endian targets.

gcc/dwarf2out.cc

index 713a55108aa2bf77d2b1c8b0081b9940308b4590..d1a55dbcbcbfe6d7606955edc8419491c2abdeed 100644 (file)
@@ -19764,18 +19764,35 @@ loc_list_from_tree_1 (tree loc, int want_address,
            {
              if (TYPE_UNSIGNED (TREE_TYPE (loc)))
                {
-                 const unsigned HOST_WIDE_INT mask
-                   = (HOST_WIDE_INT_1U << bitsize) - 1;
-                 add_loc_descr (&deref, uint_loc_descriptor (mask));
-                 add_loc_descr (&deref, new_loc_descr (DW_OP_and, 0, 0));
+                 if (BYTES_BIG_ENDIAN)
+                   {
+                     const unsigned HOST_WIDE_INT shift
+                       = size * BITS_PER_UNIT - bitsize;
+                     add_loc_descr (&deref, uint_loc_descriptor (shift));
+                     add_loc_descr (&deref, new_loc_descr (DW_OP_shr, 0, 0));
+                   }
+                 else
+                   {
+                     const unsigned HOST_WIDE_INT mask
+                       = (HOST_WIDE_INT_1U << bitsize) - 1;
+                     add_loc_descr (&deref, uint_loc_descriptor (mask));
+                     add_loc_descr (&deref, new_loc_descr (DW_OP_and, 0, 0));
+                   }
                }
              else
                {
-                 const unsigned HOST_WIDE_INT shift
+                 const unsigned HOST_WIDE_INT shiftr
                    = DWARF2_ADDR_SIZE * BITS_PER_UNIT - bitsize;
-                 add_loc_descr (&deref, uint_loc_descriptor (shift));
-                 add_loc_descr (&deref, new_loc_descr (DW_OP_shl, 0, 0));
-                 add_loc_descr (&deref, uint_loc_descriptor (shift));
+                 const unsigned HOST_WIDE_INT shiftl
+                   = BYTES_BIG_ENDIAN
+                     ? (DWARF2_ADDR_SIZE - size) * BITS_PER_UNIT
+                     : shiftr;
+                 if (shiftl > 0)
+                   {
+                     add_loc_descr (&deref, uint_loc_descriptor (shiftl));
+                     add_loc_descr (&deref, new_loc_descr (DW_OP_shl, 0, 0));
+                   }
+                 add_loc_descr (&deref, uint_loc_descriptor (shiftr));
                  add_loc_descr (&deref, new_loc_descr (DW_OP_shra, 0, 0));
                }
            }