diff mbox series

c++: Fix array type dependency [PR 98107]

Message ID c9b2f2b7-3b1a-a4ad-b39e-2eae51a468e9@acm.org
State New
Headers show
Series c++: Fix array type dependency [PR 98107] | expand

Commit Message

Nathan Sidwell Dec. 3, 2020, 3:56 p.m. UTC
I'd missed some    paths through build_cplus_array_type, plus, some
arrays come via the C-type builder.  This propagates dependency    in
more places and asserts that in the cases where TYPE_DEPENDENT_P_VALID
is unset, the type is non-dependent.

     PR c++/98107
         gcc/cp/
         * tree.c (build_cplus_array_type): Mark dependency of new variant.
         (cp_build_qualified_type_real, strip_typedefs): Assert
         TYPE_DEPENDENT_P_VALID, or not a dependent type.

Comments

Nathan Sidwell Dec. 3, 2020, 4:43 p.m. UTC | #1
These two testcases provide coverage for 98115,	which doesn't trigger on 
all hosts.

         PR c++/98115
         PR c++/98116
	gcc/testsuite/
         * g++.dg/template/pr98115.C: New.
         * g++.dg/template/pr98116.C: New.


nathan
diff mbox series

Patch

diff --git c/gcc/cp/tree.c w/gcc/cp/tree.c
index 5932777be04..4f28e6d49fd 100644
--- c/gcc/cp/tree.c
+++ w/gcc/cp/tree.c
@@ -1076,6 +1076,9 @@  build_cplus_array_type (tree elt_type, tree index_type, int dependent)
     {
       bool typeless_storage = is_byte_access_type (elt_type);
       t = build_array_type (elt_type, index_type, typeless_storage);
+
+      /* Mark as non-dependenty now, this will save time later.  */
+      TYPE_DEPENDENT_P_VALID (t) = true;
     }
 
   /* Now check whether we already have this array variant.  */
@@ -1090,6 +1093,9 @@  build_cplus_array_type (tree elt_type, tree index_type, int dependent)
       if (!t)
 	{
 	  t = build_min_array_type (elt_type, index_type);
+	  /* Mark dependency now, this saves time later.  */
+	  TYPE_DEPENDENT_P_VALID (t) = true;
+	  TYPE_DEPENDENT_P (t) = dependent;
 	  set_array_type_canon (t, elt_type, index_type, dependent);
 	  if (!dependent)
 	    {
@@ -1326,6 +1332,8 @@  cp_build_qualified_type_real (tree type,
 
       if (!t)
 	{
+	  gcc_checking_assert (TYPE_DEPENDENT_P_VALID (type)
+			       || !dependent_type_p (type));
 	  t = build_cplus_array_type (element_type, TYPE_DOMAIN (type),
 				      TYPE_DEPENDENT_P (type));
 
@@ -1563,6 +1571,8 @@  strip_typedefs (tree t, bool *remove_attributes, unsigned int flags)
     case ARRAY_TYPE:
       type = strip_typedefs (TREE_TYPE (t), remove_attributes, flags);
       t0  = strip_typedefs (TYPE_DOMAIN (t), remove_attributes, flags);
+      gcc_checking_assert (TYPE_DEPENDENT_P_VALID (t)
+			   || !dependent_type_p (t));
       result = build_cplus_array_type (type, t0, TYPE_DEPENDENT_P (t));
       break;
     case FUNCTION_TYPE: