Bug 49565 - character(kind=4) is emitted as DW_ATE_unsigned, not DW_ATE_unsigned_char
Summary: character(kind=4) is emitted as DW_ATE_unsigned, not DW_ATE_unsigned_char
Status: WAITING
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks: 24546
  Show dependency treegraph
 
Reported: 2011-06-28 15:55 UTC by Tom Tromey
Modified: 2015-10-20 21:54 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2015-10-20 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tom Tromey 2011-06-28 15:55:29 UTC
I compiled this program with svn trunk gfortran.
I used -gdwarf-4 -g.

character(kind=4) :: c
character(kind=4,len=5) :: str
c = 4_'\u00AE'
str = 4_'\u00AE\u01DD'
open(6,encoding='utf-8')
print *, c
print *, str
end


Then I examined the DWARF.  'c' is ultimately of type:

 <1><cf>: Abbrev Number: 7 (DW_TAG_base_type)
    <d0>   DW_AT_byte_size   : 4	
    <d1>   DW_AT_encoding    : 7	(unsigned)
    <d2>   DW_AT_name        : (indirect string, offset: 0x67): character(kind=4)	

I think the encoding should be DW_ATE_unsigned_char instead.
Comment 1 Tobias Burnus 2011-06-28 16:07:33 UTC
From gcc/dwarf2out.c's base_type_die:

      if (TYPE_STRING_FLAG (type))
	{
	  if (TYPE_UNSIGNED (type))
	    encoding = DW_ATE_unsigned_char;

which should set it. However, there is also in gen_array_type_die the following code:

  /* Emit DW_TAG_string_type for Fortran character types (with kind 1 only, as
     DW_TAG_string_type doesn't have DW_AT_type attribute).  */
  if (TYPE_STRING_FLAG (type)
      && TREE_CODE (type) == ARRAY_TYPE
      && is_fortran ()
      && TYPE_MODE (TREE_TYPE (type)) == TYPE_MODE (char_type_node))

That has been added by Jakub's commit Rev. 139778:
http://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=cdba1d8f465a94f6f654bcc33a7663913df2181e;hp=98923a8420e5399f31613d93ebee61e63f2d36e1

Sumitted patch was http://gcc.gnu.org/ml/gcc-patches/2008-08/msg01680.html
Comment 2 Tobias Burnus 2011-06-28 16:45:35 UTC
There are two issues:

 a) The one mentioned by Jakub for the committal cited in comment 1
    That seems to be a DWARF bug - and Tromey has now filled an issue; it should
    show up in a while at http://www.dwarfstd.org/Issues.php

    The problem is that DW_TAG_string_type does not support DW_AT_type,
    which makes it not suitable for character(kind=4) [as it already has to
    handle character(kind=1)].

 b) Independent of that issue, GCC should emit DW_ATE_unsigned_char and not
    DW_ATE_unsigned


The latter issue seems to come due to the following code in gen_array_type_die:

  if (TYPE_STRING_FLAG (type)
      /* Case handling kind=1 characters. */
    {
      ...
      return;
    }
  ...
  /* For Fortran multidimensional arrays use DW_ORD_col_major ordering.  */
  if (is_fortran ()
      && TREE_CODE (type) == ARRAY_TYPE
      && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
      && !TYPE_STRING_FLAG (TREE_TYPE (type)))
    add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);

This test is true as:
  (gdb) p type->type_common.string_flag
  $6 = 1
  (gdb) p type->typed.type->type_common.string_flag
  $7 = 0

I wonder whether the
     && !TYPE_STRING_FLAG (TREE_TYPE (type)))
shouldn't be instead a
     && !TYPE_STRING_FLAG (type))

Or alternatively, whether fortran/trans-type.c's gfc_get_character_type_len_for_eltype should not only set
  TYPE_STRING_FLAG (type) = 1;
but also
  TYPE_STRING_FLAG (TREE_TYPE (type)) = 1;
Comment 3 Tobias Burnus 2011-06-28 16:55:16 UTC
(In reply to comment #2)
>   /* For Fortran multidimensional arrays use DW_ORD_col_major ordering.  */
>   if (is_fortran ()
>       && TREE_CODE (type) == ARRAY_TYPE
>       && TREE_CODE (TREE_TYPE (type)) == ARRAY_TYPE
>       && !TYPE_STRING_FLAG (TREE_TYPE (type)))
>     add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_col_major);

It's too warm to think poperly: TREE_CODE (type) is ARRAY_TYPE but TREE_CODE(TREE_TYPE(type)) is INTEGER_TYPE - not an ARRAY_TYPE; hence the code is never executed. Nevertheless, the issue is presumably related to type having TYPE_STRING_FLAG set, but TREE_TYPE(type) having it not.
Comment 4 Tobias Burnus 2012-04-16 22:04:20 UTC
See also http://www.dwarfstd.org/ShowIssue.php?issue=120213.1
Comment 5 Tobias Burnus 2013-03-15 17:49:35 UTC
Now moved to http://www.dwarfstd.org/ShowIssue.php?issue=121221.1&type=closed

Note: It is listed under "resolved issues".
Comment 6 Dominique d'Humieres 2015-10-20 21:54:53 UTC
> Now moved to http://www.dwarfstd.org/ShowIssue.php?issue=121221.1&type=closed
>
> Note: It is listed under "resolved issues".

Any progress after two years and a half?