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] Fix a regression due to my recent composite_type changes


I noticed after my patch to composite_type that I introduced a regression
but there is no testcase for it yet in the testsuite :(.
This patch fixes that regression as you cannot use qualify_type with array
types as it uses c_build_qualified_type which touches the wrong type
when building the new type. I also implemented a little memory improvement
that I noticed while working on this problem. When the two TYPE_DOMAINS
of arrays types are NULL, you create a new type which is not necessary.


OK? Bootstrapped on powerpc-apple-darwin with no regressions.

Thanks,
Andrew Pinski


Testcase: extern const char *const a[]; extern const char *const a[]; extern const char *const a[];

ChangeLog:

	* c-typeck.c (composite_type): Do not use qualify_type
	but rather use build_qualified_type.
	<case ARRAY_TYPE>: If both of the type domains are null
	and the new element type is the same as one of the, return
	the one which the element type matches.

Patch:
Index: c-typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-typeck.c,v
retrieving revision 1.328
diff -u -p -r1.328 c-typeck.c
--- c-typeck.c	23 Jun 2004 17:05:42 -0000	1.328
+++ c-typeck.c	23 Jun 2004 19:23:00 -0000
@@ -214,6 +214,8 @@ composite_type (tree t1, tree t2)
   enum tree_code code1;
   enum tree_code code2;
   tree attributes;
+
+  int merged_quals;

/* Save time if the two types are the same. */

@@ -243,6 +245,8 @@ composite_type (tree t1, tree t2)

   if (code1 != code2)
     abort ();
+
+  merged_quals = TYPE_QUALS (t1) | TYPE_QUALS (t2);

   switch (code1)
     {
@@ -254,7 +258,7 @@ composite_type (tree t1, tree t2)
 	tree target = composite_type (pointed_to_1, pointed_to_2);
 	t1 = build_pointer_type (target);
 	t1 = build_type_attribute_variant (t1, attributes);
-	return qualify_type (t1, t2);
+	return build_qualified_type (t1, merged_quals);
       }

     case ARRAY_TYPE:
@@ -265,10 +269,16 @@ composite_type (tree t1, tree t2)
 	  return build_type_attribute_variant (t1, attributes);
 	if (elt == TREE_TYPE (t2) && TYPE_DOMAIN (t2))
 	  return build_type_attribute_variant (t2, attributes);
+	
+	if (elt == TREE_TYPE (t1) && !TYPE_DOMAIN (t2) && !TYPE_DOMAIN (t1))
+	  return build_type_attribute_variant (t1, attributes);
+	if (elt == TREE_TYPE (t2) && !TYPE_DOMAIN (t2) && !TYPE_DOMAIN (t1))
+	  return build_type_attribute_variant (t2, attributes);
+	
 	/* Merge the element types, and have a size if either arg has one.  */
 	t1 = build_array_type (elt, TYPE_DOMAIN (TYPE_DOMAIN (t1) ? t1 : t2));
 	t1 = build_type_attribute_variant (t1, attributes);
-	return qualify_type (t1, t2);
+	return build_qualified_type (t1, merged_quals);
       }

     case FUNCTION_TYPE:
@@ -293,13 +303,13 @@ composite_type (tree t1, tree t2)
 	 {
 	    t1 = build_function_type (valtype, TYPE_ARG_TYPES (t2));
 	    t1 = build_type_attribute_variant (t1, attributes);
-	    return qualify_type (t1, t2);
+	    return build_qualified_type (t1, merged_quals);
 	 }
 	if (TYPE_ARG_TYPES (t2) == 0)
 	 {
 	   t1 = build_function_type (valtype, TYPE_ARG_TYPES (t1));
 	   t1 = build_type_attribute_variant (t1, attributes);
-	   return qualify_type (t1, t2);
+	   return build_qualified_type (t1, merged_quals);
 	 }

 	/* If both args specify argument types, we must merge the two
@@ -369,7 +379,7 @@ composite_type (tree t1, tree t2)

 	c_override_global_bindings_to_false = false;
 	t1 = build_function_type (valtype, newargs);
-	t1 = qualify_type (t1, t2);
+	t1 = build_qualified_type (t1, merged_quals);
 	/* ... falls through ...  */
       }


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