public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r8-10898] dwarf2out: Fix debug info for 2 byte floats [PR99388] Date: Thu, 22 Apr 2021 16:51:58 +0000 (GMT) [thread overview] Message-ID: <20210422165159.13D413A4081C@sourceware.org> (raw) https://gcc.gnu.org/g:dbdd062665903c88b89525573d7dfde233562e8c commit r8-10898-gdbdd062665903c88b89525573d7dfde233562e8c 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. (cherry picked from commit d3dd3703f1d42b14c88b91e51a2a775fe00a2974) Diff: --- gcc/dwarf2out.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index 1162f0e9bdd..6227874b719 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -3777,7 +3777,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); @@ -16146,11 +16146,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; } } @@ -16720,11 +16721,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; } } @@ -19525,7 +19526,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]; @@ -19535,11 +19536,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 @@ -19588,9 +19597,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;
reply other threads:[~2021-04-22 16:51 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210422165159.13D413A4081C@sourceware.org \ --to=jakub@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).