This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 6/8] create a macro for max dimensions for array descr. lang. hook


The array descriptor language hook can hold the description of a limited
number of array dimensions.  This macro will ease preventing overflow in
front-ends.

gcc/ada/ChangeLog:

        * gcc-interface/misc.c (gnat_get_array_descr_info): When the
        array has more dimensions than the language hook can handle,
        fall back to a nested arrays description.  Handle context-less
        array types.

gcc/ChangeLog:

        * dwarf2out.h (DWARF2OUT_ARRAY_DESCR_INFO_MAX_DIMEN): New macro.
        (struct array_descr_info): Use it for the dimensions array's
        size.
        * dwarf2out.c (gen_type_die_with_usage): Check that the array
        descr. language hook does not return an array with more
        dimensions that it should.

--
Pierre-Marie de Rodat
>From 5221a4fadfa84f31cc97e0eba26f8640c9abe70d Mon Sep 17 00:00:00 2001
From: Pierre-Marie de Rodat <derodat@adacore.com>
Date: Fri, 21 Nov 2014 22:20:02 +0100
Subject: [PATCH 6/8] DWARF: create a macro for max dimensions for array descr.
 lang. hook

The array descriptor language hook can hold the description of a limited
number of array dimensions.  This macro will ease preventing overflow in
front-ends.

gcc/ada/ChangeLog:

	* gcc-interface/misc.c (gnat_get_array_descr_info): When the
	array has more dimensions than the language hook can handle,
	fall back to a nested arrays description.  Handle context-less
	array types.

gcc/ChangeLog:

	* dwarf2out.h (DWARF2OUT_ARRAY_DESCR_INFO_MAX_DIMEN): New macro.
	(struct array_descr_info): Use it for the dimensions array's
	size.
	* dwarf2out.c (gen_type_die_with_usage): Check that the array
	descr. language hook does not return an array with more
	dimensions that it should.
---
 gcc/ada/gcc-interface/misc.c | 16 +++++++++++++++-
 gcc/dwarf2out.c              |  4 ++++
 gcc/dwarf2out.h              |  4 +++-
 3 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/gcc/ada/gcc-interface/misc.c b/gcc/ada/gcc-interface/misc.c
index 318f566..4a355a3 100644
--- a/gcc/ada/gcc-interface/misc.c
+++ b/gcc/ada/gcc-interface/misc.c
@@ -848,7 +848,20 @@ gnat_get_array_descr_info (const_tree type, struct array_descr_info *info)
 	break;
       last_dimen = dimen;
     }
+
   info->ndimensions = i;
+
+  /* Too many dimensions?  Give up generating proper description: yield instead
+     nested arrays.  Note that in this case, this hook is invoked once on each
+     intermediate array type: be consistent and output nested arrays for all
+     dimensions.  */
+  if (info->ndimensions > DWARF2OUT_ARRAY_DESCR_INFO_MAX_DIMEN
+      || TYPE_MULTI_ARRAY_P (first_dimen))
+    {
+      info->ndimensions = 1;
+      last_dimen = first_dimen;
+    }
+
   info->element_type = TREE_TYPE (last_dimen);
 
   /* Now iterate over all dimensions in source-order and fill the info
@@ -873,7 +886,8 @@ gnat_get_array_descr_info (const_tree type, struct array_descr_info *info)
 	     expressions:  arrays that are constrained by record discriminants
 	     and XUA types.  */
 	  const bool is_xua_type =
-	   (TREE_CODE (TYPE_CONTEXT (first_dimen)) != RECORD_TYPE
+	   (TYPE_CONTEXT (first_dimen) != NULL_TREE
+            && TREE_CODE (TYPE_CONTEXT (first_dimen)) != RECORD_TYPE
 	    && contains_placeholder_p (TYPE_MIN_VALUE (index_type)));
 
 	  if (is_xua_type && gnat_encodings != DWARF_GNAT_ENCODINGS_MINIMAL)
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 2653c67..d989264 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -22454,6 +22454,10 @@ gen_type_die_with_usage (tree type, dw_die_ref context_die,
       memset (&info, 0, sizeof (info));
       if (lang_hooks.types.get_array_descr_info (type, &info))
 	{
+	  /* Fortran sometimes emits array types with no dimension.  */
+	  gcc_assert (info.ndimensions >= 0
+		      && (info.ndimensions
+			  <= DWARF2OUT_ARRAY_DESCR_INFO_MAX_DIMEN));
 	  gen_descr_array_type_die (type, &info, context_die);
 	  TREE_ASM_WRITTEN (type) = 1;
 	  return;
diff --git a/gcc/dwarf2out.h b/gcc/dwarf2out.h
index 655d91a..a2049d0 100644
--- a/gcc/dwarf2out.h
+++ b/gcc/dwarf2out.h
@@ -318,6 +318,8 @@ enum array_descr_ordering
   array_descr_ordering_column_major
 };
 
+#define DWARF2OUT_ARRAY_DESCR_INFO_MAX_DIMEN 16
+
 struct array_descr_info
 {
   int ndimensions;
@@ -341,7 +343,7 @@ struct array_descr_info
       /* Only Fortran uses more than one dimension for array types.  For other
 	 languages, the stride can be rather specified for the whole array.  */
       tree stride;
-    } dimen[10];
+    } dimen[DWARF2OUT_ARRAY_DESCR_INFO_MAX_DIMEN];
 };
 
 enum fixed_point_scale_factor
-- 
2.4.5


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]