Patchwork use XALLOCAVEC in Ada FE

login
register
mail settings
Submitter Nathan Froyd
Date Aug. 7, 2010, 8:18 p.m.
Message ID <20100807201813.GL17362@codesourcery.com>
Download mbox | patch
Permalink /patch/61192/
State New
Headers show

Comments

Nathan Froyd - Aug. 7, 2010, 8:18 p.m.
This makes converts several alloca calls to their XALLOCAVEC
equivalents.  The only possibly sketchy changes are to
env.c:__gnat_setenv; I don't have a VMS machine to test those on.

Tested on x86_64-unknown-linux-gnu.  OK to commit?

-Nathan

	* gcc-interface/decl.c (gnat_to_gnu_entity): Use XALLOCAVEC instead
	of alloca.
	(components_to_record): Likewise.
	* gcc-interface/trans.c (gnat_to_gnu): Likewise.
	* gcc-interface/utils.c (max_size): Likewise.
	(build_vms_descriptor32): Likewise.
	(build_vms_descriptor): Likewise.
	* env.c (__gnat_setenv): Likewise.  Use ASTRDUP instead of alloca
	and strcpy.
Arnaud Charlet - Aug. 7, 2010, 8:35 p.m.
> This makes converts several alloca calls to their XALLOCAVEC
> equivalents.  The only possibly sketchy changes are to
> env.c:__gnat_setenv; I don't have a VMS machine to test those on.

Isn't XALLOCAVEC a host/gcc macro? If so, this is not OK, since env.c is
both a host (for the compiler) and a target (for the run-time) source.

The gigi changes (gcc-interface) look OK to me.

Arno
Nathan Froyd - Aug. 7, 2010, 9:14 p.m.
On Sat, Aug 07, 2010 at 10:35:25PM +0200, Arnaud Charlet wrote:
> > This makes converts several alloca calls to their XALLOCAVEC
> > equivalents.  The only possibly sketchy changes are to
> > env.c:__gnat_setenv; I don't have a VMS machine to test those on.
> 
> Isn't XALLOCAVEC a host/gcc macro? If so, this is not OK, since env.c is
> both a host (for the compiler) and a target (for the run-time) source.

It looks like you are correct; there's a comment mixed in the #includes
that indicates we don't have libiberty's interfaces available.

> The gigi changes (gcc-interface) look OK to me.

Thanks for the review.  Committed without the env.c changes.

-Nathan

Patch

diff --git a/gcc/ada/env.c b/gcc/ada/env.c
index c53678a..d9ead70 100644
--- a/gcc/ada/env.c
+++ b/gcc/ada/env.c
@@ -137,11 +137,10 @@  __gnat_setenv (char *name, char *value)
 
   {
     int i, status;
-    ile_s *ile_array = alloca (sizeof (ile_s) * (num_dirs_in_pathspec + 1));
-    char *copy_pathspec = alloca (strlen (host_pathspec) + 1);
+    ile_s *ile_array = XALLOCAVEC (ile_s, num_dirs_in_pathspec + 1);
+    char *copy_pathspec = ASTRDUP (host_pathspec);
     char *curr, *next;
 
-    strcpy (copy_pathspec, host_pathspec);
     curr = copy_pathspec;
     for (i = 0; i < num_dirs_in_pathspec; i++)
       {
diff --git a/gcc/ada/gcc-interface/decl.c b/gcc/ada/gcc-interface/decl.c
index a9e3358..b63a620 100644
--- a/gcc/ada/gcc-interface/decl.c
+++ b/gcc/ada/gcc-interface/decl.c
@@ -1856,8 +1856,8 @@  gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
 	tree gnu_template_reference;
 	tree gnu_ptr_template = build_pointer_type (gnu_template_type);
 	tree gnu_fat_type = make_node (RECORD_TYPE);
-	tree *gnu_index_types = (tree *) alloca (ndim * sizeof (tree));
-	tree *gnu_temp_fields = (tree *) alloca (ndim * sizeof (tree));
+	tree *gnu_index_types = XALLOCAVEC (tree, ndim);
+	tree *gnu_temp_fields = XALLOCAVEC (tree, ndim);
 	tree gnu_max_size = size_one_node, gnu_max_size_unit, tem;
 	int index;
 
@@ -2127,7 +2127,7 @@  gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
 	    = (Convention (gnat_entity) == Convention_Fortran);
 	  const int ndim = Number_Dimensions (gnat_entity);
 	  tree gnu_base_type = gnu_type;
-	  tree *gnu_index_types = (tree *) alloca (ndim * sizeof (tree));
+	  tree *gnu_index_types = XALLOCAVEC (tree, ndim);
 	  tree gnu_max_size = size_one_node, gnu_max_size_unit;
 	  bool need_index_type_struct = false;
 	  int index;
@@ -7161,7 +7161,7 @@  components_to_record (tree gnu_record_type, Node_Id gnat_component_list,
       tree gnu_rep_type
 	= (gnu_field_list ? make_node (RECORD_TYPE) : gnu_record_type);
       int i, len = list_length (gnu_our_rep_list);
-      tree *gnu_arr = (tree *) alloca (sizeof (tree) * len);
+      tree *gnu_arr = XALLOCAVEC (tree, len);
 
       for (gnu_field = gnu_our_rep_list, i = 0;
 	   gnu_field;
diff --git a/gcc/ada/gcc-interface/trans.c b/gcc/ada/gcc-interface/trans.c
index 4bf8947..5abc562 100644
--- a/gcc/ada/gcc-interface/trans.c
+++ b/gcc/ada/gcc-interface/trans.c
@@ -4099,7 +4099,7 @@  gnat_to_gnu (Node_Id gnat_node)
 	     ndim++, gnu_type = TREE_TYPE (gnu_type))
 	  ;
 
-	gnat_expr_array = (Node_Id *) alloca (ndim * sizeof (Node_Id));
+	gnat_expr_array = XALLOCAVEC (Node_Id, ndim);
 
 	if (TYPE_CONVENTION_FORTRAN_P (TREE_TYPE (gnu_array_object)))
 	  for (i = ndim - 1, gnat_temp = First (Expressions (gnat_node));
@@ -5267,8 +5267,7 @@  gnat_to_gnu (Node_Id gnat_node)
 	  noutputs = list_length (gnu_outputs);
 	  gnu_inputs = nreverse (gnu_inputs);
 	  ninputs = list_length (gnu_inputs);
-	  oconstraints
-	    = (const char **) alloca (noutputs * sizeof (const char *));
+	  oconstraints = XALLOCAVEC (const char *, noutputs);
 
 	  for (i = 0, tail = gnu_outputs; tail; ++i, tail = TREE_CHAIN (tail))
 	    {
diff --git a/gcc/ada/gcc-interface/utils.c b/gcc/ada/gcc-interface/utils.c
index eed426a..381d71b 100644
--- a/gcc/ada/gcc-interface/utils.c
+++ b/gcc/ada/gcc-interface/utils.c
@@ -2134,7 +2134,7 @@  max_size (tree exp, bool max_p)
 
 	  n = call_expr_nargs (exp);
 	  gcc_assert (n > 0);
-	  argarray = (tree *) alloca (n * sizeof (tree));
+	  argarray = XALLOCAVEC (tree, n);
 	  for (i = 0; i < n; i++)
 	    argarray[i] = max_size (CALL_EXPR_ARG (exp, i), max_p);
 	  return build_call_array (type, CALL_EXPR_FN (exp), n, argarray);
@@ -2317,7 +2317,7 @@  build_vms_descriptor32 (tree type, Mechanism_Type mech, Entity_Id gnat_entity)
 	 ndim++, inner_type = TREE_TYPE (inner_type))
       ;
 
-  idx_arr = (tree *) alloca (ndim * sizeof (tree));
+  idx_arr = XALLOCAVEC (tree, ndim);
 
   if (mech != By_Descriptor_NCA && mech != By_Short_Descriptor_NCA
       && TREE_CODE (type) == ARRAY_TYPE && TYPE_CONVENTION_FORTRAN_P (type))
@@ -2631,7 +2631,7 @@  build_vms_descriptor (tree type, Mechanism_Type mech, Entity_Id gnat_entity)
 	 ndim++, inner_type = TREE_TYPE (inner_type))
       ;
 
-  idx_arr = (tree *) alloca (ndim * sizeof (tree));
+  idx_arr = XALLOCAVEC (tree, ndim);
 
   if (mech != By_Descriptor_NCA
       && TREE_CODE (type) == ARRAY_TYPE && TYPE_CONVENTION_FORTRAN_P (type))