* [PATCH] Emit Fortran CHARACTER types as DW_TAG_string_type
@ 2008-08-22 17:06 Jakub Jelinek
2008-08-22 18:32 ` Jason Merrill
0 siblings, 1 reply; 4+ messages in thread
From: Jakub Jelinek @ 2008-08-22 17:06 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches, fortran, Jan Kratochvil, Michael Eager
Hi!
The Dwarf3 standard says Fortran CHARACTER types should be represented
as DW_TAG_string_type (but as it has no DW_AT_type, IMHO only kind=1
characters can use it) and this patch implements that. Testcase e.g.
subroutine foo (e, f)
character (len=1) :: c
character (len=8) :: d
character (len=*) :: e
character (len=*) :: f (1:7, 8:10)
c = 'c'
d = 'd'
e = 'e'
f = 'f'
end subroutine foo
character (len=4) :: g, h (1:7, 8:10)
g = 'g'
h = 'h'
call foo (g, h)
end
gdb I have handles the constant DW_TAG_string_type DIEs well (and obviously
it is much nicer than what it printed for DW_TAG_array_type DIEs), but the
non-constant ones with DW_AT_string_length don't seem to be working right,
but IMHO what GCC emits with this patch looks correct.
2008-08-22 Jakub Jelinek <jakub@redhat.com>
* dwarf2out.c (add_subscript_info): Stop on Fortran TYPE_STRING_FLAG
types.
(gen_array_type_die): Emit DW_TAG_string_type for Fortran character
types.
--- gcc/dwarf2out.c.jj 2008-08-22 13:39:21.000000000 +0200
+++ gcc/dwarf2out.c 2008-08-22 17:49:10.000000000 +0200
@@ -12037,6 +12037,9 @@ add_subscript_info (dw_die_ref type_die,
{
tree domain = TYPE_DOMAIN (type);
+ if (TYPE_STRING_FLAG (type) && is_fortran ())
+ break;
+
/* Arrays come in three flavors: Unspecified bounds, fixed bounds,
and (in GNU C only) variable bounds. Handle all three forms
here. */
@@ -12570,7 +12573,40 @@ gen_array_type_die (tree type, dw_die_re
bool collapse_nested_arrays = !is_ada ();
tree element_type;
-
+
+ /* 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))
+ {
+ HOST_WIDE_INT size;
+
+ array_die = new_die (DW_TAG_string_type, scope_die, type);
+ add_name_attribute (array_die, type_tag (type));
+ equate_type_number_to_die (type, array_die);
+ size = int_size_in_bytes (type);
+ if (size >= 0)
+ add_AT_unsigned (array_die, DW_AT_byte_size, size);
+ else if (TYPE_DOMAIN (type) != NULL_TREE
+ && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE
+ && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
+ {
+ tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
+ dw_loc_descr_ref loc = loc_descriptor_from_tree (szdecl);
+
+ size = int_size_in_bytes (TREE_TYPE (szdecl));
+ if (loc && size > 0)
+ {
+ add_AT_loc (array_die, DW_AT_string_length, loc);
+ if (size != DWARF2_ADDR_SIZE)
+ add_AT_unsigned (array_die, DW_AT_byte_size, size);
+ }
+ }
+ return;
+ }
+
/* ??? The SGI dwarf reader fails for array of array of enum types
(e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
array type comes before the outer array type. We thus call gen_type_die
@@ -12597,7 +12633,8 @@ gen_array_type_die (tree type, dw_die_re
/* 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)
+ && 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);
#if 0
@@ -12625,8 +12662,12 @@ gen_array_type_die (tree type, dw_die_re
element_type = TREE_TYPE (type);
if (collapse_nested_arrays)
while (TREE_CODE (element_type) == ARRAY_TYPE)
- element_type = TREE_TYPE (element_type);
-
+ {
+ if (TYPE_STRING_FLAG (element_type) && is_fortran ())
+ break;
+ element_type = TREE_TYPE (element_type);
+ }
+
#ifndef MIPS_DEBUGGING_INFO
gen_type_die (element_type, context_die);
#endif
Jakub
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Emit Fortran CHARACTER types as DW_TAG_string_type
2008-08-22 17:06 [PATCH] Emit Fortran CHARACTER types as DW_TAG_string_type Jakub Jelinek
@ 2008-08-22 18:32 ` Jason Merrill
2008-08-22 18:58 ` Jakub Jelinek
0 siblings, 1 reply; 4+ messages in thread
From: Jason Merrill @ 2008-08-22 18:32 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: gcc-patches, fortran, Jan Kratochvil, Michael Eager
It seems like this patch uses DW_TAG_string_type for kind 1 CHARACTERs,
which makes sense, and leaves other CHARACTERs as DW_TAG_array_types,
which seems reasonable until the standards issue is cleared up, but then
also removes the array size/subscript information from those
DW_TAG_array_types, which I don't understand.
Jason
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Emit Fortran CHARACTER types as DW_TAG_string_type
2008-08-22 18:32 ` Jason Merrill
@ 2008-08-22 18:58 ` Jakub Jelinek
2008-08-31 2:46 ` Jason Merrill
0 siblings, 1 reply; 4+ messages in thread
From: Jakub Jelinek @ 2008-08-22 18:58 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches, fortran, Jan Kratochvil, Michael Eager
On Fri, Aug 22, 2008 at 01:58:17PM -0400, Jason Merrill wrote:
> It seems like this patch uses DW_TAG_string_type for kind 1 CHARACTERs,
> which makes sense, and leaves other CHARACTERs as DW_TAG_array_types,
> which seems reasonable until the standards issue is cleared up, but then
> also removes the array size/subscript information from those
> DW_TAG_array_types, which I don't understand.
You're right, I should have done the break in add_subscript_info only
for dimension_number > 0. The rest is IMHO correct. Even for kind 4
CHARACTER types IMHO we don't want character (kind=4,len=10) :: x (2:5,2:8)
be represented as 3 dimensional array, but 2 dimensional array of
1 dimensional arrays (when we can't use DW_TAG_string_type), to at least
hint the debugger it is not integer (kind=4) :: x (2:5,2:8,10).
2008-08-22 Jakub Jelinek <jakub@redhat.com>
* dwarf2out.c (add_subscript_info): Stop on Fortran TYPE_STRING_FLAG
types.
(gen_array_type_die): Emit DW_TAG_string_type for Fortran character
types.
--- gcc/dwarf2out.c.jj 2008-08-22 13:39:21.000000000 +0200
+++ gcc/dwarf2out.c 2008-08-22 17:49:10.000000000 +0200
@@ -12037,6 +12037,9 @@ add_subscript_info (dw_die_ref type_die,
{
tree domain = TYPE_DOMAIN (type);
+ if (TYPE_STRING_FLAG (type) && is_fortran () && dimension_number > 0)
+ break;
+
/* Arrays come in three flavors: Unspecified bounds, fixed bounds,
and (in GNU C only) variable bounds. Handle all three forms
here. */
@@ -12570,7 +12573,40 @@ gen_array_type_die (tree type, dw_die_re
bool collapse_nested_arrays = !is_ada ();
tree element_type;
-
+
+ /* 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))
+ {
+ HOST_WIDE_INT size;
+
+ array_die = new_die (DW_TAG_string_type, scope_die, type);
+ add_name_attribute (array_die, type_tag (type));
+ equate_type_number_to_die (type, array_die);
+ size = int_size_in_bytes (type);
+ if (size >= 0)
+ add_AT_unsigned (array_die, DW_AT_byte_size, size);
+ else if (TYPE_DOMAIN (type) != NULL_TREE
+ && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE
+ && DECL_P (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
+ {
+ tree szdecl = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
+ dw_loc_descr_ref loc = loc_descriptor_from_tree (szdecl);
+
+ size = int_size_in_bytes (TREE_TYPE (szdecl));
+ if (loc && size > 0)
+ {
+ add_AT_loc (array_die, DW_AT_string_length, loc);
+ if (size != DWARF2_ADDR_SIZE)
+ add_AT_unsigned (array_die, DW_AT_byte_size, size);
+ }
+ }
+ return;
+ }
+
/* ??? The SGI dwarf reader fails for array of array of enum types
(e.g. const enum machine_mode insn_operand_mode[2][10]) unless the inner
array type comes before the outer array type. We thus call gen_type_die
@@ -12597,7 +12633,8 @@ gen_array_type_die (tree type, dw_die_re
/* 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)
+ && 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);
#if 0
@@ -12625,8 +12662,12 @@ gen_array_type_die (tree type, dw_die_re
element_type = TREE_TYPE (type);
if (collapse_nested_arrays)
while (TREE_CODE (element_type) == ARRAY_TYPE)
- element_type = TREE_TYPE (element_type);
-
+ {
+ if (TYPE_STRING_FLAG (element_type) && is_fortran ())
+ break;
+ element_type = TREE_TYPE (element_type);
+ }
+
#ifndef MIPS_DEBUGGING_INFO
gen_type_die (element_type, context_die);
#endif
Jakub
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Emit Fortran CHARACTER types as DW_TAG_string_type
2008-08-22 18:58 ` Jakub Jelinek
@ 2008-08-31 2:46 ` Jason Merrill
0 siblings, 0 replies; 4+ messages in thread
From: Jason Merrill @ 2008-08-31 2:46 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: gcc-patches, fortran, Jan Kratochvil, Michael Eager
OK.
Jason
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-08-29 15:48 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-22 17:06 [PATCH] Emit Fortran CHARACTER types as DW_TAG_string_type Jakub Jelinek
2008-08-22 18:32 ` Jason Merrill
2008-08-22 18:58 ` Jakub Jelinek
2008-08-31 2:46 ` Jason Merrill
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).