Re: [PATCH] DWARF5 - Emit DW_AT_rank and DW_TAG_generic_subrange for assumed-rank arrays

2016-10-31 Thread Jason Merrill

OK.


[PATCH] DWARF5 - Emit DW_AT_rank and DW_TAG_generic_subrange for assumed-rank arrays

2016-10-26 Thread Jakub Jelinek
Hi!

The following patch starts emitting another new DWARF5 feature - DW_AT_rank
and DW_TAG_generic_subrange for Fortran assumed-rank arrays.
Unlike DW_TAG_subrange_type, the expressions in DW_TAG_generic_subrange
attributes have a magic 0 to rank-1 values pushed onto the DWARF stack
first; rather than allocating yet another DEBUG_EXPR_DECL for that,
I've used a PLACEHOLDER_EXPR with integral type.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

BTW, DWARF5 also has DW_TAG_coarray_type support, guess the
gfc_get_array_descr_info lang hook interface should be extended for that
(perhaps just as little as including ncodimensions next to dimensions
and filling the rest of the coranges, but I'm afraid I don't know enough
about the coarray stuff to be able to write the Fortran side of it.
So, Tobias or others, if you could come up with the trans-types.c side
and some examples, I can help with the dwarf2out.c side.

2016-10-26  Jakub Jelinek  

* dwarf2out.h (struct dw_loc_descr_node): Adjust comment
for frame_offset_rel bit.
(struct array_descr_info): Add rank field.
* dwarf2out.c (struct loc_descr_context): Add placeholder_arg
and placeholder_seen fields.
(resolve_args_picking_1): Handle also frame_offset_rel DW_OP_dup
and DW_OP_over.  Optimize DW_OP_pick 0 into DW_OP_dup and
DW_OP_pick 1 into DW_OP_over.
(function_to_dwarf_procedure, type_byte_size, field_byte_offset,
gen_variant_part): Clear placeholder_{arg,seen}.
(loc_list_from_tree_1): Drop const from context argument.
Handle integral PLACEHOLDER_EXPR if context->placeholder_arg.
(loc_list_for_address_of_addr_expr_of_indirect_ref,
loc_list_from_tree, loc_descriptor_from_tree): Drop const from
context argument.
(add_scalar_info): Drop const from context argument.  Handle
context->placeholder_arg.
(add_bound_info): Drop const from context argument.
(gen_descr_array_type_die): Drop const from ctx variable.
Initialize placeholder_arg and placeholder_seen.  Add DW_AT_rank
attribute and use a single DW_TAG_generic_subrange instead of
7 DW_TAG_subrange_type for assumed rank arrays.
fortran/
* trans-types.c (gfc_get_array_descr_info): For -gdwarf-5 or
-gno-strict-dwarf, handle assumed rank arrays the way dwarf2out
expects.
ada/
* gcc-interface/misc.c (gnat_get_array_descr_info): Clear rank
field.

--- gcc/dwarf2out.h.jj  2016-10-22 18:57:43.0 +0200
+++ gcc/dwarf2out.h 2016-10-26 10:45:44.104651085 +0200
@@ -234,9 +234,9 @@ struct GTY((chain_next ("%h.dw_loc_next"
   /* Used to distinguish DW_OP_addr with a direct symbol relocation
  from DW_OP_addr with a dtp-relative symbol relocation.  */
   unsigned int dtprel : 1;
-  /* For DW_OP_pick operations: true iff. it targets a DWARF prodecure
- argument.  In this case, it needs to be relocated according to the current
- frame offset.  */
+  /* For DW_OP_pick, DW_OP_dup and DW_OP_over operations: true iff.
+ it targets a DWARF prodecure argument.  In this case, it needs to be
+ relocated according to the current frame offset.  */
   unsigned int frame_offset_rel : 1;
   int dw_loc_addr;
   dw_val_node dw_loc_oprnd1;
@@ -322,6 +322,7 @@ struct array_descr_info
   tree allocated;
   tree associated;
   tree stride;
+  tree rank;
   bool stride_in_bits;
   struct array_descr_dimen
 {
--- gcc/dwarf2out.c.jj  2016-10-25 22:13:57.0 +0200
+++ gcc/dwarf2out.c 2016-10-26 10:49:31.041820289 +0200
@@ -3293,9 +3293,9 @@ struct loc_descr_context;
 static void add_loc_descr_to_each (dw_loc_list_ref list, dw_loc_descr_ref ref);
 static void add_loc_list (dw_loc_list_ref *ret, dw_loc_list_ref list);
 static dw_loc_list_ref loc_list_from_tree (tree, int,
-  const struct loc_descr_context *);
+  struct loc_descr_context *);
 static dw_loc_descr_ref loc_descriptor_from_tree (tree, int,
- const struct 
loc_descr_context *);
+ struct loc_descr_context *);
 static HOST_WIDE_INT ceiling (HOST_WIDE_INT, unsigned int);
 static tree field_type (const_tree);
 static unsigned int simple_type_align_in_bits (const_tree);
@@ -3320,9 +3320,9 @@ static void add_name_attribute (dw_die_r
 static void add_gnat_descriptive_type_attribute (dw_die_ref, tree, dw_die_ref);
 static void add_comp_dir_attribute (dw_die_ref);
 static void add_scalar_info (dw_die_ref, enum dwarf_attribute, tree, int,
-const struct loc_descr_context *);
+struct loc_descr_context *);
 static void add_bound_info (dw_die_ref, enum dwarf_attribute, tree,
-   const struct loc_descr_context *);
+   struct