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]

C++ PATCH for c++/34206 (crash in retrieve_local_specialization)


Jakub's suggested fix of just avoiding the crash if local_specializations is null would work, but it seemed to me that we really shouldn't need to tsubst this type at all, since it doesn't use any template parameters. Changing tsubst_aggr_type to check whether the base type uses template parms fixes the bug. Checking uses_template_parms of a type doesn't slow us down because we cache TYPE_DEPENDENT_P; running the C++ testsuites takes the same amount of time or possibly even less with the patch.

I tried checking uses_template_parms for all types and returning immediately if false, but it turns out that we need to go through tsubst for VLAs in templates or they don't work properly. Rather than mess with that now, I limited the change to tsubst_aggr_type.

The dependent_type_r change is not necessary to fix the bug, but addresses an issue that I noticed while trying to make the more comprehensive change work; dependent_type_p was returning false for the domain type of a dependent array type, which seems clearly incorrect.

Tested x86_64-pc-linux-gnu, applied to trunk.
Index: pt.c
===================================================================
*** pt.c	(revision 130990)
--- pt.c	(working copy)
*************** tsubst_aggr_type (tree t,
*** 7563,7569 ****
        /* Else fall through.  */
      case ENUMERAL_TYPE:
      case UNION_TYPE:
!       if (TYPE_TEMPLATE_INFO (t))
  	{
  	  tree argvec;
  	  tree context;
--- 7563,7569 ----
        /* Else fall through.  */
      case ENUMERAL_TYPE:
      case UNION_TYPE:
!       if (TYPE_TEMPLATE_INFO (t) && uses_template_parms (t))
  	{
  	  tree argvec;
  	  tree context;
*************** dependent_type_p_r (tree type)
*** 15323,15335 ****
    if (TREE_CODE (type) == ARRAY_TYPE)
      {
        if (TYPE_DOMAIN (type)
! 	  && ((value_dependent_expression_p
! 	       (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
! 	      || (type_dependent_expression_p
! 		  (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))))
  	return true;
        return dependent_type_p (TREE_TYPE (type));
      }
  
    /* -- a template-id in which either the template name is a template
       parameter ...  */
--- 15323,15340 ----
    if (TREE_CODE (type) == ARRAY_TYPE)
      {
        if (TYPE_DOMAIN (type)
! 	  && dependent_type_p (TYPE_DOMAIN (type)))
  	return true;
        return dependent_type_p (TREE_TYPE (type));
      }
+   else if (TREE_CODE (type) == INTEGER_TYPE
+ 	   && !TREE_CONSTANT (TYPE_MAX_VALUE (type)))
+     {
+       /* If this is the TYPE_DOMAIN of an array type, consider it
+ 	 dependent.  */
+       return (value_dependent_expression_p (TYPE_MAX_VALUE (type))
+ 	      || type_dependent_expression_p (TYPE_MAX_VALUE (type)));
+     }
  
    /* -- a template-id in which either the template name is a template
       parameter ...  */

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