https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66728

--- Comment #1 from Ulrich Weigand <uweigand at gcc dot gnu.org> ---
A bit of debugging shows that what's going on here is this:

add_const_value_attribute is called with the following constant RTL:
(const_wide_int 0x80000000000000000000000000000000)

The routine then does:
         add_AT_wide (die, DW_AT_const_value,
                      std::make_pair (rtl, GET_MODE (rtl)));

Note that GET_MODE (rtl) is VOIDmode.  This apparently causes creation of a
wide_int value with precision 0:
{<wide_int_storage> = {val = {0, -9223372036854775808, 2}, len = 2, precision =
0}

This seems already wrong, but doesn't quite explain the inconsistent output.

However, dwarf2out.c:get_full_len returns 0 if the precision is 0. 
Subsequently, when the DIE is emitted in output_die, we have:

            int len = get_full_len (*a->dw_attr_val.v.val_wide);
            int l = HOST_BITS_PER_WIDE_INT / HOST_BITS_PER_CHAR;
            if (len * HOST_BITS_PER_WIDE_INT > 64)
              dw2_asm_output_data (1, get_full_len (*a->dw_attr_val.v.val_wide)
* l,
                                   NULL);

            if (WORDS_BIG_ENDIAN)
              for (i = len - 1; i >= 0; --i)
                {
                  dw2_asm_output_data (l, a->dw_attr_val.v.val_wide->elt (i),
                                       "%s", name);
                  name = NULL;
                }

When get_full_len is 0, the "if" is false, and thus no length is emitted.  In
addition, the loop count is 0, so nothing is emitted at all.

On the other hand, when the abbrev is emitted, value_format does:

    case dw_val_class_wide_int:
      switch (get_full_len (*a->dw_attr_val.v.val_wide) *
HOST_BITS_PER_WIDE_INT)
        {
        case 8:
          return DW_FORM_data1;
        case 16:
          return DW_FORM_data2;
        case 32:
          return DW_FORM_data4;
        case 64:
          return DW_FORM_data8;
        default:
          return DW_FORM_block1;
        }

so for a length of 0 we fall into the default case and assume DW_FORM_block1.

Any suggestions how to fix those (two?) problems?

Reply via email to