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 to genattrtab.c: eliminate last use of VA_START [take 2]


 > From: Graham Stott <grahams@redhat.com>
 > 
 > Kaveh,
 > 
 > Looking at the patch it would appear that the routine call va_start
 > via one the new new VA_ macros and now in some places returns
 > without calling va_end ().
 > 
 > I think this is wrong and that va_start/va_end should be paired.
 > Graham

Hmm, I suppose for those rare systems where va_end actually does
something, you're right.

Ok, here's another approach which moves the contents of attr_rtx into
a new function attr_rtx_1.  Then attr_rtx becomes a simple wrapper
using the VA_OPEN stuff.  There's exactly one exit point and
VA_CLOSE/va_end is always called.

Ok to install?

		Thanks,
		--Kaveh


2001-11-29  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* genattrtab.c (attr_rtx_1): New function containing the
	majority of `attr_rtx'.  Move variable declarations into the
	scope where they are used.  Eliminate unnecessary gotos.
	(attr_rtx): Now just a wrapper for `attr_rtx_1' using VA_OPEN,
	VA_FIXEDARG, and VA_CLOSE.

diff -rup orig/egcc-CVS20011129/gcc/genattrtab.c egcc-CVS20011129/gcc/genattrtab.c
--- orig/egcc-CVS20011129/gcc/genattrtab.c	Wed Nov 14 16:30:31 2001
+++ egcc-CVS20011129/gcc/genattrtab.c	Thu Nov 29 18:20:12 2001
@@ -365,6 +365,7 @@ rtx pic_offset_table_rtx;
 static void attr_hash_add_rtx	PARAMS ((int, rtx));
 static void attr_hash_add_string PARAMS ((int, char *));
 static rtx attr_rtx		PARAMS ((enum rtx_code, ...));
+static rtx attr_rtx_1		PARAMS ((enum rtx_code, va_list));
 static char *attr_printf	PARAMS ((unsigned int, const char *, ...))
   ATTRIBUTE_PRINTF_2;
 static char *attr_string        PARAMS ((const char *, int));
@@ -541,25 +542,15 @@ attr_hash_add_string (hashcode, str)
    rtx attr_rtx (code, [element1, ..., elementn])  */
 
 static rtx
-attr_rtx VPARAMS ((enum rtx_code code, ...))
+attr_rtx_1 (code, p)
+     enum rtx_code code;
+     va_list p;
 {
-#ifndef ANSI_PROTOTYPES
-  enum rtx_code code;
-#endif
-  va_list p;
-  int i;		/* Array indices...			*/
-  const char *fmt;	/* Current rtx's format...		*/
   rtx rt_val = NULL_RTX;/* RTX to return to caller...		*/
   int hashcode;
   struct attr_hash *h;
   struct obstack *old_obstack = rtl_obstack;
 
-  VA_START (p, code);
-
-#ifndef ANSI_PROTOTYPES
-  code = va_arg (p, enum rtx_code);
-#endif
-
   /* For each of several cases, search the hash table for an existing entry.
      Use that entry if one is found; otherwise create a new RTL and add it
      to the table.  */
@@ -573,7 +564,6 @@ attr_rtx VPARAMS ((enum rtx_code code, .
 	{
 	  rt_val = rtx_alloc (code);
 	  XEXP (rt_val, 0) = arg0;
-	  va_end (p);
 	  return rt_val;
 	}
 
@@ -582,7 +572,7 @@ attr_rtx VPARAMS ((enum rtx_code code, .
 	if (h->hashcode == hashcode
 	    && GET_CODE (h->u.rtl) == code
 	    && XEXP (h->u.rtl, 0) == arg0)
-	  goto found;
+	  return h->u.rtl;
 
       if (h == 0)
 	{
@@ -604,7 +594,6 @@ attr_rtx VPARAMS ((enum rtx_code code, .
 	  rt_val = rtx_alloc (code);
 	  XEXP (rt_val, 0) = arg0;
 	  XEXP (rt_val, 1) = arg1;
-	  va_end (p);
 	  return rt_val;
 	}
 
@@ -614,7 +603,7 @@ attr_rtx VPARAMS ((enum rtx_code code, .
 	    && GET_CODE (h->u.rtl) == code
 	    && XEXP (h->u.rtl, 0) == arg0
 	    && XEXP (h->u.rtl, 1) == arg1)
-	  goto found;
+	  return h->u.rtl;
 
       if (h == 0)
 	{
@@ -637,7 +626,7 @@ attr_rtx VPARAMS ((enum rtx_code code, .
 	if (h->hashcode == hashcode
 	    && GET_CODE (h->u.rtl) == code
 	    && XSTR (h->u.rtl, 0) == arg0)
-	  goto found;
+	  return h->u.rtl;
 
       if (h == 0)
 	{
@@ -659,7 +648,7 @@ attr_rtx VPARAMS ((enum rtx_code code, .
 	    && GET_CODE (h->u.rtl) == code
 	    && XSTR (h->u.rtl, 0) == arg0
 	    && XSTR (h->u.rtl, 1) == arg1)
-	  goto found;
+	  return h->u.rtl;
 
       if (h == 0)
 	{
@@ -673,19 +662,16 @@ attr_rtx VPARAMS ((enum rtx_code code, .
     {
       HOST_WIDE_INT arg0 = va_arg (p, HOST_WIDE_INT);
       if (arg0 == 0)
-	{
-	  va_end (p);
-	  return false_rtx;
-	}
-      if (arg0 == 1)
-	{
-	  va_end (p);
-	  return true_rtx;
-	}
-      goto nohash;
+	return false_rtx;
+      else if (arg0 == 1)
+	return true_rtx;
+      else
+	goto nohash;
     }
   else
     {
+      int i;		/* Array indices...			*/
+      const char *fmt;	/* Current rtx's format...		*/
     nohash:
       rt_val = rtx_alloc (code);	/* Allocate the storage space.  */
 
@@ -722,19 +708,25 @@ attr_rtx VPARAMS ((enum rtx_code code, .
 	      abort ();
 	    }
 	}
-      va_end (p);
       return rt_val;
     }
 
   rtl_obstack = old_obstack;
-  va_end (p);
   attr_hash_add_rtx (hashcode, rt_val);
   RTX_INTEGRATED_P (rt_val) = 1;
   return rt_val;
+}
 
- found:
-  va_end (p);
-  return h->u.rtl;
+static rtx
+attr_rtx VPARAMS ((enum rtx_code code, ...))
+{
+  rtx result;
+  
+  VA_OPEN (p, code);
+  VA_FIXEDARG (p, enum rtx_code, code);
+  result = attr_rtx_1 (code, p);
+  VA_CLOSE (p);
+  return result;
 }
 
 /* Create a new string printed with the printf line arguments into a space


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