[gcc r11-7753] dwarf2out: Fix debug info for 2 byte floats [PR99388]

Jakub Jelinek jakub@gcc.gnu.org
Sun Mar 21 16:29:21 GMT 2021


https://gcc.gnu.org/g:fc24ea2374259d401a46ce3526688b7e79d4cc13

commit r11-7753-gfc24ea2374259d401a46ce3526688b7e79d4cc13
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Sun Mar 21 17:27:39 2021 +0100

    dwarf2out: Fix debug info for 2 byte floats [PR99388]
    
    Aarch64, ARM and a couple of other architectures have 16-bit floats, HFmode.
    As can be seen e.g. on
    void
    foo (void)
    {
      __fp16 a = 1.0;
      asm ("nop");
      a = 2.0;
      asm ("nop");
      a = 3.0;
      asm ("nop");
    }
    testcase, GCC mishandles this on the dwarf2out.c side by assuming all
    floating point types have sizes in multiples of 4 bytes, so what GCC emits
    is it says that e.g. the DW_OP_implicit_value will be 2 bytes but then
    doesn't emit anything and so anything emitted after it is treated by
    consumers as the value and then they get out of sync.
    real_to_target which insert_float uses indeed fills it that way, but putting
    into an array of long 32 bits each time, but for the half floats it puts
    everything into the least significant 16 bits of the first long no matter
    what endianity host or target has.
    
    The following patch fixes it.  With the patch the -g -O2 -dA output changes
    (in a cross without .uleb128 support):
            .byte   0x9e    // DW_OP_implicit_value
            .byte   0x2     // uleb128 0x2
    +       .2byte  0x3c00  // fp or vector constant word 0
            .byte   0x7     // DW_LLE_start_end (*.LLST0)
            .8byte  .LVL1   // Location list begin address (*.LLST0)
            .8byte  .LVL2   // Location list end address (*.LLST0)
            .byte   0x4     // uleb128 0x4; Location expression size
            .byte   0x9e    // DW_OP_implicit_value
            .byte   0x2     // uleb128 0x2
    +       .2byte  0x4000  // fp or vector constant word 0
            .byte   0x7     // DW_LLE_start_end (*.LLST0)
            .8byte  .LVL2   // Location list begin address (*.LLST0)
            .8byte  .LFE0   // Location list end address (*.LLST0)
            .byte   0x4     // uleb128 0x4; Location expression size
            .byte   0x9e    // DW_OP_implicit_value
            .byte   0x2     // uleb128 0x2
    +       .2byte  0x4200  // fp or vector constant word 0
            .byte   0       // DW_LLE_end_of_list (*.LLST0)
    
    Bootstrapped/regtested on x86_64-linux, aarch64-linux and
    armv7hl-linux-gnueabi, ok for trunk?
    
    I fear the CONST_VECTOR case is still broken, while HFmode elements of vectors
    should be fine (it uses eltsize of the element sizes) and likewise SFmode could
    be fine, DFmode vectors are emitted as two 32-bit ints regardless of endianity
    and I'm afraid it can't be right on big-endian.  But I haven't been able to
    create a testcase that emits a CONST_VECTOR, for e.g. unused vector vars
    with constant operands we emit CONCATN during expansion and thus ...
    DW_OP_*piece for each element of the vector and for
    DW_TAG_call_site_parameter we give up (because we handle CONST_VECTOR only
    in loc_descriptor, not mem_loc_descriptor).
    
    2021-03-21  Jakub Jelinek  <jakub@redhat.com>
    
            PR debug/99388
            * dwarf2out.c (insert_float): Change return type from void to
            unsigned, handle GET_MODE_SIZE (mode) == 2 and return element size.
            (mem_loc_descriptor, loc_descriptor, add_const_value_attribute):
            Adjust callers.

Diff:
---
 gcc/dwarf2out.c | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index b3ca159c3a8..ececcf50f8a 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -3825,7 +3825,7 @@ static void add_data_member_location_attribute (dw_die_ref, tree,
 static bool add_const_value_attribute (dw_die_ref, rtx);
 static void insert_int (HOST_WIDE_INT, unsigned, unsigned char *);
 static void insert_wide_int (const wide_int &, unsigned char *, int);
-static void insert_float (const_rtx, unsigned char *);
+static unsigned insert_float (const_rtx, unsigned char *);
 static rtx rtl_for_decl_location (tree);
 static bool add_location_or_const_value_attribute (dw_die_ref, tree, bool);
 static bool tree_add_const_value_attribute (dw_die_ref, tree);
@@ -16292,11 +16292,12 @@ mem_loc_descriptor (rtx rtl, machine_mode mode,
 	      scalar_float_mode float_mode = as_a <scalar_float_mode> (mode);
 	      unsigned int length = GET_MODE_SIZE (float_mode);
 	      unsigned char *array = ggc_vec_alloc<unsigned char> (length);
+	      unsigned int elt_size = insert_float (rtl, array);
 
-	      insert_float (rtl, array);
 	      mem_loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
-	      mem_loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
-	      mem_loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
+	      mem_loc_result->dw_loc_oprnd2.v.val_vec.length
+		= length / elt_size;
+	      mem_loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
 	      mem_loc_result->dw_loc_oprnd2.v.val_vec.array = array;
 	    }
 	}
@@ -16866,11 +16867,11 @@ loc_descriptor (rtx rtl, machine_mode mode,
 	    {
 	      unsigned int length = GET_MODE_SIZE (smode);
 	      unsigned char *array = ggc_vec_alloc<unsigned char> (length);
+	      unsigned int elt_size = insert_float (rtl, array);
 
-	      insert_float (rtl, array);
 	      loc_result->dw_loc_oprnd2.val_class = dw_val_class_vec;
-	      loc_result->dw_loc_oprnd2.v.val_vec.length = length / 4;
-	      loc_result->dw_loc_oprnd2.v.val_vec.elt_size = 4;
+	      loc_result->dw_loc_oprnd2.v.val_vec.length = length / elt_size;
+	      loc_result->dw_loc_oprnd2.v.val_vec.elt_size = elt_size;
 	      loc_result->dw_loc_oprnd2.v.val_vec.array = array;
 	    }
 	}
@@ -19689,7 +19690,7 @@ insert_wide_int (const wide_int &val, unsigned char *dest, int elt_size)
 
 /* Writes floating point values to dw_vec_const array.  */
 
-static void
+static unsigned
 insert_float (const_rtx rtl, unsigned char *array)
 {
   long val[4];
@@ -19699,11 +19700,19 @@ insert_float (const_rtx rtl, unsigned char *array)
   real_to_target (val, CONST_DOUBLE_REAL_VALUE (rtl), mode);
 
   /* real_to_target puts 32-bit pieces in each long.  Pack them.  */
+  if (GET_MODE_SIZE (mode) < 4)
+    {
+      gcc_assert (GET_MODE_SIZE (mode) == 2);
+      insert_int (val[0], 2, array);
+      return 2;
+    }
+
   for (i = 0; i < GET_MODE_SIZE (mode) / 4; i++)
     {
       insert_int (val[i], 4, array);
       array += 4;
     }
+  return 4;
 }
 
 /* Attach a DW_AT_const_value attribute for a variable or a parameter which
@@ -19752,9 +19761,10 @@ add_const_value_attribute (dw_die_ref die, rtx rtl)
 	  scalar_float_mode mode = as_a <scalar_float_mode> (GET_MODE (rtl));
 	  unsigned int length = GET_MODE_SIZE (mode);
 	  unsigned char *array = ggc_vec_alloc<unsigned char> (length);
+	  unsigned int elt_size = insert_float (rtl, array);
 
-	  insert_float (rtl, array);
-	  add_AT_vec (die, DW_AT_const_value, length / 4, 4, array);
+	  add_AT_vec (die, DW_AT_const_value, length / elt_size, elt_size,
+		      array);
 	}
       return true;


More information about the Gcc-cvs mailing list