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 PR41144


This fixes PR41144 - the C++ FE is somewhat unlucky with the
order it completes types during template substitution and
messes up canonical types this way.  The following patch ensures
we're not recording types with structurall equality requirements
in the canonical hash table.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.

Richard.

2009-09-06  Richard Guenther  <rguenther@suse.de>

	PR middle-end/41144
	* tree.c (build_array_type): Do not record types marked
	with structural equality in the canonical type hashtable.

	* g++.dg/torture/pr41144.C: New testcase.

Index: gcc/tree.c
===================================================================
*** gcc/tree.c	(revision 151458)
--- gcc/tree.c	(working copy)
*************** build_array_type (tree elt_type, tree in
*** 6906,6949 ****
    t = make_node (ARRAY_TYPE);
    TREE_TYPE (t) = elt_type;
    TYPE_DOMAIN (t) = index_type;
!   
!   if (index_type == 0)
!     {
!       tree save = t;
!       hashcode = iterative_hash_object (TYPE_HASH (elt_type), hashcode);
!       t = type_hash_canon (hashcode, t);
!       if (save == t)
! 	layout_type (t);
! 
!       if (TYPE_CANONICAL (t) == t)
! 	{
! 	  if (TYPE_STRUCTURAL_EQUALITY_P (elt_type))
! 	    SET_TYPE_STRUCTURAL_EQUALITY (t);
! 	  else if (TYPE_CANONICAL (elt_type) != elt_type)
! 	    TYPE_CANONICAL (t) 
! 	      = build_array_type (TYPE_CANONICAL (elt_type), index_type);
! 	}
  
!       return t;
!     }
  
    hashcode = iterative_hash_object (TYPE_HASH (elt_type), hashcode);
!   hashcode = iterative_hash_object (TYPE_HASH (index_type), hashcode);
    t = type_hash_canon (hashcode, t);
  
-   if (!COMPLETE_TYPE_P (t))
-     layout_type (t);
- 
    if (TYPE_CANONICAL (t) == t)
      {
        if (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
! 	  || TYPE_STRUCTURAL_EQUALITY_P (index_type))
  	SET_TYPE_STRUCTURAL_EQUALITY (t);
        else if (TYPE_CANONICAL (elt_type) != elt_type
! 	       || TYPE_CANONICAL (index_type) != index_type)
  	TYPE_CANONICAL (t) 
  	  = build_array_type (TYPE_CANONICAL (elt_type),
! 			      TYPE_CANONICAL (index_type));
      }
  
    return t;
--- 6906,6934 ----
    t = make_node (ARRAY_TYPE);
    TREE_TYPE (t) = elt_type;
    TYPE_DOMAIN (t) = index_type;
!   layout_type (t);
  
!   /* If the element type is incomplete at this point we get marked for
!      structural equality.  Do not record these types in the canonical
!      type hashtable.  */
!   if (TYPE_STRUCTURAL_EQUALITY_P (t))
!     return t;
  
    hashcode = iterative_hash_object (TYPE_HASH (elt_type), hashcode);
!   if (index_type)
!     hashcode = iterative_hash_object (TYPE_HASH (index_type), hashcode);
    t = type_hash_canon (hashcode, t);
  
    if (TYPE_CANONICAL (t) == t)
      {
        if (TYPE_STRUCTURAL_EQUALITY_P (elt_type)
! 	  || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type)))
  	SET_TYPE_STRUCTURAL_EQUALITY (t);
        else if (TYPE_CANONICAL (elt_type) != elt_type
! 	       || (index_type && TYPE_CANONICAL (index_type) != index_type))
  	TYPE_CANONICAL (t) 
  	  = build_array_type (TYPE_CANONICAL (elt_type),
! 			      index_type ? TYPE_CANONICAL (index_type) : NULL);
      }
  
    return t;
Index: gcc/testsuite/g++.dg/torture/pr41144.C
===================================================================
*** gcc/testsuite/g++.dg/torture/pr41144.C	(revision 0)
--- gcc/testsuite/g++.dg/torture/pr41144.C	(revision 0)
***************
*** 0 ****
--- 1,23 ----
+ /* { dg-do compile } */
+ 
+ struct rgba8;
+ template<class ColorT> class span_gouraud     {
+ public:
+     struct coord_type { };
+     coord_type m_coord[3];
+ };
+ template<class ColorT> class span_gouraud_rgba : public span_gouraud<ColorT>   
+ {
+   typedef ColorT color_type;
+   typedef span_gouraud<color_type> base_type;
+   typedef typename base_type::coord_type coord_type;
+ public:
+   void prepare()         {
+       coord_type coord[3];
+   }
+ };
+ void the_application() {
+     typedef span_gouraud_rgba<rgba8> gouraud_span_gen_type;
+     gouraud_span_gen_type span_gouraud;
+     span_gouraud.prepare();
+ }


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